davnicwil / react-frontload

Async data loading for React components, on client & server
451 stars 21 forks source link

frontloadMeta.serverRendered false on webkit #60

Open matthewlein opened 2 years ago

matthewlein commented 2 years ago

Hello,

I have a very odd situation going on where a certain page is refetching (re-frontloading) the data after page load, but only on webkit browsers (safari and chrome). Debugging a bit logging out console.log(frontloadMeta.serverRendered); I see the server always logs true (3 times), safari/chrome log false always (also 3), and firefox logs true once.

These are redux thunks

const { frontloadMeta } = useFrontload('ContentListContainer', async () => {
    console.log('frontloading');
    await Promise.all([
      dispatch(fetchAllArticles()),
      dispatch(fetchOtherVideos()),
      dispatch(fetchAllVideos()),
    ]);

    return true;
  });

The frontload data is there in the source in all browsers.

window.__FRONTLOAD_DATA__={"ContentListContainer":true}

And generally frontloading works everywhere else as expected. Logging the same thing in other places results in frontloadMeta.serverRendered true everywhere, as you'd expect. Places that use similar redux thunks in Promise.all look fine. Its a real mystery...

Any ideas?

matthewlein commented 2 years ago

I've dug into this for hours and haven't narrowed anything down too much yet.

Breakpointing here:

https://github.com/davnicwil/react-frontload/blob/a2063644e23dfee559fee47dd88575872a773e7b/src/index.tsx#L408-L416

I can see that in Firefox frontloadState.serverRender.cache is { ContentListContainer: true } as expected, where on chrome it is empty {}

Server log show it rendered, and the page loads with content preloaded.

react-frontload server render trace

1 frontloads ran in 3 render passes
  - ContentListContainer

∙ Render pass 0           |  1 total, 1 new
  - ContentListContainer  |  new

∙ Render pass 1           |  1 total, 0 new
  - ContentListContainer  |  cached

∙ Render pass 2
  - final render pass, no frontloads ran
___________________________________

In another case, reordering the dispatches in Promise.all resulted in serverRendered true.