Skip to content

LibWeb: Parse HTML fragments directly into DocumentFragment#10567

Merged
shannonbooth merged 4 commits into
LadybirdBrowser:masterfrom
shannonbooth:fragment-parser-confusion
Jul 10, 2026
Merged

LibWeb: Parse HTML fragments directly into DocumentFragment#10567
shannonbooth merged 4 commits into
LadybirdBrowser:masterfrom
shannonbooth:fragment-parser-confusion

Conversation

@shannonbooth

Copy link
Copy Markdown
Member

Refactor the HTML fragment parser to insert the root's children straight
into a DocumentFragment instead of a connected temporary document. On
top of being a correctness fix, this should also improve performance of
fragment parsing.

Making this change has other fallout due to the timing of document
adoption changing. This results in related other changes needing to be
made, including:

  • The parser having "allow declarative shadow roots" as a parser flag
    so that it does not read the flag from the wrong document. This
    prevents some regressions which would happen otherwise, but also
    aligns our behaviour in general where in some cases the wrong setting
    was previously being chosen.
  • Custom element registry is now taken from the target node instead
    of the context node. This also prevents regressions as part of the
    fallout of these changes, but also fixes the selection of the custom
    element registry for ShadowRoots (which was previously being taken
    from the root document).
  • Use a null custom element registry for template.innerHTML. Similar to
    both cases above, this prevents regressions from the above changes
    due to the change in timing of document adoption, but fixing this
    also aligns behaviour closer what other engines implement.

See: whatwg/html#12624 for background.

@shannonbooth
shannonbooth force-pushed the fragment-parser-confusion branch 2 times, most recently from 0d19e99 to 81ccdc0 Compare July 9, 2026 19:54
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Jul 10, 2026
@shannonbooth
shannonbooth force-pushed the fragment-parser-confusion branch from 81ccdc0 to fc23bfb Compare July 10, 2026 18:44
@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Jul 10, 2026
@shannonbooth

Copy link
Copy Markdown
Member Author

fixed da conflicts

@shannonbooth
shannonbooth force-pushed the fragment-parser-confusion branch from fc23bfb to 880c24c Compare July 10, 2026 19:08
Refactor the HTML fragment parser to insert the root's children straight
into a DocumentFragment instead of a connected temporary document. On
top of being a correctness fix, this should also improve performance of
fragment parsing.

Making this change has other fallout due to the timing of document
adoption changing. This results in related other changes needing to be
made, including:

 * The parser having "allow declarative shadow roots" as a parser flag
   so that it does not read the flag from the wrong document. This
   prevents some regressions which would happen otherwise, but also
   aligns our behaviour in general where in some cases the wrong setting
   was previously being chosen.
 * Custom element registry is now taken from the *target* node instead
   of the *context* node. This also prevents regressions as part of the
   fallout of these changes, but also fixes the selection of the custom
   element registry for ShadowRoots (which was previously being taken
   from the root document).
 * Use a null custom element registry for template.innerHTML. Similar to
   both cases above, this prevents regressions from the above changes
   due to the change in timing of document adoption, but fixing this
   also aligns behaviour closer what other engines implement.

Ref: whatwg/html#12624
@shannonbooth
shannonbooth force-pushed the fragment-parser-confusion branch from 880c24c to c61632e Compare July 10, 2026 19:13
@shannonbooth
shannonbooth merged commit 350d20b into LadybirdBrowser:master Jul 10, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant