You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use componentWillMount to kick off some redux-thunks that do data fetching for my component on the server side.
Since react-async-component walks the tree to find the async components, it triggers all of the componentWillMount calls...then I still have to render the resulting appWithAsyncComponents with react-dom that invokes all of those componentWillMounts again.
The result is that I end up hitting my API twice for everything...once while finding the async components, and once when actually rendering to string.
UPDATE: I also find when using react-resolver that the same occurs. Essentially, any data fetching / expensive activity that's triggered by a pass over the tree would have to happen twice with this sort of approach.
The text was updated successfully, but these errors were encountered:
Yeah, a difficult one to manage. Ideally I would love to be able to skip the componentWillMount call completely, but it's a part of the React server side contract and lots of people set up critical state within this lifecycle method for the render. We need this state to render and walk the tree correctly.
I have another library react-jobs which also makes use of the tree walking technique. I plan to create an integration layer so that the use of both does not result in a double tree walk. I can and do fire redux-thunk based actions in my own implementations using react-jobs. It's a bit more boilerplate but you can create util functions to cover your own use case.
Sorry, not looking for self promotion, but it's the only solution I know of thus far if you are wanting to do full server side rendering.
Full server side rendering is a pain. If SEO isn't absolutely critical to you my recommended approach is to use async components with the ssrMode: 'defer' option set. Render your app shell on the server for perceived performance, have everything else render client side. This doesn't fit everyones case of course, which I can appreciate. However I'd like to reiterate this as I often hear of people trying do SSR react without considering what parts of their app need to be SSR'ed and what other parts could be deferred. Code splitting is still a massive win.
ctrlplusb
changed the title
Multiple componentWillMount calls on server
Document the "multiple componentWillMount" behaviour
Mar 20, 2017
Hey, thanks for your work on this.
I use
componentWillMount
to kick off someredux-thunk
s that do data fetching for my component on the server side.Since
react-async-component
walks the tree to find the async components, it triggers all of thecomponentWillMount
calls...then I still have to render the resultingappWithAsyncComponents
withreact-dom
that invokes all of thosecomponentWillMount
s again.The result is that I end up hitting my API twice for everything...once while finding the async components, and once when actually rendering to string.
UPDATE: I also find when using
react-resolver
that the same occurs. Essentially, any data fetching / expensive activity that's triggered by a pass over the tree would have to happen twice with this sort of approach.The text was updated successfully, but these errors were encountered: