facebook / facebook/relay

Is it worth it to use PreloadedQuery?

Open
#4,529 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

in https://relay.dev/docs/tutorial/queries-2/
There is a lot of "do this" and "do this" for PreloadedQuery

I really don't understand most of it. But it just feels like a lot of "just do this and it should work" kind of thing.

It is a lot of "Convention over configuration": just follow it.

I also tried the time between `LazyLoad` vs `PreloadedQuery`. So I added taking down the `window.hoverStartTime`:

Inside of Hovercard.tsx:

```tsx
useEffect(() => {
console.log("ENTERING useEffect");
const target = targetRef.current;
const enterCallback = (event: MouseEvent) => {
window.hoverStartTime = window.hoverStartTime || Date.now();
onBeginHover?.();
setHoverState({
```

and then in

PosterDetailsHovercardContents.tsx:

```tsx
function PosterDetailsHovercardContentsBody({

console.log(
"DURATION PosterDetailsHovercardContentsBody",
Date.now() - window.hoverStartTime
);

return (
<>
```
So these are the results of `PreloadedQuery`:

I tried it 6 times:

```
1019
1021
1062
1029
1021
1015
```

(a little bit over 1 second)

and for `LazyLoad`:

```
1015
1023
1063
1017
1022
1023
```

so the numbers are very close. I figured: most of the time is for the fetch. The Processor time is very little... do we really care about the 0.02 or 0.03 seconds difference, even if there is any.

So is there really advantage of "Preload"? It takes so much more work to do it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.