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

Move modern strict to experimental #28152

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3792,12 +3792,9 @@ function commitDoubleInvokeEffectsInDEV(
hasPassiveEffects: boolean,
) {
if (__DEV__) {
if (useModernStrictMode) {
if (useModernStrictMode && root.tag !== LegacyRoot) {
let doubleInvokeEffects = true;

if (root.tag === LegacyRoot && !(root.current.mode & StrictLegacyMode)) {
doubleInvokeEffects = false;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@sammy-SC @acdlite, I fixed this bug that turned on strict effects in Legacy Mode, which may be the reason it was hard to land internally, breaking unit tests and whatnot.

Previously, legacyCommitDoubleInvokeEffectsInDEV would be called in the legacy root too (when strict mode was on), but we wouldn't fire any effects because no fiber flags were set. When we copied over the check to this block, it forces effects to be fired, since it's not checking fiber flags (by design).

We have a test that caught this, but we didn't have any test variants that enabled useModernStrictMode:

it('should not double invoke effects in legacy mode', async () => {

if (
root.tag === ConcurrentRoot &&
!(root.current.mode & (StrictLegacyMode | StrictEffectsMode))
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const disableJavaScriptURLs = false;
// Modern <StrictMode /> behaviour aligns more with what components
// components will encounter in production, especially when used With <Offscreen />.
// TODO: clean up legacy <StrictMode /> once tests pass WWW.
export const useModernStrictMode = false;
export const useModernStrictMode = __NEXT_MAJOR__;

// Not ready to break experimental yet.
// Remove IE and MsApp specific workarounds for innerHTML
Expand Down