[whatwg/dom] Attribute change steps should run after setting the value, not before (Issue #1190)

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:

```html
<!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----

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1190
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1190@github.com>

Received on Monday, 24 April 2023 12:47:14 UTC