-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
Double invoke effects in a subtree wrapped with StrictMode
#32315
Open
Andarist
wants to merge
2
commits into
facebook:main
Choose a base branch
from
Andarist:fix/double-invoke-effects-in-subtree-strict-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Double invoke effects in a subtree wrapped with StrictMode
#32315
Andarist
wants to merge
2
commits into
facebook:main
from
Andarist:fix/double-invoke-effects-in-subtree-strict-mode
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comparing: ff62833...89afbaa Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
Andarist
commented
Feb 6, 2025
@@ -4079,16 +4079,20 @@ function flushRenderPhaseStrictModeWarningsInDEV() { | |||
function recursivelyTraverseAndDoubleInvokeEffectsInDEV( | |||
root: FiberRoot, | |||
parentFiber: Fiber, | |||
treeFlags: Flags, |
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.
- The problem is that in this scenario only the root gets
PlacementDev
flag becausereconcileChildren
routes tomountChildFibers
for all of the descendant's fibers. - That in turn is a reconciler function created with
shouldTrackSideEffects === false
- So
.subtreeFlags
can't be relied upon because, well, those flags are not set on those descendant fibers so they are also not propagated onto their ancestors'.subtreeFlags
That led me to propagate the treeFlags
through the callers' chain here
82ee1ee
to
5af49d5
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Currently, strict effects don't behave as expected when
StrictMode
isn't placed at the root of the app. Wrapping only a part of the app is a valid use case described in the docs: https://react.dev/reference/react/StrictMode#enabling-strict-mode-for-a-part-of-the-appHow did you test this change?
I added tests in the repo to verify that it works 😉
I expect some subtleties around this so this might not be a fully correct PR (yet). With some guidance I could improve it. I'm especially not sure if the code paths related to Offscree/Visibility are changed correctly. If you could suggest some extra test cases for them, I'd appreciate it