Skip to content

[DOM] Fix Fragment dispatchEvent when the container is a Document - #37165

Merged
jackpope merged 1 commit into
mainfrom
fragment-refs/dispatch-event-document-container
Aug 12, 2026
Merged

[DOM] Fix Fragment dispatchEvent when the container is a Document#37165
jackpope merged 1 commit into
mainfrom
fragment-refs/dispatch-event-document-container

Conversation

@jackpope

@jackpope jackpope commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

dispatchEvent appends a temporary Text node to the fragment's nearest host parent, but a Document can't contain Text, so createRoot(document) threw HierarchyRequestError whenever the fragment had a listener or the event didn't bubble.

Use a Comment node for Document containers: it is a legal document child and sits at the fragment's own position, unlike documentElement, which would put the target inside the fragment and fire its listeners twice.

@meta-cla meta-cla Bot added the CLA Signed label Jul 31, 2026
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 50c41c4 to 9ed52f6 Compare July 31, 2026 19:14
@github-actions github-actions Bot added the React Core Team Opened by a member of the React Core Team label Jul 31, 2026
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 9ed52f6 to 183e79d Compare July 31, 2026 20:15
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 183e79d to 0e06a46 Compare July 31, 2026 20:55
@jackpope
jackpope requested a review from eps1lon July 31, 2026 21:08
@jackpope
jackpope marked this pull request as ready for review July 31, 2026 21:08
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 0e06a46 to 377f084 Compare August 9, 2026 19:15
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 377f084 to d550553 Compare August 11, 2026 03:49
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from d550553 to 85a1474 Compare August 12, 2026 00:50
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 85a1474 to 4b0a229 Compare August 12, 2026 01:05

@poteto poteto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM (light skim). Stacking stamps for the fragment-refs land sequence.

@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from 4b0a229 to ba31100 Compare August 12, 2026 01:13
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from ba31100 to d3c60e9 Compare August 12, 2026 01:19
Base automatically changed from fragment-refs/text-child-event-listeners to main August 12, 2026 01:25
dispatchEvent appends a temporary Text node to the fragment's nearest
host parent, but a Document can't contain Text, so createRoot(document)
threw HierarchyRequestError whenever the fragment had a listener or the
event didn't bubble. Use a Comment node for Document containers: it is
a legal document child and sits at the fragment's own position, unlike
documentElement, which would put the target inside the fragment and
fire its listeners twice.
@jackpope
jackpope force-pushed the fragment-refs/dispatch-event-document-container branch from d3c60e9 to 627d3c3 Compare August 12, 2026 01:25
@react-sizebot

Copy link
Copy Markdown

Comparing: 18c30e7...627d3c3

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 7.35 kB 7.35 kB = 1.96 kB 1.96 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.01% 620.61 kB 620.70 kB +0.02% 109.71 kB 109.73 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.36 kB 7.36 kB +0.05% 1.96 kB 1.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.01% 691.82 kB 691.91 kB +0.02% 121.20 kB 121.22 kB
facebook-www/ReactDOM-prod.classic.js +0.01% 712.02 kB 712.11 kB +0.02% 124.66 kB 124.69 kB
facebook-www/ReactDOM-prod.modern.js +0.01% 702.33 kB 702.42 kB +0.02% 123.09 kB 123.11 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 627d3c3

@jackpope
jackpope merged commit 305feb9 into main Aug 12, 2026
465 of 466 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 12, 2026
…7165)

dispatchEvent appends a temporary Text node to the fragment's nearest
host parent, but a Document can't contain Text, so createRoot(document)
threw HierarchyRequestError whenever the fragment had a listener or the
event didn't bubble.

Use a Comment node for Document containers: it is a legal document child
and sits at the fragment's own position, unlike documentElement, which
would put the target inside the fragment and fire its listeners twice.

DiffTrain build for [305feb9](305feb9)
github-actions Bot pushed a commit that referenced this pull request Aug 12, 2026
…7165)

dispatchEvent appends a temporary Text node to the fragment's nearest
host parent, but a Document can't contain Text, so createRoot(document)
threw HierarchyRequestError whenever the fragment had a listener or the
event didn't bubble.

Use a Comment node for Document containers: it is a legal document child
and sits at the fragment's own position, unlike documentElement, which
would put the target inside the fragment and fire its listeners twice.

DiffTrain build for [305feb9](305feb9)
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