boolean
false
Enalbe SSR configuration.
When the value type is boolean
, it indicates whether to enable SSR deployment mode. The default is false
to disable it.
When the value type is Object
, the following properties can be configured:
Name | Type | Default | Description |
---|---|---|---|
mode | string |
string |
which defaults to using renderToString for rendering. Configure stream to enable streaming rendering |
forceCSR | boolean |
false |
which is off by default for forcing CSR rendering. Configure true to force CSR by adding ?csr=true or adding x-modern-ssr-fallback header when accessing the page |
disablePrerender | boolean |
fasle |
To ensure compatibility with the old data request method (useLoader ), by default, Modern.js performs pre-rendering of components.However, if developers want to reduce one rendering when there is no use of the useLoader API in your project, you can set the configuration disablePrerender=true |
unsafeHeaders | string[] |
[] |
For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected |
scriptLoading | defer | blocking | module | async |
defer |
The configuration is the same as html.scriptLoading, supporting SSR injected script set to async loading. The priority is ssr.scriptLoading > html.scriptLoading |
loaderFailureMode | clientRender | errorBoundary |
errorBoundary |
The default configuration is 'errorBoundary' , when an error occurs in data loader, it will default to rendering the Error component of the route. When configured as 'clientRender' , if a loader throws an error, it switch to client-side rendering,you can use it with Client Loader |
In a production environment, there are scenarios where it is necessary to actively fallback an SSR project to CSR. Examples include
When the SSR fails, a fallback to the CSR is required to ensure product availability.
When the SSR is working normally, but there are rendering failures during csr, debugging is required.
When the SSR server is under heavy load, it may be necessary to fallback some traffic directly to the CSR to avoid service downtime.
By configuring server.ssr.forceCSR
to true
in the project, you can control this behavior through query strings or request headers.
For example, in a custom Web Server middleware, you can actively fallback when traffic exceeds a certain threshold: