Skip to content

Stream HTML into element or ShadowRoot - #12758

Open
noamr wants to merge 5 commits into
noamr/streaming-sanitizerfrom
noamr/stream-html
Open

Stream HTML into element or ShadowRoot#12758
noamr wants to merge 5 commits into
noamr/streaming-sanitizerfrom
noamr/stream-html

Conversation

@noamr

@noamr noamr commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Add streaming HTML insertion methods to Element, ShadowRoot, and ChildNode

Introduce safe and unsafe streaming HTML parsing and insertion methods:

  • Element & ShadowRoot: streamHTML(), streamHTMLUnsafe(), streamAppendHTML(), streamAppendHTMLUnsafe(), streamPrependHTML(), and streamPrependHTMLUnsafe()
  • ChildNode: streamBeforeHTML(), streamBeforeHTMLUnsafe(), streamAfterHTML(), streamAfterHTMLUnsafe(), streamReplaceWithHTML(), and streamReplaceWithHTMLUnsafe()
    This allows developers to parse and stream HTML directly into specific positions of the DOM tree using WritableStream.

The HTML fragment parser is divided into two:

  • Preparing the fragment parser (create an inert document with a proper element stack)
  • Using that parser to parse into a DocumentFragment

The preparation algorithm is used when streaming, by creating a new fragment parser, and then the stream is routed to feed that parser.

When parsing, the "insertion target redirection map" is configured to reroute insertions intended for the root to go directly into the stream's target element, instead of going into the DocumentFragment.

A special sanitizer mitigation is in place to avoid these removed elements from incurring side effects, by creating them in an inert document if they are about to be removed.

Closes #2142

(https://github.com/whatwg/meta/blob/main/COMMITTING.md) to use.

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


/dynamic-markup-insertion.html ( diff )
/infrastructure.html ( diff )
/interactive-elements.html ( diff )
/parsing.html ( diff )
/references.html ( diff )
/system-state.html ( diff )

@noamr noamr changed the title Add streaming HTML insertion methods Streaming HTML insertion methods Aug 5, 2026
@noamr noamr changed the title Streaming HTML insertion methods Stream HTML into element or ShadowRoot Aug 5, 2026
@noamr
noamr force-pushed the noamr/stream-html branch from df24ea2 to e416732 Compare August 5, 2026 09:32
@noamr noamr closed this Aug 5, 2026
@noamr noamr reopened this Aug 5, 2026
@noamr
noamr force-pushed the noamr/stream-html branch from e416732 to 5106e9d Compare August 6, 2026 16:23
@noamr
noamr force-pushed the noamr/stream-html branch from deb55bb to e97c374 Compare August 6, 2026 19:46
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.

A way to stream content into an element

1 participant