Re: [whatwg/dom] Collapse range before mutations in deleteContents and extract (PR #1452)

stevenobiajulu left a comment (whatwg/dom#1452)

I ran the empirical test. @annevk you're right — all three browsers already implement the corrected behavior.

**Test structure**

```
container > [p#before(0), trigger(1), p#inside(2), p#sentinel(3)]
Range: (container, 1) → (container, 3)
```

The mutation callback removes `p#before` (at index 0, before the range's start boundary) while the operation is executing. Under the old spec, `collapse(container, 1)` would be applied after this removal, overwriting the live-range adjustment with a stale offset. Under the new spec the range collapses first, so the live-range machinery tracks the removal and produces `startOffset: 0`. The observable difference is `startOffset: 0` (new spec) vs `startOffset: 1` (old spec).

**Results — Chrome 133, Firefox 135, Safari 18**

| Track | Trigger mechanism | Operation | `startOffset` | Verdict |
|---|---|---|---|---|
| A | `disconnectedCallback` (custom element) | `deleteContents` | 0 (all three) | ✅ new-spec behavior |
| A | `disconnectedCallback` (custom element) | `extractContents` | 0 (all three) | ✅ new-spec behavior |
| B | `pagehide`/`unload` in iframe `srcdoc` | `deleteContents` | 0 (all three) | ✅ new-spec behavior |
| B | `pagehide`/`unload` in iframe `srcdoc` | `extractContents` | 0 (all three) | ✅ new-spec behavior |

Track A: `disconnectedCallback` fired synchronously mid-operation in all three browsers (not deferred past the `[CEReactions]` boundary on `deleteContents()` as I'd initially worried — reactions flush when each internal `remove()` completes).

Track B: `pagehide` and `unload` both fired synchronously in all three browsers including Firefox, which surprised me given the HTML spec's "without any unload events firing" language and Bugzilla #1850228. That bug may describe a different scenario.

Screenshots attached. 
**Chrome**:
<img width="810" height="1306" alt="Screenshot 2026-03-06 at 11 25 28 AM" src="https://github.com/user-attachments/assets/94f3f11b-1b1c-4681-a680-8d8cd9f23a88" />

**Safari**:
<img width="847" height="1207" alt="Screenshot 2026-03-06 at 11 27 11 AM" src="https://github.com/user-attachments/assets/e6ea7b86-944c-45e2-a4b5-d7c39d06dad1" />

**Firefox**:
<img width="1280" height="1348" alt="Screenshot 2026-03-06 at 12 00 38 PM" src="https://github.com/user-attachments/assets/f0b6abe1-e840-4137-a306-df12077df044" />

**What this means for the open items**

- The spec change is a correctness clarification, not a fix for a bug in shipping browsers. I'll update the filed browser bugs to note that.
- On the WPT tests in #58008: given that there's nothing for browsers to fix, I'm happy to close that PR. Alternatively the static collapse-position tests could stay as regression guards for the spec ordering itself — up to you.


-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1452#issuecomment-4012955171
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1452/c4012955171@github.com>

Received on Friday, 6 March 2026 17:12:12 UTC