Proposal: restrict matches to not span containment elements · Issue #89 · WICG/scroll-to-text-fragment (original) (raw)
As currently specified, it appears a text fragment identifier can match elements across a very wide swath of DOM, including the entire document, in one match. WICG/display-locking#125 on the display locking repo gives a real-world example where the match is very broad.
That issue also describes why this is a problem for semantics and usability of the beforematch
event. It may also be a usability issue of scroll to text fragment, because the scroll will not show the entire match.
I propose that text fragment identifiers not be allowed to cross elements with contain: style layout
. This specific restriction is chosen to match semantics of subtree-visibility, and resolve WICG/display-locking#125. Additional restrictions for other types of layout may be appropriate as well.
/cc @bokand @nickburris
--
One potential concern was raised by @vmpstr when discussing this proposal offline, which is that a site could "opt out" of scroll to text fragment by putting every word in a contain: style layout
div. However, I don't think this is a significant problem because (a) I don't think it's a problem to worry about if sites go out of their way to avoid text fragments via extreme hacks, and (b) the site will have poor performance and layout behavior if they attempt it.