-
Notifications
You must be signed in to change notification settings - Fork 243
NOTICE: componentWillMount and this starter kit #409
Comments
For anyone concerned, @ctrlplusb has already made a patch that fixes the problem. A boggling question from my perspective is... what is the side effect of calling componentWillUnmount by default for all components? |
@birkir one thing I can think of is those components that rely/expect some sort of dom/event binding to exist. hopefully they check this is the case before doing any sort of disposal. I do wrap the call with a try catch to avoid fallovers though. It will be interesting to see how this fairs for us. |
hmm.. without setting the useStaticRendering(true);
asyncBootstrapper(app).then(() => {
useStaticRendering(false);
render(app, content);
}); |
Hey @xiao-hu |
Aha, just found that. Yeah, that sounds like a much better solution for mobx. Officially supported and you can use it around the full server side render too. 👍 https://github.com/mobxjs/mobx-react#server-side-rendering-with-usestaticrendering |
That's right. Thanks for the very detailed description of the root cause! |
Guys, after applying this to my production app using
Using options |
Thanks for getting back to use about this @diondirza |
We use
react-async-bootstrapper
to bootstrap your application on the client/server sides so that things like async components (and data in thefeatures/react-jobs
branch) can be pre-resolved.Your React application will go through the following process:
asyncBootstrapper
- this tries to mimic the behaviour of a server side render (to a degree) by walking your react component tree. It has to callcomponentWillMount
along the way as this is expected behaviour inrenderToString/renderToStaticMarkup
calls. Generally people put things like state initialisation etc in thecomponentWillMount
, so this will be needed so that therender
functions of your components can be called with the required state it needs to return it's result (i.e. children). The process continues down the "tree" until the bootstrapping process is complete. This may sound expensive but all we are doing is creating and throwing away object instances - no DOM creation/interaction/manipulation occurs.render
/renderToString
functions for "normal" rendering (with all the global state given to it by the bootstrapping process).I have found the above working awesomely for me in large production projects that use Redux as a state management tool. However, I have become aware of other libraries (e.g. MobX) that bind some "event listeners" within the
componentWillMount
call. This will cause unexpected behaviour given our bootstrapping process. This is because the bootstrapping process never callscomponentWillUnmount
, again mimicking the behaviour of a typicalrenderToString
/renderToStaticMarkup
call. Unfortunately libraries that generally do event binding incomponentWillMount
do the unbinding withincomponentWillUnmount
. As we never call this the event listeners for the bootstrapping process live on, and then things like MobX state updates will cause things likeforceUpdate
errors as the associated components do not exist.I am considering extending the
asyncBootstrapper
function to allow you to pass a prop stating thatcomponentWillUnmount
should run. This may improve interoperability with these types of libraries, however, it could cause issues on others. We will have to experiment together.The text was updated successfully, but these errors were encountered: