Skip to content
This repository was archived by the owner on Jun 3, 2019. It is now read-only.
This repository was archived by the owner on Jun 3, 2019. It is now read-only.

NOTICE: componentWillMount and this starter kit #409

@ctrlplusb

Description

@ctrlplusb

We use react-async-bootstrapper to bootstrap your application on the client/server sides so that things like async components (and data in the features/react-jobs branch) can be pre-resolved.

Your React application will go through the following process:

  • Passed into asyncBootstrapper - this tries to mimic the behaviour of a server side render (to a degree) by walking your react component tree. It has to call componentWillMount along the way as this is expected behaviour in renderToString/renderToStaticMarkup calls. Generally people put things like state initialisation etc in the componentWillMount, so this will be needed so that the render 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.
  • After the bootstrapping process has complete your application is passed to the 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 calls componentWillUnmount, again mimicking the behaviour of a typical renderToString/renderToStaticMarkup call. Unfortunately libraries that generally do event binding in componentWillMount do the unbinding within componentWillUnmount. As we never call this the event listeners for the bootstrapping process live on, and then things like MobX state updates will cause things like forceUpdate errors as the associated components do not exist.

I am considering extending the asyncBootstrapper function to allow you to pass a prop stating that componentWillUnmount should run. This may improve interoperability with these types of libraries, however, it could cause issues on others. We will have to experiment together.

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