Skip to content

Attribute change steps should run after setting the value, not before #1190

@emilio

Description

@emilio

https://dom.spec.whatwg.org/#concept-element-attributes-change first runs the change steps, then sets the value.

That means that if the steps trigger something that then changes the relevant attribute, per spec we should keep the "old" value, which seems wrong.

Example:

<!doctype html>
<div popover="manual">wat</div>
<button>Hide</button>
<script>
let div = document.querySelector("div");
div.addEventListener("beforetoggle", function(e) {
  if (e.newState == "closed") {
    this.setAttribute("popover", "manual");
  }
})
document.querySelector("button").addEventListener("click", function(e) {
  div.removeAttribute("popover");
});
div.showPopover();
</script>

Per spec, after clicking the value the popover attribute should not be there, which is wrong and doesn't match implementations.

My guess is that modulo that case this is generally not very observable, because other attribute change steps are usually async.

It feels very weird tho that removeAttribute runs script synchronously for popover btw...

cc @mbrodesser-igalia, @mfreed7, @domenic, @annevk, @smaug----

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions