Skip to content

Link elements should not fetch and process upon idempotent attribute mutations #11400

Open
@domfarolino

Description

@domfarolino

What is the issue with the HTML Standard?

Links of type "stylesheet" are defined as fetching their resource whenever the href attribute changes (the same goes for a few other attributes as well). Unfortunately "changes" feels ambiguous, although if you were reading as precisely as you could, you'd probably wind up at https://dom.spec.whatwg.org/#handle-attribute-changes with the conclusion that triggering a mutation on an attribute, even if the attribute's value doesn't change, counts as the type of mutation that would re-trigger the link processing model.

This means link.href = link.href should re-process a link resource, which doesn't match what any browser does. While investigating https://crbug.com/41436016 for Chromium, I discovered that a few years ago WebKit implemented a bunch of logic to ensure that idempotent href, rel, media, and type mutations do not re-trigger the link processing model, for all link types.

This almost matches what Chromium has been doing for years, which is not firing the load event multiple times on the same element (mostly though, the resource itself could be requested). It looks like this was to stop infinite recursion when people would switch rel=preload to rel=stylesheet in the link's load event.

I'm updating Chromium to match WebKit's behavior and writings some WPTs, because Gecko also seems to be doing the same thing, and we want to fix the weird Chromium behavior of still requesting the resource, but just suppressing the load event.

To catch up with reality, HTML should probably define some stricter conditions on exactly what attribute mutations trigger the fetch and process steps for all link types.

For more information/history, see https://chromium-review.googlesource.com/c/chromium/src/+/6667508 and WebKit/WebKit@3775c2e#diff-568964e1a0c5f28dee0d18f24483251642f990cdb1381312e684ac1496a506ef.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions