react-tree-walker icon indicating copy to clipboard operation
react-tree-walker copied to clipboard

Behavior on server-side when using in conjunction with dynamic imports

Open oyeanuj opened this issue 7 years ago • 7 comments

Hi @ctrlplusb, while debugging https://github.com/ctrlplusb/react-jobs/issues/51 & https://github.com/ctrlplusb/react-jobs/issues/56, I realized that if there were jobs on dynamic import components, then those jobs wouldn't execute on the server-side since the components are not being imported before render is considered complete.

Here is a simple summarized hierarchy that could reproduced it for me -

<App>
  <Auth> /* <--- Fetch data */
    <Switch>
      <Route component = { AsyncProfile } />
      { /* AsyncProfile dynamically imports Profile which fetches the data */ }
    </Switch>
  </Auth>
<App>

Looking through codebases of this library and react-jobs, it seems like this issue should be resolved here. Thoughts on what should be the expected behavior?

oyeanuj avatar Mar 31 '18 03:03 oyeanuj

Definitely should resolve. Sorry was half way through updating react-jobs. Will do and then post an example for you on how to interop the two. I'll probably link the example with react-async-bootstrapper - since that is the "standard" interop interface between the two.

ctrlplusb avatar Apr 04 '18 18:04 ctrlplusb

Apologies @oyeanuj been so busy!

ctrlplusb avatar Apr 26 '18 16:04 ctrlplusb

@ctrlplusb No worries, hope you get a chance soon :)

oyeanuj avatar Apr 27 '18 16:04 oyeanuj

@ctrlplusb Just checking in for an update here? Not sure if you are done updating react-jobs, but an example would be super helpful since this prevents SSR with data-fetching right now :(

oyeanuj avatar Jul 28 '18 17:07 oyeanuj

Hey @oyeanuj

You are the definition of patience. 😃

I am trying to throw up a razzle based example now, using react-async-component as well as react-jobs. 👍

ctrlplusb avatar Aug 10 '18 10:08 ctrlplusb

Ok, got it working. :)

Demo: https://razzle-async-components-and-data.now.sh/

Source: https://github.com/ctrlplusb/demo-react-async-and-jobs

I also added emotion for good measure.

ctrlplusb avatar Aug 10 '18 11:08 ctrlplusb

@ctrlplusb I've had a chance to drill down more into this and I have one quick question to ask, and observation to report:

Theoretically, should a setup like this work with react-jobs and react-async-bootstrapper on the server-side?

<App>
  <Auth> /* <--- Fetch data */
    <ListingPage> /* <--- Fetch data */
      <MovieOne /> /* <--- Fetch data */
      <MovieTwo /> /* <--- Fetch data */
  </Auth>
<App>

I'm noticing that the after the first pass of react-jobs, the asyncBootstrapper is considering its job over before rest of the jobs have a chance to resolve and render their children.

Any ideas or thoughts would be super useful!

oyeanuj avatar Dec 23 '18 03:12 oyeanuj