Skip to content

Fix parentNode for nested root host views like <Modal>#57623

Closed
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D113012362
Closed

Fix parentNode for nested root host views like <Modal>#57623
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D113012362

Conversation

@rubennorte

Copy link
Copy Markdown
Member

Summary:
NativeDOM::getParentNode returned the document for any shadow node carrying the RootNodeKind trait. That trait is set not only on a surface's actual root node but also on nested host views such as <Modal> (and portal/overlay-style components), so their parentNode/parentElement incorrectly resolved to the document instead of their real containing element.

Because the EventTarget-based event dispatch builds its capture/bubble ancestor path by walking getParentNode up the shadow tree, this truncated the path at the modal boundary: a listener registered on an ancestor rendered above the modal never received events (e.g. focus/blur) originating inside it.

Fix by returning the document only for the surface's actual root node, identified via ShadowNode::sameFamily(*currentRevision, *shadowNode). Every other node — including nested root-kind nodes — now reports its real structural parent, while disconnected nodes still report none.

Changelog:
[General][Fixed] - Fix parentNode/parentElement returning the document instead of the containing element for <Modal> and other nested root host views, which severed capture/bubble event propagation to ancestors rendered above them

Differential Revision: D113012362

Summary:
`NativeDOM::getParentNode` returned the document for any shadow node carrying the `RootNodeKind` trait. That trait is set not only on a surface's actual root node but also on nested host views such as `<Modal>` (and portal/overlay-style components), so their `parentNode`/`parentElement` incorrectly resolved to the document instead of their real containing element.

Because the EventTarget-based event dispatch builds its capture/bubble ancestor path by walking `getParentNode` up the shadow tree, this truncated the path at the modal boundary: a listener registered on an ancestor rendered above the modal never received events (e.g. focus/blur) originating inside it.

Fix by returning the document only for the surface's actual root node, identified via `ShadowNode::sameFamily(*currentRevision, *shadowNode)`. Every other node — including nested root-kind nodes — now reports its real structural parent, while disconnected nodes still report none.

Changelog:
[General][Fixed] - Fix `parentNode`/`parentElement` returning the document instead of the containing element for `<Modal>` and other nested root host views, which severed capture/bubble event propagation to ancestors rendered above them

Differential Revision: D113012362
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 21, 2026
@meta-codesync

meta-codesync Bot commented Jul 21, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113012362.

@meta-codesync meta-codesync Bot closed this in e410ff5 Jul 21, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jul 21, 2026
@meta-codesync

meta-codesync Bot commented Jul 21, 2026

Copy link
Copy Markdown

This pull request has been merged in e410ff5.

@rubennorte
rubennorte deleted the export-D113012362 branch July 22, 2026 11:29
react-native-bot pushed a commit that referenced this pull request Jul 22, 2026
Summary:
Pull Request resolved: #57623

`NativeDOM::getParentNode` returned the document for any shadow node carrying the `RootNodeKind` trait. That trait is set not only on a surface's actual root node but also on nested host views such as `<Modal>` (and portal/overlay-style components), so their `parentNode`/`parentElement` incorrectly resolved to the document instead of their real containing element.

Because the EventTarget-based event dispatch builds its capture/bubble ancestor path by walking `getParentNode` up the shadow tree, this truncated the path at the modal boundary: a listener registered on an ancestor rendered above the modal never received events (e.g. focus/blur) originating inside it.

Fix by returning the document only for the surface's actual root node, identified via `ShadowNode::sameFamily(*currentRevision, *shadowNode)`. Every other node — including nested root-kind nodes — now reports its real structural parent, while disconnected nodes still report none.

Changelog:
[General][Fixed] - Fix `parentNode`/`parentElement` returning the document instead of the containing element for `<Modal>` and other nested root host views, which severed capture/bubble event propagation to ancestors rendered above them

Reviewed By: javache

Differential Revision: D113012362

fbshipit-source-id: 88043a9b9de128e7c3c96d8516b0950cbd6c3c68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant