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

Strict mode fix offscreen edge case #25322

Closed
wants to merge 1 commit into from

Conversation

sammy-SC
Copy link
Contributor

@sammy-SC sammy-SC commented Sep 24, 2022

We need to keep track of fibers that have had effects invoked twice.
To achieve this, this commit repurposes flag PlacementDEV to
NeedsDoubleInvokedEffectsDEV, which is unset by StrictMode.
Previous approach with Offscreen was not enough. When previously visible
Offscreen is hidden, it can have descendants added. Once Offscreen
becomes visible, only newly added components have to have their effects
double invoked. Not the previously existing components.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 24, 2022
@sizebot
Copy link

sizebot commented Sep 24, 2022

Comparing: cb5084d...ec54d7e

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 = 135.28 kB 135.28 kB = 43.39 kB 43.39 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 142.74 kB 142.74 kB = 45.58 kB 45.58 kB
facebook-www/ReactDOM-prod.classic.js = 490.70 kB 490.70 kB = 87.32 kB 87.32 kB
facebook-www/ReactDOM-prod.modern.js = 475.99 kB 475.99 kB = 85.13 kB 85.13 kB
facebook-www/ReactDOMForked-prod.classic.js = 490.70 kB 490.70 kB = 87.32 kB 87.32 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against ec54d7e

@sammy-SC sammy-SC force-pushed the strict-mode-fix-offscreen-edge-case branch 9 times, most recently from 9a30e80 to b76fd66 Compare September 25, 2022 18:40
We need to keep track of fibers that have had effects invoked twice.
To achieve this, this commit repurposes flag PlacementDEV to
`NeedsDoubleInvokedEffectsDEV`, which is unset by StrictMode.
Previous approach with Offscreen was not enough. When previously visible
Offscreen is hidden, it can have descendants added. Once Offscreen
becomes visible, only newly added components have to have their effects
double invoked. Not the previously existing components.

Co-authored-by: Robert Balicki <robertbalicki@fb.com>
@sammy-SC sammy-SC force-pushed the strict-mode-fix-offscreen-edge-case branch from b76fd66 to ec54d7e Compare September 25, 2022 18:44
@sammy-SC sammy-SC marked this pull request as ready for review September 25, 2022 18:44
Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

I don't think the behavior described by the test is worth the additional implementation complexity.

A hidden/detached tree is meant to behave identically to an unmounted tree, with the only difference being that the state is reused if it's later made visible again. So it's perfectly consistent to me that if a tree is hidden and then revealed, its effects would be double invoked. More to the point, though, it shouldn't matter either way.

I know you opened this PR because there's a Relay test that depended on the old behavior, but in what way? Is it an actual bug or did the test just happen to assert on a particular behavior?

Any code that is not resilient to double invoking a second time is almost certainly not resilient to actual production Offscreen behavior. Could we fix the Relay code instead? Or maybe the Relay code is fine, but the test is too coupled to implementation details?

@sammy-SC
Copy link
Contributor Author

You're right, hiding/showing Offscreen semantically should be the same as unmounting/mounting three. I thought it would be easier to fix this from our end to unblock the sync. Let me go back to Relay team and see what we can do from their end.

It seems they depend on this behaviour in several places, here is one if them.

@acdlite
Copy link
Collaborator

acdlite commented Sep 26, 2022

I think I recall @rbalicki2 said that code was only needed to prevent a duplicate refresh, but there's another strategy Relay could use to account for that instead

@acdlite
Copy link
Collaborator

acdlite commented Sep 26, 2022

If we do need to unblock the sync, it might be worth reverting the Strict Mode refactor (including the ref fix) until we're able to unblock Relay. But I suspect it might be easier to fix or skip those Relay tests instead, as long as it doesn't cause an issue in production.

@sammy-SC
Copy link
Contributor Author

To unblock the sync, we've decided to put new implementation of strict mode behind a feature flag: #25365

@sammy-SC sammy-SC closed this Sep 30, 2022
@sammy-SC sammy-SC deleted the strict-mode-fix-offscreen-edge-case branch September 30, 2022 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants