Skip to content

Bugfix: Infinite loop in beforeblur event #19053

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

Merged
merged 3 commits into from
Jun 1, 2020

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented May 30, 2020

If the focused node is hidden by a Suspense boundary, we fire the beforeblur event. Our check for whether a tree is being hidden isn't specific enough. It should only fire when the tree is initially hidden, but it's being fired for updates, too.

To optimize this, we should use a dedicated effect tag and mark it in the render phase. I've left this for a follow-up, though. Maybe can revisit after the planned refactor of the commit phase.

If the focused node is hidden by a Suspense boundary, we fire the
beforeblur event. Our check for whether a tree is being hidden isn't
specific enough. It should only fire when the tree is initially hidden,
but it's being fired for updates, too.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels May 30, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 30, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ec032c8:

Sandbox Source
rough-snow-jtm78 Configuration

@sizebot
Copy link

sizebot commented May 30, 2020

Details of bundled changes.

Comparing: 1d85bb3...ec032c8

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js 0.0% 0.0% 876.43 KB 876.54 KB 199.56 KB 199.59 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.1% 0.0% 442.54 KB 442.8 KB 79.79 KB 79.79 KB FB_WWW_PROD
react-dom.production.min.js 0.0% -0.0% 121.16 KB 121.2 KB 37.9 KB 37.9 KB NODE_PROD
ReactDOMForked-profiling.js +0.1% 0.0% 453.13 KB 453.4 KB 81.55 KB 81.55 KB FB_WWW_PROFILING
ReactDOMTesting-dev.js 0.0% 0.0% 963.12 KB 963.43 KB 214.98 KB 215.05 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 70.08 KB 70.08 KB 19.59 KB 19.59 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.1% 0.0% 406.25 KB 406.52 KB 74.89 KB 74.9 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 13.05 KB 13.05 KB 4.8 KB 4.8 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 920.78 KB 920.9 KB 202.09 KB 202.11 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 121.05 KB 121.09 KB 38.84 KB 38.83 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 125.02 KB 125.06 KB 40.08 KB 40.09 KB UMD_PROFILING
ReactDOMForked-dev.js 0.0% 0.0% 1.04 MB 1.04 MB 238.74 KB 238.8 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% -0.0% 125.26 KB 125.3 KB 39.13 KB 39.12 KB NODE_PROFILING
ReactDOM-dev.js 0.0% 0.0% 1.04 MB 1.04 MB 236.52 KB 236.58 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 0.0% 445.11 KB 445.37 KB 78.75 KB 78.77 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% 0.0% 456.64 KB 456.9 KB 80.67 KB 80.69 KB FB_WWW_PROFILING
ReactDOMServer-dev.js 0.0% 0.0% 146.67 KB 146.67 KB 37.29 KB 37.29 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 75.25 KB 75.25 KB 20.09 KB 20.09 KB UMD_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js 0.0% -0.0% 604.98 KB 605.12 KB 128.14 KB 128.12 KB NODE_DEV
react-reconciler-reflection.development.js -3.7% -2.2% 17.33 KB 16.68 KB 5.09 KB 4.98 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.1% 0.0% 82.57 KB 82.61 KB 24.65 KB 24.65 KB NODE_PROD
react-reconciler-reflection.production.min.js -4.1% -4.6% 2.91 KB 2.8 KB 1.21 KB 1.15 KB NODE_PROD

Size changes (stable)

Generated by 🚫 dangerJS against ec032c8

@sizebot
Copy link

sizebot commented May 30, 2020

Details of bundled changes.

