Skip to content

Treat fragment parser documents as not connected#1474

Closed
shannonbooth wants to merge 1 commit into
whatwg:mainfrom
shannonbooth:fragment-parser
Closed

Treat fragment parser documents as not connected#1474
shannonbooth wants to merge 1 commit into
whatwg:mainfrom
shannonbooth:fragment-parser

Conversation

@shannonbooth

@shannonbooth shannonbooth commented Jun 24, 2026

Copy link
Copy Markdown
Member

Matching the behaviour of engines. For: whatwg/html#11023, but needs a small patch in HTML spec also, which I will raise if directionally this is okay.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@annevk

annevk commented Jun 24, 2026

Copy link
Copy Markdown
Member

I don't like changing the meaning of connected for this. It feels a bit like a layering violation. Also, as discovered in whatwg/html#11669 (comment) I don't think this will actually do the trick long term as not all browsers create an intermediate document.

I wonder if @noamr and @foolip have ideas on how to address this properly.

@noamr

noamr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I don't like changing the meaning of connected for this. It feels a bit like a layering violation. Also, as discovered in whatwg/html#11669 (comment) I don't think this will actually do the trick long term as not all browsers create an intermediate document.

I wonder if @noamr and @foolip have ideas on how to address this properly.

I think a more consistent approach would be to insert elements directly to the DocumentFragment rather than inserting them to the inert document and then moving them to the fragment in bulk.
Then they wouldn't be "connected" in the first place and we don't need a DOM change.

@shannonbooth
shannonbooth marked this pull request as draft June 24, 2026 15:39
@shannonbooth

Copy link
Copy Markdown
Member Author

Indeed it feels a bit yuck, though it doesn't seem possible to change in a nice way as long as connected is defined in terms of document and fragment parsing requires a document. If we can wire up fragment parsing without a document that indeed seems much nicer, I can try and investigate that approach (unless this is already being worked on based on what is mentioned above?)

@noamr

noamr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Indeed it feels a bit yuck, though it doesn't seem possible to change in a nice way as long as connected is defined in terms of document and fragment parsing requires a document. If we can wire up fragment parsing without a document that indeed seems much nicer, I can try and investigate that approach (unless this is already being worked on based on what is mentioned above?)

An element inserted to a DocumentFragment is never connected so I think it would solve this.

Note that multiple in-flight and upcoming changes like whatwg/html#11818 are doing this work through redirecting the insertion target (see https://html.spec.whatwg.org/multipage/parsing.html#appropriate-place-for-inserting-a-node). This would probably be the place to fix it as well. I would prefer if we do this after these in-flight changes are complete though.

@WebReflection

Copy link
Copy Markdown

An element inserted to a DocumentFragment is never connected so I think it would solve this.

if persistent document fragment will ever exist, the element is connected "if the fragment is" so please consider the fact in the future there could be live/persistent document fragments, thank you!

@noamr

noamr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

An element inserted to a DocumentFragment is never connected so I think it would solve this.

if persistent document fragment will ever exist, the element is connected "if the fragment is" so please consider the fact in the future there could be live/persistent document fragments, thank you!

Sure, but in this case it wouldn't be that future type of fragment, but a normal disconnected fragment.

@shannonbooth

Copy link
Copy Markdown
Member Author

Indeed it feels a bit yuck, though it doesn't seem possible to change in a nice way as long as connected is defined in terms of document and fragment parsing requires a document. If we can wire up fragment parsing without a document that indeed seems much nicer, I can try and investigate that approach (unless this is already being worked on based on what is mentioned above?)

An element inserted to a DocumentFragment is never connected so I think it would solve this.

Note that multiple in-flight and upcoming changes like whatwg/html#11818 are doing this work through redirecting the insertion target (see https://html.spec.whatwg.org/multipage/parsing.html#appropriate-place-for-inserting-a-node). This would probably be the place to fix it as well. I would prefer if we do this after these in-flight changes are complete though.

Sounds good, I'll hold off!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants