Skip to content

Context is empty after async bootstrap #32

@terencechow

Description

@terencechow

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions