← Back to context

Comment by dfabulich

15 hours ago

The new element syntax is needed to signify DOM ranges that may cross the boundaries of HTML element trees.

  <p>
    <em>Some <?start name="hl"?>text</em>
    to replace<?end name="hl"?>.
  </p>

Jake Archibald at Mozilla has a good video about this. https://www.youtube.com/shorts/yARSOcqOWvY

I am puzzled then: so what would happen if the template will replace this island form your example with markup without closing `</em>`?

  •   <p>
        <em>Some replaced text
      </p>
    

    Which, by the HTML standard, will automatically close the `</em>` as the `</p>` closes.

    • It would be pretty wild if this feature allowed you to go back and add/remove individual tokens from earlier in the document and re-apply all the tree construction rules, like an even more unhinged version of document.write(). I think the actual proposal is expressed in terms of moving DOM nodes around and doesn't allow stuff like this.

      1 reply →

Oh nooooooo are you kidding? That's beyond horrific.

That's really really really awful

  • As far as I can tell, this is not actually allowed by the current proposal. The definition of the "find markers" algorithm in https://github.com/whatwg/html/pull/11818 requires that the <?end> marker be a sibling of the <?start> marker in the DOM, so they can't have different parents like this.

    Well, you're allowed to write it, but the browser will just ignore the <?end> marker. The range will end at the </em> tag, the same place https://github.com/WICG/declarative-partial-updates/blob/mai... says it goes by default if you don't write the <?end> at all. (That default wouldn't make a ton of sense if patch ranges were allowed to break out of their parent elements like this.)

    Jake Archibald thinks it'd be cool to use a similar syntax to do CSS highlights, but there are other problems with that (like not being able to create overlapping ranges), and he's not on the Chrome team that's pushing this proposal.

    • (and this is correct, the start/end marker need to be siblings. You can't input something that starts in one parent and ends in another.)

    • We're working together with Jake on this. I do hope that processing instructions can help with highlights in the future.