whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.03k stars 2.62k forks source link

Should `:target` match after elements are removed and reattached to the document? #10029

Open josepharhar opened 8 months ago

josepharhar commented 8 months ago

What is the issue with the HTML Standard?

https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-element

When navigating to a fragment, we set a target element which is used to match against :target in CSS. There is no algorithms which set the target element back to null when it is removed, but blink and webkit have been doing this since 2008: https://github.com/WebKit/WebKit/commit/163f46186e9a965a9c2b60356576c3cc2ab3f2de

The compat difference with firefox was raised here where someone asked for :target to continue to match after reattaching: https://bugs.chromium.org/p/chromium/issues/detail?id=1252507

I tried reverting the 2008 change in blink and the crash test did not reproduce, so it seems safe to do so. If webkit is also willing to implement this, then we will have interop with no spec changes needed. Would webkit be willing to implement this? @cdumez @rniwa @nt1m

nt1m commented 8 months ago

I tried reverting the 2008 change in blink and the crash test did not reproduce, so it seems safe to do so.

Seems reasonable to do if safe. I think it would make sense for it to continue to match.

If webkit is also willing to implement this, then we will have interop with no spec changes needed.

We might still want some spec logic for the case where an element with the ID of the URL fragment is appended if we want that to work, but maybe that case doesn't matter too much.

josepharhar commented 8 months ago

Thanks, I'm going to try shipping the change in chrome then. Here is a WPT: https://github.com/web-platform-tests/wpt/pull/43817

domenic commented 8 months ago

Somewhat related (but not blocking): https://github.com/w3c/csswg-drafts/issues/6942