ctrlplusb / react-async-component

Resolve components asynchronously, with support for code splitting and advanced server side rendering use cases.
MIT License
1.45k stars 62 forks source link

Context is empty after async bootstrap #32

Closed terencechow closed 6 years ago

terencechow commented 7 years ago

I'm trying to do ssr with injected reducers using redux. However I'm seeing no store on the context when the renderToString function is executed.

I'm essentially following this repo https://github.com/dlebedynskyi/react-playground and specifically i don't see this.context.store in this component: https://github.com/dlebedynskyi/react-playground/blob/master/src/app/store/withAsyncReducers.js

That repo uses an outdated version of react async component and react async bootstrapped so I'm basically trying to do the same with the updated libraries. In the older version a variable appWithAsyncComponents would exist after the bootstrap but now that doesn't exist. Would you have any idea why the context is an empty object when rendering to string but exists before that? Any guidance would be appreciated.

//... In my middleware fn...
const app = (
    <AsyncComponentProvider asyncContext={asyncContext}>
      <Provider store={store}>
          <StaticRouter location={request.url} context={routerContext}>
              <MyApp />
          </StaticRouter>
      </Provider>
    </AsyncComponentProvider>
  )

// this.context.store exists here๐Ÿ‘‡
asyncBootstrapper(app).then(() => {
      // app doesn't have store here ๐Ÿ‘‡
      const appString = renderToString(app)
ctrlplusb commented 7 years ago

This is a strange case that I haven't experienced myself. Any chance for a minimal example I can use to view and debug the issue for you?

ctrlplusb commented 6 years ago

Closing due to inactivity. Feel free to reopen with example. ๐Ÿ‘