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

[react-interactions] Ensure onBeforeBlur fires for hideInstance #18064

Merged
merged 2 commits into from
Feb 18, 2020

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Feb 18, 2020

As part of the React Flare system, we have the notion of a React specific event called onBeforeBlur. This is meant to triggered just before a managed node of React gets removed or hidden from the UI. We already support the case where this fires before we removed the node, but we didn't have a codepath or support for when this can occur during Suspense. During Suspense, we display: none the content when showing the fallback, which means that the React Flare focus systems fail to know of the fact that blur is about to be triggered, which is required to properly handle focus management logic. This PR adds that code path in, so onBeforeBlur correctly fires during Suspense too.

On a separate node, we should move this logic and other existing onBeforeBlur logic out of the Flare flag sometime and make it its own core feature at some point.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 18, 2020
function instanceContainsElem(instance: Instance, element: HTMLElement) {
let fiber = getClosestInstanceFromNode(element);
while (fiber !== null) {
if (fiber.tag === HostComponent && fiber.stateNode === element) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be a bit strange that we expose Fiber details in the host config, but we do this in other places.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 18, 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.

@sizebot
Copy link

sizebot commented Feb 18, 2020

Details of bundled changes.

Comparing: 9def56e...c13297b

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% 0.0% 123.73 KB 123.73 KB 38.72 KB 38.72 KB NODE_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
ReactDOM-dev.js +0.1% +0.1% 988.16 KB 988.91 KB 217.83 KB 218.02 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.21 KB 1.21 KB 709 B 711 B UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 55.46 KB 55.46 KB 15.61 KB 15.61 KB UMD_DEV
react-dom-testing.profiling.min.js 0.0% 0.0% 121.28 KB 121.28 KB 38.28 KB 38.28 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 139.25 KB 139.25 KB 36.93 KB 36.93 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.21 KB 11.21 KB 4.17 KB 4.16 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.46 KB 20.46 KB 7.5 KB 7.5 KB UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 53.73 KB 53.73 KB 15.29 KB 15.29 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.99 KB 10.99 KB 4.1 KB 4.1 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.39 KB 20.39 KB 7.47 KB 7.47 KB NODE_PROD
react-dom.development.js +0.1% +0.1% 967.74 KB 968.5 KB 217.27 KB 217.46 KB UMD_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.73 KB 58.73 KB 15.35 KB 15.36 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 119.88 KB 119.88 KB 38.31 KB 38.31 KB UMD_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.25 KB 10.25 KB 3.47 KB 3.48 KB UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 140.25 KB 140.25 KB 35.5 KB 35.5 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% 0.0% 123.51 KB 123.51 KB 39.5 KB 39.5 KB UMD_PROFILING
ReactDOMServer-prod.js 0.0% 0.0% 48.27 KB 48.27 KB 11.02 KB 11.02 KB FB_WWW_PROD
react-dom.development.js +0.1% +0.1% 961.82 KB 962.58 KB 215.64 KB 215.84 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.43 KB 58.43 KB 15.28 KB 15.28 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 119.94 KB 119.94 KB 37.58 KB 37.58 KB NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 9.99 KB 9.99 KB 3.38 KB 3.38 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.1% 1.21 KB 1.21 KB 697 B 698 B NODE_PROD
ReactDOM-prod.js 🔺+0.2% 🔺+0.3% 371.73 KB 372.51 KB 67.49 KB 67.66 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.3% 383.04 KB 383.81 KB 69.55 KB 69.73 KB FB_WWW_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.5% 1.05 KB 1.05 KB 640 B 643 B NODE_PROD
react-dom-testing.development.js +0.1% +0.1% 965.09 KB 965.85 KB 216.27 KB 216.46 KB UMD_DEV
react-dom-testing.production.min.js 0.0% 0.0% 117.53 KB 117.53 KB 37.86 KB 37.86 KB UMD_PROD
ReactDOMTesting-dev.js +0.1% +0.1% 987.76 KB 988.51 KB 217.71 KB 217.91 KB FB_WWW_DEV
react-dom-testing.profiling.min.js 0.0% 0.0% 121.05 KB 121.05 KB 39 KB 39 KB UMD_PROFILING
ReactDOMTesting-prod.js 🔺+0.2% 🔺+0.3% 370.12 KB 370.89 KB 67.43 KB 67.6 KB FB_WWW_PROD
react-dom-testing.development.js +0.1% +0.1% 959.18 KB 959.94 KB 214.64 KB 214.83 KB NODE_DEV
ReactDOMTesting-profiling.js +0.2% +0.3% 370.12 KB 370.89 KB 67.43 KB 67.6 KB FB_WWW_PROFILING
react-dom-server.node.development.js 0.0% 0.0% 136.29 KB 136.29 KB 36.14 KB 36.14 KB NODE_DEV
react-dom-testing.production.min.js 0.0% 0.0% 117.61 KB 117.61 KB 37.17 KB 37.17 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 🔺+0.3%

Size changes (experimental)

Generated by 🚫 dangerJS against c13297b

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

I'm concerned we're adding more to an already deprecated codepath — which might make it harder to get rid of it later because it would lead to regressions. I'm also not sure if this is a hot path or not. I guess not because it only happens for the receded state?

@sizebot
Copy link

sizebot commented Feb 18, 2020

Details of bundled changes.

Comparing: 9def56e...c13297b

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-profiling.js +0.2% +0.2% 406.7 KB 407.47 KB 73.91 KB 74.08 KB FB_WWW_PROFILING
react-dom-testing.production.min.js 0.0% 0.0% 117.08 KB 117.08 KB 37.03 KB 37.03 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.72 KB 58.72 KB 15.35 KB 15.35 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.04 KB 1.04 KB 633 B 635 B NODE_PROD
react-dom-testing.profiling.min.js 0.0% 0.0% 120.75 KB 120.75 KB 38.14 KB 38.14 KB NODE_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10.24 KB 10.24 KB 3.47 KB 3.47 KB UMD_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom.development.js +0.1% +0.1% 967.72 KB 968.47 KB 217.25 KB 217.45 KB UMD_DEV
react-dom-server.browser.development.js 0.0% 0.0% 139.22 KB 139.22 KB 36.93 KB 36.93 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.2 KB 1.2 KB 688 B 690 B NODE_PROD
react-dom.production.min.js 0.0% 0.0% 115.96 KB 115.96 KB 37.21 KB 37.21 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20 KB 20 KB 7.4 KB 7.4 KB UMD_PROD
ReactDOMTesting-dev.js +0.1% +0.1% 987.75 KB 988.51 KB 217.7 KB 217.9 KB FB_WWW_DEV
react-dom.development.js +0.1% +0.1% 961.8 KB 962.56 KB 215.63 KB 215.83 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.2% 🔺+0.2% 382.42 KB 383.2 KB 69.49 KB 69.66 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 135.16 KB 135.16 KB 35.9 KB 35.9 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116 KB 116 KB 36.55 KB 36.55 KB NODE_PROD
react-dom-testing.development.js +0.1% +0.1% 965.07 KB 965.83 KB 216.25 KB 216.45 KB UMD_DEV
ReactDOMTesting-profiling.js +0.2% +0.2% 382.42 KB 383.2 KB 69.49 KB 69.66 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.93 KB 19.93 KB 7.39 KB 7.39 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom.profiling.min.js 0.0% 0.0% 119.67 KB 119.67 KB 37.67 KB 37.67 KB NODE_PROFILING
react-dom-testing.production.min.js 0.0% 0.0% 117 KB 117 KB 37.71 KB 37.71 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.2 KB 1.2 KB 701 B 703 B UMD_PROD
ReactDOM-dev.js +0.1% +0.1% 989.1 KB 989.86 KB 218.14 KB 218.34 KB FB_WWW_DEV
react-dom-testing.profiling.min.js 0.0% 0.0% 120.52 KB 120.52 KB 38.85 KB 38.85 KB UMD_PROFILING
ReactDOMServer-dev.js 0.0% 0.0% 140.24 KB 140.24 KB 35.5 KB 35.5 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.2% 395.37 KB 396.14 KB 71.82 KB 71.99 KB FB_WWW_PROD
react-dom-testing.development.js +0.1% +0.1% 959.15 KB 959.91 KB 214.63 KB 214.82 KB NODE_DEV
ReactDOMServer-prod.js 0.0% 0.0% 48.98 KB 48.98 KB 11.18 KB 11.18 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.7 KB 3.7 KB 1.49 KB 1.5 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.42 KB 58.42 KB 15.27 KB 15.28 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 55.44 KB 55.44 KB 15.61 KB 15.61 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 9.98 KB 9.98 KB 3.37 KB 3.37 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 11.2 KB 11.2 KB 4.16 KB 4.16 KB UMD_PROD
react-dom-test-utils.development.js 0.0% 0.0% 53.71 KB 53.71 KB 15.29 KB 15.29 KB NODE_DEV
react-dom-server.node.development.js 0.0% 0.0% 136.27 KB 136.27 KB 36.13 KB 36.13 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.97 KB 10.97 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.34 KB 20.34 KB 7.54 KB 7.54 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against c13297b

@trueadm trueadm force-pushed the onbeforeblur-hideinstance branch from 48ed570 to a393d91 Compare February 18, 2020 13:35
packages/react-dom/src/client/ReactDOMHostConfig.js Outdated Show resolved Hide resolved
if (enableDeprecatedFlareAPI && selectionInformation) {
const focusedElem = selectionInformation.focusedElem;
if (focusedElem !== null && instanceContainsElem(instance, focusedElem)) {
dispatchBeforeDetachedBlur(((focusedElem: any): HTMLElement));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to dispatch this event for the new event system too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will eventually.

@@ -336,6 +338,68 @@ describe.each(table)('FocusWithin responder', hasPointerEvents => {
expect.objectContaining({isTargetAttached: false}),
);
});

it.experimental(
Copy link
Contributor

Choose a reason for hiding this comment

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

These kinds of unit tests that involve the scheduler don't feel like they belong in the responders to me. Doesn't really matter right now since all this is going away eventually. But it makes me think about how we decide where the boundaries lie, as did your PR that rearranged the DOM event plugin system and its tests for the better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought that. It's best if this code moved out of Flare soon.

@trueadm trueadm merged commit 1a6d817 into facebook:master Feb 18, 2020
@trueadm trueadm deleted the onbeforeblur-hideinstance branch February 18, 2020 18:50
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.

5 participants