question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apollo's getDataFromTree does not fetch data for a Loadable component's children queries

See original GitHub issue

💬 Questions and Help

I’m using @loadable/component along with react-apollo. For SSR, I have used @neoziro’s SSR middleware solution in issue https://github.com/smooth-code/loadable-components/issues/30 and it works great.

However, I’m encountering an issue while trying to preload pages for client-side navigation.

When navigating, we call react-apollo’s getDataFromTree function on client side to preload all the data from GraphQL queries in the tree. getDataFromTree does not know to wait for loadable-components, though, so it immediately renders a loading screen instead of keeping the user on the initial page until all the loadable-components and their children queries have finished loading.

Here’s a more concrete example:

  1. User clicks a link on the Home page to a Profile page, which starts a client-side navigation.
  2. getDataFromTree begins walking the Profile page React tree and fetching data for Query components
  3. Eventually, getDataFromTree tries to render a loadable-component, which immediately renders a loading component while the loadable chunk is asynchronously loaded in.
  4. Once all other queries have fetched data, getDataFromTree resolves without waiting for the js chunk to load in.
  5. Once the JS chunk loads in, loadable-component will render its component. Any children queries within the loadable-component now start to fetch their data.

Expected: User clicks Profile page link, Profile page loads in with all data already fetched. Actual: User clicks Profile page link, sees loading screen while Profile chunk loads in, then sees additional loading screen while Profile chunks’ Queries are loaded, then finally sees Profile page with all data.

How can I get around this problem?

My initial thought was to pass the InnerLoadableComponent’s this.promise to getDataFromTree via a wrapper component, but I don’t have access to the InnerLoadable due to Ref Forwarding.

Any other thoughts, solutions, or discussion would be greatly appreciated. Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
masihjahangiricommented, Sep 17, 2019

Hello @jdmoody, You must run jsx = extractor.collectChunks(), then getDataFromTree(jsx). The collectChunks will take care of loading all modules.

not work for me!

1reaction
gregbergecommented, Jan 22, 2019

Yes it is what I mean.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apollo's getDataFromTree does not fetch data for a Loadable ...
When navigating, we call react-apollo's getDataFromTree function on client side to preload all the data from GraphQL queries in the tree.
Read more >
Server-side rendering - Apollo GraphQL Docs
We can instruct Apollo Client to execute all of the queries required by the tree's components with the getDataFromTree function. This function walks...
Read more >
React Apollo SSR getDataFromTree not waiting for query
The issue here is that getDataFromTree is not waiting for my query at all. It simply returns the component with loading: true and...
Read more >
Next.js + Multiple Apollo Clients & GraphQL Sources
This gives our child components access to the data coming from the ... running `getDataFromTree`", error); } // getDataFromTree does not ...
Read more >
react-universal-component - npm
Packages in the past like React Loadable did not address this aspect. ... async component loads AND while any data-fetching may be occuring ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found