[DOM] Handle blur on Fragments below Document - #37062
Merged
Merged
Conversation
eps1lon
force-pushed
the
sebbie/fragment-ref-blur-document
branch
2 times, most recently
from
July 19, 2026 10:57
fb42f26 to
8dbbc6b
Compare
eps1lon
force-pushed
the
sebbie/fragment-ref-blur-document
branch
2 times, most recently
from
July 19, 2026 12:08
13280bf to
c31a171
Compare
Document
eps1lon
marked this pull request as ready for review
July 19, 2026 12:15
eps1lon
force-pushed
the
sebbie/fragment-ref-blur-document
branch
from
July 19, 2026 12:21
c1c16cb to
3e44489
Compare
daltino
approved these changes
Jul 19, 2026
daltino
left a comment
There was a problem hiding this comment.
The PR fixes handling blur events on Fragments below the Document by properly accounting for the document context via getOwnerDocumentFromRootContainer. The changes are minimal, coherent, and backed by a new test case to ensure the behavior is correct. Everything aligns with the contribution guidelines and seems ready to merge.
jackpope
approved these changes
Jul 19, 2026
eps1lon
disabled the stack merge
July 19, 2026 19:40
eps1lon
force-pushed
the
sebbie/fragment-ref-blur-document
branch
from
July 19, 2026 19:42
3e44489 to
ed407f7
Compare
… a Document When a FragmentInstance's nearest host parent fiber is the HostRoot, `getInstanceFromHostFiber` returns the root's `Container`. `blur()` reads `parentHostInstance.ownerDocument.activeElement` from it, but a `Document` container's `ownerDocument` is null, so the read throws. The test mounts the fragment above the `<html>` element of a root created on the document, where the nearest host parent is always the HostRoot. This keeps the coverage intact even once HostSingleton fibers are treated as host parents, which will stop fragments mounted under `<body>` from falling back to the root. The test pins down the current throwing behavior. The fix in the next commit flips it to asserting that the focused child inside the fragment actually loses focus. Co-Authored-By: Claude Fable 5 <[email protected]>
When a FragmentInstance's nearest host parent fiber is the HostRoot, `blur()` read `parentInstanceOrContainer.ownerDocument.activeElement` from the root's `Container`. A `Document` container's `ownerDocument` is null, so the read threw for fragments whose nearest host parent resolves to a root mounted on the document. The owner document is now resolved with the existing `getOwnerDocumentFromRootContainer` helper, which returns the container itself when it is a `Document`. The `contains(activeElement)` check and the rest of the flow already work on a `Document`. The test from the previous commit flips from asserting the throw to asserting that the focused child inside the fragment loses focus. Co-Authored-By: Claude Fable 5 <[email protected]>
eps1lon
force-pushed
the
sebbie/fragment-ref-blur-document
branch
from
July 20, 2026 20:44
ed407f7 to
54b6d91
Compare
|
Comparing: fa5212c...54b6d91 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
jackpope
approved these changes
Jul 21, 2026
github-actions Bot
pushed a commit
that referenced
this pull request
Jul 21, 2026
Co-authored-by: Claude Fable 5 <[email protected]> DiffTrain build for [862e275](862e275)
github-actions Bot
pushed a commit
that referenced
this pull request
Jul 21, 2026
Co-authored-by: Claude Fable 5 <[email protected]> DiffTrain build for [862e275](862e275)
github-actions Bot
pushed a commit
to HaroldHuanrongLIU/react
that referenced
this pull request
Jul 21, 2026
Co-authored-by: Claude Fable 5 <[email protected]> DiffTrain build for [862e275](react@862e275)
github-actions Bot
pushed a commit
to HaroldHuanrongLIU/react
that referenced
this pull request
Jul 21, 2026
Co-authored-by: Claude Fable 5 <[email protected]> DiffTrain build for [862e275](react@862e275)
github-actions Bot
pushed a commit
to code/lib-react
that referenced
this pull request
Jul 25, 2026
Co-authored-by: Claude Fable 5 <[email protected]> DiffTrain build for [862e275](react@862e275)
github-actions Bot
pushed a commit
to code/lib-react
that referenced
this pull request
Jul 25, 2026
Co-authored-by: Claude Fable 5 <[email protected]> DiffTrain build for [862e275](react@862e275)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we
blur, we check first if the active element is even within the Fragment to avoid having to traverse the whole subtree.However, assuming
ownerDocumentreturns aDocumentis incorrect for the cases where theNodeis aDocument. Then theownerDocumentisnull. We need to handle that case to avoidCannot read properties of null (reading 'activeElement').