Repository navigation
Add support for Element-scoped View Transitions - #7
Merged
Merged
Conversation
bramus
commented
Nov 24, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.