Comparing: 1d85bb3...ec032c8

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js 0.0% 0.0% 910.38 KB 910.49 KB 206.19 KB 206.22 KB NODE_DEV
ReactDOMForked-prod.js 🔺+0.1% 0.0% 431.35 KB 431.61 KB 77.92 KB 77.93 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 138.24 KB 138.24 KB 36.58 KB 36.58 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 126.2 KB 126.24 KB 39.37 KB 39.37 KB NODE_PROD
ReactDOMForked-profiling.js +0.1% 0.0% 441.88 KB 442.15 KB 79.66 KB 79.67 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 0.0% 13.18 KB 13.18 KB 4.9 KB 4.9 KB UMD_PROD
ReactDOMTesting-dev.js 0.0% 0.0% 937.33 KB 937.64 KB 209.44 KB 209.5 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 70.09 KB 70.09 KB 19.6 KB 19.6 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.1% 0.0% 394.4 KB 394.66 KB 73.01 KB 73.01 KB FB_WWW_PROD
react-dom-test-utils.production.min.js 0.0% 0.0% 13.06 KB 13.06 KB 4.8 KB 4.81 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 5.36 KB 5.36 KB 1.8 KB 1.8 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.17 KB 1.17 KB 665 B 666 B NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.2 KB 1.2 KB 705 B 706 B UMD_PROD
react-dom.development.js 0.0% 0.0% 956.26 KB 956.38 KB 208.79 KB 208.81 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.2% 1.01 KB 1.01 KB 615 B 616 B NODE_PROD
react-dom.production.min.js 0.0% 0.0% 126.01 KB 126.04 KB 40.35 KB 40.35 KB UMD_PROD
react-dom.profiling.min.js 0.0% -0.0% 130.11 KB 130.15 KB 41.58 KB 41.57 KB UMD_PROFILING
ReactDOMForked-dev.js 0.0% 0.0% 1.02 MB 1.02 MB 233.05 KB 233.11 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% 0.0% 130.44 KB 130.48 KB 40.65 KB 40.66 KB NODE_PROFILING
ReactDOM-dev.js 0.0% 0.0% 1.01 MB 1.01 MB 230.93 KB 231 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 0.0% 434.04 KB 434.3 KB 76.9 KB 76.92 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% 0.0% 445.5 KB 445.77 KB 78.8 KB 78.83 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 20.26 KB 20.26 KB 7.51 KB 7.51 KB NODE_PROD
ReactDOMServer-dev.js 0.0% 0.0% 142.63 KB 142.63 KB 36.29 KB 36.29 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 46.58 KB 46.58 KB 10.9 KB 10.9 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 75.26 KB 75.26 KB 20.1 KB 20.1 KB UMD_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js 0.0% -0.0% 632.27 KB 632.42 KB 133.74 KB 133.73 KB NODE_DEV
react-reconciler-reflection.development.js -3.7% -2.2% 17.34 KB 16.7 KB 5.09 KB 4.98 KB NODE_DEV
react-reconciler.production.min.js 0.0% 🔺+0.1% 86.5 KB 86.54 KB 25.78 KB 25.8 KB NODE_PROD
react-reconciler-reflection.production.min.js -4.0% -4.5% 2.93 KB 2.81 KB 1.21 KB 1.16 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against ec032c8

Should only beforeblur fire if the node was previously visible. Not
during updates to an already hidden tree.

To optimize this, we should use a dedicated effect tag and mark it in
the render phase. I've left this for a follow-up, though. Maybe can
revisit after the planned refactor of the commit phase.
@acdlite acdlite changed the title Failing test: Infinite loop in beforeblur event Bugfix: Infinite loop in beforeblur event Jun 1, 2020
@acdlite acdlite requested a review from trueadm June 1, 2020 06:55
@acdlite acdlite marked this pull request as ready for review June 1, 2020 07:05
@@ -333,13 +333,21 @@ export function findCurrentHostFiberWithNoPortals(parent: Fiber): Fiber | null {
return null;
}

// This function detects when a Suspense boundary goes from visible to hidden.
// It returns false if the boundary is already hidden.
// TODO: Use an effect tag. And move this to ReactFiberCommitWork.
export function isFiberSuspenseAndTimedOut(fiber: Fiber): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is also used by Scopes for traversal, will this change affect that too? See:

https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberScope.new.js#L51

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My mistake, didn't search for other uses.

I moved the logic into the commit phase.

isFiberSuspenseAndTimedOut is used elsewhere, so I inlined the commit
logic into the commit phase itself.
@acdlite acdlite force-pushed the blur-infinite-loop branch 2 times, most recently from 954048d to 1f52fe2 Compare June 1, 2020 15:21
Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

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

Thanks for these changes! Makes sense to me :)

@acdlite acdlite force-pushed the blur-infinite-loop branch from 1f52fe2 to ec032c8 Compare June 1, 2020 15:30
@acdlite
Copy link
Collaborator Author

acdlite commented Jun 1, 2020

Thanks for the quick review!

@acdlite acdlite merged commit 4c7036e into facebook:master Jun 1, 2020
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