Re: [csswg-drafts] [css-highlight-api] Specifying behavior for Highlights involving multiple documents (#6417)

Right after discussing this I realized there's a problem with the "throw on mismatch" approach that we didn't catch during the meeting. The issue is that a Range can be moved to another Document _after_ it has been added to a `Highlight` and _after_ the `Highlight` has been added to the `HighlightRegistry`.

```js
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
let r1 = new Range();
r1.setStart(document.body, 0);
r1.setStart(document.body, 1);
let h1 = new Highlight(r1); // doesn't throw; r1 is in the creator document of the Highlight.
CSS.highlights.set("foo", h1); // doesn't throw; Highlight's creator document is the same as the HighlightRegistry's.
r1.setStart(iframe.contentDocument.body, 0); // r1 is now in a different document! But it's too late for highlight APIs to throw.
r1.setEnd(iframe.contentDocument.body, 0);
```

The above breaks the proposed invariant that a `HighlightRegistry`'s `Highlight`s only have Ranges from the document associated with the `HighlightRegistry`. But, there was no point at which we could have thrown, unless every time we move a `Range` we do a check for each `Highlight` that it is a member of.

I can't think of a solution for this, so I think we should revisit the original solution discussed during today's meeting:
> 1. A Highlight can contain Ranges from multiple document trees.
> 2. A Highlight can be added to multiple HighlightRegistries.
> 3. When a HighlightRegistry is painting one of its Highlights, it must only paint the Ranges in the document tree associated
   with that HighlightRegistry.

Or maybe there's a way to work around this problem that I'm not seeing. cc @smfr @emilio @tabatkins @sanketj 


-- 
GitHub Notification of comment by dandclark
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6417#issuecomment-884332586 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 21 July 2021 16:41:39 UTC