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
- React Hot Loader interoperability. 🎉
- The provider is no longer required for a browser-only context.
- `ssrMode` config renamed to `serverMode`.
- Errors are no longer server rendered.
- Code simplification parse.
Now, you can simply import `Product` anywhere in your application and not have to worry about having to call `createAsyncComponent` again.
79
+
Now, you can simply import `Product` anywhere in your application and use it exactly as you would any other component.
98
80
99
81
For example:
100
82
@@ -131,9 +113,9 @@ The asynchronous component factory. Config goes in, an asynchronous component co
131
113
-`ErrorComponent` (_Component_, Optional, default: `null`) : A Component that will be displayed if any error occurred whilst trying to resolve your component. All props will be passed to it as well as an `error` prop which is an object with a `message` and `stack` property.
132
114
-`name` (_String_, Optional, default: `'AsyncComponent'`) : Use this if you would like to name the created async Component, which helps when firing up the React Dev Tools for example.
133
115
-`autoResolveES2015Default` (_Boolean_, Optional, default: `true`) : Especially useful if you are resolving ES2015 modules. The resolved module will be checked to see if it has a `.default` and if so then the value attached to `.default` will be used. So easy to forget to do that. 😀
134
-
-`ssrMode` (_Boolean_, Optional, default: `'render'`) : Only applies for server side rendering applications. Please see the documentation on server side rendering. The following values are allowed.
116
+
-`serverMode` (_Boolean_, Optional, default: `'render'`) : Only applies for server side rendering applications. Please see the documentation on server side rendering. The following values are allowed.
135
117
-__`'render'`__ - Your asynchronous component will be resolved and rendered on the server. It's children will
136
-
be checked to see if there are any nested asynchronous component instances, which will then be processed based on the `ssrMode` value that was associated with them.
118
+
be checked to see if there are any nested asynchronous component instances, which will then be processed based on the `serverMode` value that was associated with them.
137
119
-__`'defer'`__ - Your asynchronous component will _not_ be rendered on the server, instead deferring rendering to the client/browser.
138
120
-__`'boundary'`__ - Your asynchronous component will be resolved and rendered on the server. However, if it has a nested asynchronous component instance within it's children that component will be ignored and treated as being deferred for rendering in the client/browser instead.
139
121
We highly recommend that you consider using `defer` as much as you can.
Wraps your application allowing for efficient and effective use of asynchronous components.
171
+
Currently only useful when building server side rendering applications. Wraps your application allowing for efficient and effective use of asynchronous components.
190
172
191
173
#### Props
192
174
193
-
-`asyncContext` (_Object_, Optional) : You can optionally provide an asynchronous context (created using `createAsyncContext`). If you don't provide one then an instance will be created automatically internally. It can be useful to create and provide your own instance so that you can gain hooks into the context for advanced use cases such as server side rendering state rehydration or hot module replacement interoperability.
194
-
-`rehydrateState` (_Object_, Optional) : Only useful in a server side rendering application (see the docs). This allows you to provide the state returned by the server to be used to rehydrate the client appropriately, ensuring that it's rendered checksum will match that of the content rendered by the server.
175
+
-`asyncContext` (_Object_) : Used so that you can gain hooks into the context for server side rendering render tracking and rehydration. See the `createAsyncContext` helper for creating an instance.
176
+
-`rehydrateState` (_Object_, Optional) : Used on the "browser-side" of a server side rendering application (see the docs). This allows you to provide the state returned by the server to be used to rehydrate the client appropriately.
195
177
196
178
### `createAsyncContext()`
197
179
@@ -201,7 +183,13 @@ Creates an asynchronous context that can be used by the `<AsyncComponentProvider
201
183
202
184
## Server Side Rendering
203
185
204
-
This library has been designed for generic interoperability with [`react-async-bootstrapper`](https://github.com/ctrlplusb/react-async-bootstrapper). The `react-async-bootstrapper` utility allows us to do a "pre-render parse" of a React Element tree and execute any "bootstrapping" functions that are attached to a components within the tree. In our case the "bootstrapping" process involves the resolution of asynchronous components so that they can be rendered "synchronously" by the server. We use this 3rd party library as it allows interoperability with other libraries which also require a "bootstrapping" process (e.g. data preloading as supported by [`react-jobs`](https://github.com/ctrlplusb/react-jobs)).
186
+
> NOTE: This section only really applies if you would like to have control over the behaviour of how your asyncComponent instances are rendered on the server. If you don't mind your asyncComponents always being resolved on the client only then you need not do any of the below. In my opinion there is great value in just server rendering your app shell and having everything else resolve on the client, however, you may have very strict SEO needs - in which case, we have your back.
187
+
188
+
This library has been designed for interoperability with [`react-async-bootstrapper`](https://github.com/ctrlplusb/react-async-bootstrapper).
189
+
190
+
`react-async-bootstrapper` allows us to do a "pre-render parse" of our React Element tree and execute an `asyncBootstrap` function that are attached to a components within the tree. In our case the "bootstrapping" process involves the resolution of asynchronous components so that they can be rendered "synchronously" by the server. We use this 3rd party library as it allows interoperability with other libraries which also require a "bootstrapping" process (e.g. data preloading as supported by [`react-jobs`](https://github.com/ctrlplusb/react-jobs)).
191
+
192
+
> NOTE: I have not updated `react-jobs` to make use of `react-async-bootstrapper` as of yet.
205
193
206
194
Firstly, install `react-async-bootstrapper`:
207
195
@@ -303,7 +291,7 @@ Although this operation isn't as expensive as an actual render as we don't gener
303
291
304
292
### SSR Performance Optimisation
305
293
306
-
As discussed in the ["SSR AsyncComponent Resolution Process"](#ssr-asyncComponent-resolution-process) section above it is possible to have an inefficient implementation of your `asyncComponent` instances. Therefore we introduced a new configuration object property for the `asyncComponent` factory, called `ssrMode`, which provides you with a mechanism to optimise the configuration of your async Component instances. Please see the API documentation for more information.
294
+
As discussed in the ["SSR AsyncComponent Resolution Process"](#ssr-asyncComponent-resolution-process) section above it is possible to have an inefficient implementation of your `asyncComponent` instances. Therefore we introduced a new configuration object property for the `asyncComponent` factory, called `serverMode`, which provides you with a mechanism to optimise the configuration of your async Component instances. Please see the API documentation for more information.
307
295
308
296
Understand your own applications needs and use the options appropriately . I personally recommend using mostly "defer" and a bit of "boundary". Try to see code splitting as allowing you to server side render an application shell to give the user perceived performance. Of course there will be requirements otherwise (SEO), but try to isolate these components and use a "boundary" as soon as you feel you can.
0 commit comments