Skip to content

Conversation

@foolip
Copy link
Member

@foolip foolip commented Oct 22, 2025

Fixes #11542.

  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs:
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

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


/dom.html ( diff )
/indices.html ( diff )
/parsing.html ( diff )
/scripting.html ( diff )

@foolip foolip changed the title Add <template contentmethod declarative out-of-order streaming Add <template contentmethod> for declarative out-of-order streaming Oct 22, 2025
@foolip foolip marked this pull request as draft October 22, 2025 15:05
source Outdated

<li><p>Depending on the contentmethod state, remove existing nodes and update the insertion point.</p></li>

<li><p>Question: do we adjust the insertion point simply by setting <var>adjusted insertion location</var>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit more involved because we need to adjust the location based on the grandparent's contentmethod and the parent's contentname.

source Outdated
<li><p>TODO: what to we need to do so that elements are inserted into the template element
and redirected by our pre-insertion steps? We need to undo whatever it is that causes nodes
to be inserted into the DocumentFragment normally.</p></li>
</ol>
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's the "adjusted insertion location" or whatever it's called

@foolip
Copy link
Member Author

foolip commented Nov 6, 2025

I've made some additional changes but things don't quite make sense yet. The direction I'm heading in is:

  • When the parser encounters an <template contentmethod> element, it doesn't insert it.
  • In insert an element at the adjusted insertion location, if we're about to insert an element with a contentname attribute into such a <template> element:
    • Find the target element among the descendents of the element that the <template> element was in. That target is kept as a bookkeeping slot, the tree traversal only happens once.
    • For contentmethod=replace, remove the target and actually insert. (For the following cases, the element isn't inserted.)
    • For contentmethod=replace-children, remove the children.
    • For contentmethod=prepend, save the current first element of the target.
    • For contentmethod=append, there's nothing to do here.
  • In appropriate place for inserting a node further adjust the location based on contentmethod after the existing foster parenting adjustments. (This happens before the above step, but isn't relevant in that case.)
  • In insert an element at the adjusted insertion location, if we're about to insert into an element with a contentname attribute and the bookkeeping all checks out:
    • For contentmethod=replace-children and contentmethod=append, just append.
    • For contentmethod=prepend, use the saved first element of the target.

There are options for where to store the bookkeeping. I initially put it on the <template> element but now think it might be easier to follow if the bookkeeping goes on the element with the contentname attribute. An implementation might keep it as extra information in the stack of open elements.

@noamr
Copy link
Collaborator

noamr commented Nov 6, 2025

I've made some additional changes but things don't quite make sense yet. The direction I'm heading in is:

  • When the parser encounters an <template contentmethod> element, it doesn't insert it.

contentmethod also needs to be valid

  • In insert an element at the adjusted insertion location, if we're about to insert an element with a contentname attribute into such a <template> element:

    • Find the target element among the descendents of the element that the <template> element was in. That target is kept as a bookkeeping slot, the tree traversal only happens once.
    • For contentmethod=replace, remove the target and actually insert. (For the following cases, the element isn't inserted.)
    • For contentmethod=replace-children, remove the children.
    • For contentmethod=prepend, save the current first element of the target.
    • For contentmethod=append, there's nothing to do here.
  • In appropriate place for inserting a node further adjust the location based on contentmethod after the existing foster parenting adjustments. (This happens before the above step, but isn't relevant in that case.)

  • In insert an element at the adjusted insertion location, if we're about to insert into an element with a contentname attribute and the bookkeeping all checks out:

    • For contentmethod=replace-children and contentmethod=append, just append.
    • For contentmethod=prepend, use the saved first element of the target.

It also needs to fail if that first element is no longer a child of the target.

There are options for where to store the bookkeeping. I initially put it on the <template> element but now think it might be easier to follow if the bookkeeping goes on the element with the contentname attribute. An implementation might keep it as extra information in the stack of open elements.

Yea makes sense, that way you don't have to deal with grandparents.

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

Development

Successfully merging this pull request may close these issues.

Out of order HTML streaming ("patching")

4 participants