GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add concept of StrictMode levels 1 & 2 (no public API yet) by bvaughn · Pull Request #20844 · react/react

Conversation

@bvaughn

@bvaughn bvaughn commented Feb 18, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Stack

  • Add concept of StrictMode levels 1 & 2 (no public API yet) #20844: Add concept of StrictMode levels 1 & 2 (no public API yet)
  • Separate strict effects mode feature flags #20847: Separate strict effects mode feature flags
  • Add StrictMode level prop and createRoot unstable_strictModeLevel option #20849: Add StrictMode level prop and createRoot unstable_strictModeLevel option

Strict mode level 0 (aka loose or sloppy mode)

This isn't really a mode so much as it's the absence of any strict modes.

Strict mode level 1 (aka legacy mode)

The exported <React.StrictMode> tag remains the same and opts legacy subtrees into strict mode level one (mode == StrictLegacyMode). This mode enables DEV-only double rendering, double component lifecycles, string ref warnings, legacy context warnings, etc. The primary purpose of this mode is to help detected render phase side effects. No new behavior. Roots created with experimental createRoot and createBlockingRoot APIs will also (for now) continue to default to strict mode level 1.

Strict mode level 2 (aka strict effects mode)

In a subsequent commit I will add support for a "level" attribute on the <React.StrictMode> tag (as well as a new option supported by createRoot). This will be the way to opt into strict mode level 2 (mode == StrictEffectsMode). This mode will enable DEV-only double invoking of effects on initial mount (see #19523). This will simulate future Offscreen API semantics for trees being mounted, then hidden, and then shown again. The primary purpose of this mode is to enable applications to prepare for compatibility with the new Offscreen API (more information to follow shortly).

Strict mode level >= 3?

In the future we may add additional strict mode levels (TBD).

External changes?

For now, this commit changes no public facing behavior. The only mechanism for opting into strict mode level 2 is the pre-existing enableDoubleInvokingEffects feature flag (only enabled within Facebook for now).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Mathspy, eps1lon, awareness481, and joealden reacted with heart emoji
All reactions
  • ❤️ 4 reactions
@bvaughn
bvaughn requested review from acdlite, gaearon, rickhanlonii and sebmarkbage February 18, 2021 21:28
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 18, 2021
@bvaughn
bvaughn force-pushed the strict-mode-level-1-and-2 branch from e12cf07 to f0a5fac Compare February 18, 2021 21:30
acdlite
acdlite reviewed Feb 18, 2021
View reviewed changes
Comment thread packages/react-reconciler/src/ReactTypeOfMode.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sizebot

sizebot commented Feb 18, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Comparing: 4190a34...372bb8b

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 122.36 kB 122.36 kB = 39.41 kB 39.41 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 128.94 kB 128.94 kB = 41.47 kB 41.47 kB
facebook-www/ReactDOM-prod.classic.js +0.06% 404.67 kB 404.90 kB +0.07% 75.15 kB 75.20 kB
facebook-www/ReactDOM-prod.modern.js +0.06% 393.02 kB 393.24 kB +0.08% 73.24 kB 73.30 kB
facebook-www/ReactDOMForked-prod.classic.js +0.06% 404.68 kB 404.91 kB +0.07% 75.15 kB 75.20 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-debug-tools/cjs/react-debug-tools.development.js +0.48% 21.31 kB 21.41 kB +0.89% 5.84 kB 5.89 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.development.js +0.48% 21.31 kB 21.41 kB +0.89% 5.84 kB 5.89 kB

Generated by 🚫 dangerJS against 372bb8b

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dai-shi

dai-shi commented Feb 18, 2021

Copy link
Copy Markdown
Contributor

StrictMode level sounds nice.
I hope it would be possible to add useRef read warning on mutable values, at some level.
#18545 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bvaughn

bvaughn commented Feb 18, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Both of the new warnings you refer to are related to render phase side effects, so if anything they both belong in level 1. An argument could be made for warning about mutated refs even outside of strict mode.

dai-shi and tjallingt reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jacobp100

jacobp100 commented Feb 19, 2021

Copy link
Copy Markdown

Sorry if this is too off-topic - does this mean double invoking the functions passed to useEffect?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eps1lon

eps1lon commented Feb 19, 2021

Copy link
Copy Markdown
Collaborator

Sorry if this is too off-topic - does this mean double invoking the functions passed to useEffect?

@jacobp100 For what "strict effects mode" is, check out the original PR:

TL;DR: It doesn't just double invoke the functions passed to useEffect (create) but also runs their cleanup logic inbetween:

This PR changes the behavior in DEV when an effect runs from create() to create() -> destroy() -> create()

--#19523

jacobp100 and bvaughn reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bvaughn bvaughn mentioned this pull request Feb 19, 2021
Separate strict effects mode feature flags #20847
Closed
3 tasks done
@bvaughn bvaughn changed the title Add StrictMode levels 1 & 2 Add concept of StrictMode levels 1 & 2 (no public API yet) Feb 19, 2021
@bvaughn
bvaughn force-pushed the strict-mode-level-1-and-2 branch from e52ca35 to dd40e13 Compare February 19, 2021 16:33
@bvaughn bvaughn mentioned this pull request Feb 19, 2021
Add StrictMode level prop and createRoot unstable_strictModeLevel option #20849
Merged
3 tasks done
@bvaughn

bvaughn commented Feb 19, 2021

Copy link
Copy Markdown
Contributor Author

Circle CI doing something weird here I think. Hm. Should sort itself out next time I rebase onto master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rickhanlonii
rickhanlonii reviewed Feb 19, 2021
View reviewed changes

@rickhanlonii rickhanlonii left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I still wonder if we can wait on this until we have more information but happy to move forward if others want to approve and land.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bvaughn
bvaughn force-pushed the strict-mode-level-1-and-2 branch from dd40e13 to 11b8797 Compare February 22, 2021 20:09
@bvaughn
bvaughn requested review from acdlite and rickhanlonii February 23, 2021 14:51
rickhanlonii
rickhanlonii approved these changes Feb 24, 2021
View reviewed changes

@rickhanlonii rickhanlonii left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great, these changes are really exciting 🎉

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/react-reconciler/src/ReactChildFiber.new.js
import {emptyRefsObject} from './ReactFiberClassComponent.new';
import {isCompatibleFamilyForHotReloading} from './ReactFiberHotReloading.new';
import {StrictMode} from './ReactTypeOfMode';
import {StrictLegacyMode} from './ReactTypeOfMode';

@rickhanlonii rickhanlonii Feb 24, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Chatted offline and we can follow up with this if we agree - we may want to name this something other than "legacy" since the term overloaded to mean "legacy root", "legacy strict mode" and any other "legacys" we have. I was thinking something like:

  • NoMode = 0
  • StrictWarningMode = Level 1
  • StrictRenderMode = Level 2
  • StrictEffectMode = Level 3

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bvaughn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Brian Vaughn added 2 commits February 24, 2021 14:54
Brian Vaughn
The exported '<React.StrictMode>' tag remains the same and opts legac…
42f6a5e
…y subtrees into strict mode level one ('mode == StrictModeL1'). This mode enables DEV-only double rendering, double component lifecycles, string ref warnings, legacy context warnings, etc. The primary purpose of this mode is to help detected render phase side effects. No new behavior. Roots created with experimental 'createRoot' and 'createBlockingRoot' APIs will also (for now) continue to default to strict mode level 1.

In a subsequent commit I will add support for a 'level' attribute on the '<React.StrictMode>' tag (as well as a new option supported by ). This will be the way to opt into strict mode level 2 ('mode == StrictModeL2'). This mode will enable DEV-only double invoking of effects on initial mount. This will simulate future Offscreen API semantics for trees being mounted, then hidden, and then shown again. The primary purpose of this mode is to enable applications to prepare for compatibility with the new Offscreen API (more information to follow shortly).

For now, this commit changes no public facing behavior. The only mechanism for opting into strict mode level 2 is the pre-existing 'enableDoubleInvokingEffects' feature flag (only enabled within Facebook for now).
Brian Vaughn
Renamed strict mode constants
372bb8b
StrictModeL1 -> StrictLegacyMode and StrictModeL2 -> StrictEffectsMode
@bvaughn
bvaughn force-pushed the strict-mode-level-1-and-2 branch from 11b8797 to 372bb8b Compare February 24, 2021 20:24
@bvaughn

bvaughn commented Feb 24, 2021

Copy link
Copy Markdown
Contributor Author

Merged via #20849

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bvaughn bvaughn closed this Feb 24, 2021
@bvaughn
bvaughn deleted the strict-mode-level-1-and-2 branch February 24, 2021 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sebmarkbage sebmarkbage Awaiting requested review from sebmarkbage
@gaearon gaearon Awaiting requested review from gaearon
@acdlite acdlite Awaiting requested review from acdlite
1 more reviewer
@rickhanlonii rickhanlonii rickhanlonii approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@bvaughn @sizebot @dai-shi @jacobp100 @eps1lon @rickhanlonii @acdlite @facebook-github-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.