feature(cli): add reactStrictMode
option
#3721
Merged
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.
Description
Adds an option to
sanity.cli.js
that controls wether strict mode is enabled. It was previously always-on. Now it's opt-in. The test studio enables it by default.Prior art: https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode
How to disable strict mode in the test studio without editing
renderStudio.tsx
ordev/test-studio/sanity.cli.ts
Either run the dev command with an env var override:
Or run this once and carry on as usual:
Double console log calls
If you're seeing double console logs after enabling strict mode, check the
Hide logs during second render in Strict Mode
option in the React Devtools Components Settings modal:What to review
In studios that have a
sanity.cli.ts
file, addreactStrictMode: true
to enable it.In studios without, it should be possible to opt-in by either
SANITY_STUDIO_REACT_STRICT_MODE=true sanity start
or by creating a.env.development
file adjacent tosanity.config.ts
with the same env var.Other studios shouldn't see strict mode on.
Including custom studios that call
renderStudio
directly.Notes for release
You can opt-in to React's Strict Mode checks for your custom studio components in these ways:
reactStrictMode: true
to yoursanity.cli.ts
file..env.development
file and addSANITY_STUDIO_REACT_STRICT_MODE=true
to it.SANITY_STUDIO_REACT_STRICT_MODE=true sanity start
We strongly suggest you opt-in to better prepare your custom studio for the future of React. This only affects development mode, production mode or
sanity build
is unaffected by this setting.