Allow developers to disable concurrent rendering (reactRoot: false) with React 18 #36419
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently any website that uses React 18 causes
shouldUseReactRoot()
to return true, which forcesconfig.experimental.reactRoot
to be true and enables concurrent rendering. There are several libraries--often those that buffer up CSS used during rendering and emit it before streaming the response to the client--that rely on React's rendering to be synchronous. While those libraries will eventually need to be updated to support streaming and Suspense in some cases, they work with React 18 otherwise.This commit lets websites disable concurrent features by explicitly setting
experimental.reactRoot = false
in next.config.js. Ifexperimental.reactRoot
is unspecified, then the existing default behavior still applies:reactRoot
is true when using React 18+ or an experimental version and false otherwise. Production builds use the same resolved config object so future changes to this behavior will apply to both development and production.Tested in a sample website that relies on synchronous React rendering and uses React 18. When
experimental.reactRoot
is false, the site renders. When it's true or not defined, the site expectedly fails to render (as was the case before this commit). Rannext build
to make sure that production builds honor the same logic.Added an integration test. Run with
node run-tests.js test/integration/react-18-serial/test/index.test.js
.Bug
fixes #number
This PR is the bug reportcontributing.md
N/A