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

Fix sloppy factoring in performSyncWorkOnRoot #21246

Merged
merged 2 commits into from
Apr 20, 2021

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Apr 13, 2021

finishedLanes is sometimes NoLanes in the commit phase, which is wrong. See #21233 for additional context.

I added a dev-only internal warning that fires whenever this is the case. That's the first commit, which causes a handful of test failures. I opted to go this route instead of writing dedicated tests because the exact codepath that triggers this scenario isn't that interesting and likely wouldn't survive a refactor. The warning is like an internal property invariant that ensures the model is consistent even if implementation details around it change. It also covers future features or codepaths that might affect finishedLanes.

The second commit fixes all these warnings by refactoring performSyncWorkOnRoot and performConcurrentWorkOnRoot. See commit message for details.

acdlite added 2 commits April 12, 2021 23:20
`finishedLanes` is assigned in `performSyncWorkOnRoot` and
`performSyncWorkOnRoot`. It's meant to represent whichever lanes we
used to render, but because of some sloppy factoring, it can sometimes
equal `NoLanes`.

The fixes are:
- Always check if the lanes are not `NoLanes` before entering the work
loop. There was a branch where this wasn't always true.
- In `performSyncWorkOnRoot`, don't assume the next lanes are sync; the
priority may have changed, or they may have been flushed by a
previous task.
- Don't re-assign the `lanes` variable (the one that gets assigned to
`finishedLanes` until right before we enter the work loop, so that it
is always corresponds to the newest complete root.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 13, 2021
@sizebot
Copy link

sizebot commented Apr 13, 2021

Comparing: 84c06fe...27fea88

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 +0.06% 122.68 kB 122.75 kB +0.06% 39.38 kB 39.40 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.05% 129.25 kB 129.32 kB +0.06% 41.46 kB 41.49 kB
facebook-www/ReactDOM-prod.classic.js +0.07% 412.18 kB 412.47 kB +0.07% 76.23 kB 76.28 kB
facebook-www/ReactDOM-prod.modern.js +0.07% 400.23 kB 400.53 kB +0.07% 74.32 kB 74.37 kB
facebook-www/ReactDOMForked-prod.classic.js +0.07% 412.18 kB 412.47 kB +0.07% 76.23 kB 76.29 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 27fea88

@acdlite acdlite requested a review from rickhanlonii April 13, 2021 05:01
@acdlite acdlite marked this pull request as ready for review April 13, 2021 05:02
@acdlite acdlite force-pushed the fix-finishedlanes branch from c857453 to 27fea88 Compare April 13, 2021 05:10
Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

LGTM

@acdlite acdlite merged commit bd7f4a0 into facebook:master Apr 20, 2021
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 21, 2021
Summary:
This sync includes the following changes:
- **[bd7f4a013](facebook/react@bd7f4a013 )**: Fix sloppy factoring in `performSyncWorkOnRoot` ([#21246](facebook/react#21246)) //<Andrew Clark>//
- **[78120032d](facebook/react@78120032d )**: Remove `flushDiscreteUpdates` from end of event ([#21223](facebook/react#21223)) //<Andrew Clark>//
- **[a3a7adb83](facebook/react@a3a7adb83 )**: Turn off enableSyncDefaultUpdates in test renderer ([#21319](facebook/react#21319)) //<Ricky>//
- **[cdb6b4c55](facebook/react@cdb6b4c55 )**: Only hide outermost host nodes when Offscreen is hidden ([#21250](facebook/react#21250)) //<Brian Vaughn>//
- **[b9c6a2b30](facebook/react@b9c6a2b30 )**: Remove LayoutStatic check from commit phase ([#21249](facebook/react#21249)) //<Brian Vaughn>//
- **[af1a4cbf7](facebook/react@af1a4cbf7 )**: Revert expiration for retry lanes ([#21300](facebook/react#21300)) //<Andrew Clark>//
- **[cc4b431da](facebook/react@cc4b431da )**: Mark boundary as client rendered even if aborting fallback ([#21294](facebook/react#21294)) //<Sebastian Markbåge>//

Changelog:
[General][Changed] - React Native sync for revisions f7cdc89...bd7f4a0

jest_e2e[run_all_tests]

Reviewed By: JoshuaGross

Differential Revision: D27909257

fbshipit-source-id: 36ec4cf1de9df109f1fe1542031df10a693baae0
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
* Warn if `finishedLanes` is empty in commit phase

See facebook#21233 for context.

* Fix sloppy factoring when assigning finishedLanes

`finishedLanes` is assigned in `performSyncWorkOnRoot` and
`performSyncWorkOnRoot`. It's meant to represent whichever lanes we
used to render, but because of some sloppy factoring, it can sometimes
equal `NoLanes`.

The fixes are:
- Always check if the lanes are not `NoLanes` before entering the work
loop. There was a branch where this wasn't always true.
- In `performSyncWorkOnRoot`, don't assume the next lanes are sync; the
priority may have changed, or they may have been flushed by a
previous task.
- Don't re-assign the `lanes` variable (the one that gets assigned to
`finishedLanes` until right before we enter the work loop, so that it
is always corresponds to the newest complete root.
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