Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(cli): add reactStrictMode option #3721

Merged
merged 1 commit into from
Oct 5, 2022

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Oct 5, 2022

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 or dev/test-studio/sanity.cli.ts

Either run the dev command with an env var override:

SANITY_STUDIO_REACT_STRICT_MODE=false yarn dev

Or run this once and carry on as usual:

cp dev/test-studio/.env.example dev/test-studio/.env.development

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:

Screenshot 2022-10-05 at 06 35 29

What to review

In studios that have a sanity.cli.ts file, add reactStrictMode: 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 to sanity.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:

  • Add reactStrictMode: true to your sanity.cli.ts file.
  • Create a .env.development file and add SANITY_STUDIO_REACT_STRICT_MODE=true to it.
  • Set the env var while starting sanity: 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.

@vercel
Copy link

vercel bot commented Oct 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Oct 5, 2022 at 4:34AM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
studio-workshop ⬜️ Ignored (Inspect) Oct 5, 2022 at 4:34AM (UTC)

@stipsan stipsan force-pushed the chore/sc-25382/add-react-strict-mode-option branch from 16a3408 to 600a24e Compare October 5, 2022 04:29
@stipsan stipsan added the v3 label Oct 5, 2022
@stipsan stipsan marked this pull request as ready for review October 5, 2022 04:57
Copy link
Contributor

@snorrees snorrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nice info in the description here 👍

Only have one suggestion: add a period in the last sentence of Notes for release. I read it as "only affects development mode, production mode ... ie as a list of things it affects.

"This only affects development mode. Production mode or sanity build is unaffected by this setting."

@stipsan stipsan merged commit 5ecbbd9 into v3 Oct 5, 2022
@stipsan stipsan deleted the chore/sc-25382/add-react-strict-mode-option branch October 5, 2022 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants