-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Conversation
function instanceContainsElem(instance: Instance, element: HTMLElement) { | ||
let fiber = getClosestInstanceFromNode(element); | ||
while (fiber !== null) { | ||
if (fiber.tag === HostComponent && fiber.stateNode === element) { |
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.
It might be a bit strange that we expose Fiber details in the host config, but we do this in other places.
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. |
Details of bundled changes.Comparing: 9def56e...c13297b react-dom
ReactDOM: size: 0.0%, gzip: 🔺+0.3% Size changes (experimental) |
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.
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?
Details of bundled changes.Comparing: 9def56e...c13297b react-dom
ReactDOM: size: 0.0%, gzip: 0.0% Size changes (stable) |
48ed570
to
a393d91
Compare
if (enableDeprecatedFlareAPI && selectionInformation) { | ||
const focusedElem = selectionInformation.focusedElem; | ||
if (focusedElem !== null && instanceContainsElem(instance, focusedElem)) { | ||
dispatchBeforeDetachedBlur(((focusedElem: any): HTMLElement)); |
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.
Do we want to dispatch this event for the new event system too?
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.
We will eventually.
@@ -336,6 +338,68 @@ describe.each(table)('FocusWithin responder', hasPointerEvents => { | |||
expect.objectContaining({isTargetAttached: false}), | |||
); | |||
}); | |||
|
|||
it.experimental( |
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.
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
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.
Yeah, I thought that. It's best if this code moved out of Flare soon.
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, wedisplay: none
the content when showing the fallback, which means that the React Flare focus systems fail to know of the fact thatblur
is about to be triggered, which is required to properly handle focus management logic. This PR adds that code path in, soonBeforeBlur
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.