Skip to content

Add support for Element-scoped View Transitions - #7

Merged
bramus merged 9 commits into
mainfrom
element-scoped
Nov 26, 2026
Merged

bramus merged 9 commits into
mainfrom
element-scoped

Conversation

@bramus

@bramus bramus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator
  • Add support for Element-scoped View Transitions
  • Rework the demo
  • Fix callback-vs-promise timing mismatches
  • Fix failing tests using Firefox on macOS

The failure:

```
1) [firefox-latest] › tests/promisesorder.pw.test.ts:330:3 › Promises Order › It should order callbacks and promises accurately on triple startViewTransition

    Error: expect(received).toEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 1

    @@ -1,12 +1,12 @@
      Array [
        "ready1Catch",
        "ready2Catch",
        "callback1",
    +   "callback2",
        "updateCallbackDone1",
        "finished1",
    -   "callback2",
        "updateCallbackDone2",
        "finished2",
        "callback3",
        "updateCallbackDone3",
        "ready3",

      384 |         startTripleVTAndReturnLoggedMessages,
      385 |       );
    > 386 |       expect(nativeResult).toEqual(expectedResult);
          |                            ^
      387 |     }
      388 |
      389 |     // Force register the mock
        at /Users/bramus/repos/google/view-transitions-mock/tests/promisesorder.pw.test.ts:386:28

  1 failed
    [firefox-latest] › tests/promisesorder.pw.test.ts:330:3 › Promises Order › It should order callbacks and promises accurately on triple startViewTransition
```

The analysis:

```
This is actually an **engine/spec divergence in native `startViewTransition()`**, and **Firefox is following the literal spec**.

### Why Firefox differs from Chromium (and WebKit 26.0)

When three transitions (`vt1`, `vt2`, `vt3`) are started synchronously, both `vt1` and `vt2` are skipped before their update callbacks run. Only the **native** assertion (`nativeResult`) failed — the mock itself passes on all browsers.

- **Firefox (and WebKit `main` ≥ `323173@main` / STP 255):** Implements the spec’s [`#flush-the-update-callback-queue`](https://drafts.csswg.org/css-view-transitions-1/#flush-the-update-callback-queue) (`Document::FlushViewTransitionUpdateCallbackQueue` in Gecko, `ViewTransition::flushUpdateCallbackQueue` in WebKit), which iterates `[vt1, vt2]` in a **single task**:
  1. `callTheUpdateCallback(vt1)` invokes `callback1` (step 5). WebIDL’s *"clean up after running script"* runs a microtask checkpoint as `callback1` returns — **before** step 8 (*"React to `callbackPromise`"*).
  2. Step 8 then queues `vt1`’s `fulfillSteps` microtask (`updateCallbackDone1` / `finished1`), with **no** microtask checkpoint before the loop advances to `vt2`.
  3. `callTheUpdateCallback(vt2)` invokes `callback2`; when `callback2` returns, its WebIDL exit microtask checkpoint drains `vt1`’s queued reaction (`updateCallbackDone1`, `finished1`), and `vt2`’s reaction drains after the loop ends.
  - Result: `callback1 → callback2 → updateCallbackDone1 → finished1 → updateCallbackDone2 → finished2`.
- **Chromium (and Playwright 1.58’s WebKit 26.0):** Blink’s `DOMViewTransition::DidSkipTransition` posts a **separate task** (`PostTask`) per skipped transition instead of batch-flushing a shared queue, so a full microtask checkpoint runs between `vt1` and `vt2`.
  - Result: `callback1 → updateCallbackDone1 → finished1 → callback2 → updateCallbackDone2 → finished2`.
- *(On double `startViewTransition`, only `vt1` is in the queue, so all engines agree.)*

### Fix Applied

Updated the triple `startViewTransition` test in [`tests/promisesorder.pw.test.ts`](file:///Users/bramus/repos/google/view-transitions-mock/tests/promisesorder.pw.test.ts#L366-L423):
- Kept the **mock** assertion strict (`expect(mockedResult).toEqual(expectedResult)`), matching Chromium and [`drainUpdateCallbackQueue`](file:///Users/bramus/repos/google/view-transitions-mock/src/same-document.ts#L514-L535).
- Updated the **native** assertion to accept either exact engine ordering (`expectedResult` for per-task engines like Chromium/WebKit 26.0, or `expectedBatchFlushResult` for spec batch-flush engines like Firefox and WebKit ≥ `323173@main`).
```
 zizmor --fix=all --gh-token=$(gh auth token) .github/workflows
@bramus
bramus merged commit e2eee56 into main Nov 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant