Skip to content

fix: handle router view transition rejections - #543

Merged
Mohamed Mansour (mohamedmansour) merged 3 commits into
mainfrom
mohamedmansour-router-transition-rejection
Sep 17, 2026
Merged

Mohamed Mansour (mohamedmansour) merged 3 commits into
mainfrom
mohamedmansour-router-transition-rejection

Conversation

@mohamedmansour

Copy link
Copy Markdown
Contributor

Why

A router-owned view transition can reject its animation ready promise even after the route DOM commit succeeds. Leaving that rejection unobserved produces an unhandled browser error for superseded or invalidated transitions.

Approach

Attach one shared rejection handler to transition.ready immediately after starting the transition. Keep updateCallbackDone as the only readiness barrier, preserving genuine commit errors and allowing rapid navigation without waiting for animations. The browser already marks finished handled; it only rejects alongside a failed commit callback.

Reuse the existing router unit tests and browser fixture, with no new dependencies, fixtures, configuration, global rejection suppression, or delayed resize. Update the specification and public routing contract. Measured bundle growth is 50 minified bytes (21 gzip bytes).

Validation

  • Native Chromium 153 supersession and invalid snapshot state regressions fail before the fix with unhandled ready rejections (AbortError and InvalidStateError) and pass afterward.
  • Router unit tests: 116 passed, including commit barrier timing and exact-identity callback error propagation.
  • Router Playwright suite: 36 passed, 4 pre-existing skips. Transition regressions repeated 10 times: 30 passed.
  • Strict E2E type-check passed.
  • cargo xtask check: passed, including docs, in 149.5 seconds.

Reproduction limitation: Actual viewport resize immediately after route notification passes without page errors, but resize alone did not reproduce the reported abort in this small fixture/browser before the fix. Deterministic native supersession and invalid snapshot capture establish the rejecting promise and regression instead.

Observe animation readiness rejection without changing the route commit barrier. Cover native supersession, invalid snapshot state, immediate resize, and callback error propagation in the existing tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@mddinbox

Copy link
Copy Markdown
Contributor

Thanks for the fix and the error-identity coverage! One non-blocking browser-compatibility follow-up: on Edge 153.0.4234.46 / Windows, a throwing route-component $destroy() still produces an unhandled rejection from transition.finished, even though the router catches and logs the original commit error. This reproduced through public router startup/navigation with real HTTP partial responses in 5/5 runs. It also occurs on the base branch, so this is not a regression introduced by this PR, and the successful-commit animation-skip fix remains valid.

Please consider observing both promises without awaiting them, keeping updateCallbackDone as the only awaited promise:

void transition.ready.catch(ignoreTransitionRejection);
void transition.finished.catch(ignoreTransitionRejection);
await transition.updateCallbackDone;

Here, ignoreTransitionRejection would be the renamed existing helper. Adding the finished observer removed the extra rejection in 5/5 runs while preserving the original router error log.

If included, please update the tests alongside the production change:

  • Leave finished unhandled in the mock, using const finished = updateCallbackDone.then(() => {});, so the test verifies that the router itself observes the rejection.
  • Narrow the source-inspection assertion to !source.includes('await transition.finished') rather than rejecting every transition.finished reference. Retain the behavioral test with pending ready/finished promises to ensure navigation does not wait for animation completion.

The combined runtime/mock/assertion adjustments passed all 86 tests in router.test.ts in an in-memory validation. A native-browser callback-failure test would additionally protect against specification-versus-browser differences, and the documentation’s automatic-handling assumption should be qualified.

A separate compatibility follow-up would also be reasonable given this PR’s scope.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohamedmansour

Copy link
Copy Markdown
Contributor Author

mddinbox Accepted in 30c8b6f9: both ready and finished are observed with the shared helper, while only updateCallbackDone is awaited to preserve the original commit error. I updated the mocks, assertion, and docs, retained pending-promise coverage, and added a native $destroy() regression that failed before the fix and passed 5/5 afterward; 116 unit tests, 38 browser tests (4 existing skips), strict typechecking, and the full quality gate passed.

@mohamedmansour
Mohamed Mansour (mohamedmansour) merged commit ef2d562 into main Sep 17, 2026
35 checks passed
@mohamedmansour
Mohamed Mansour (mohamedmansour) deleted the mohamedmansour-router-transition-rejection branch September 17, 2026 23:52
Mohamed Mansour (mohamedmansour) added a commit that referenced this pull request Sep 18, 2026
## Release

Bumps WebUI to `0.0.29`.

Previous release tag: `v0.0.28`

## Changes since `v0.0.28`

Features:

- Ship version-matched AI authoring guidance with `@microsoft/webui`,
using a lightweight skill that reads the installed package's reference
(feat: bundle versioned AI guidance with WebUI #522 by @mohamedmansour).
- Add plugin-aware component discovery, with filename-based HTML
components and manifest-driven FAST components (feat: add plugin-aware
component discovery #524 by @mohamedmansour).
- Add WebUI Press `--show=all|content` for shell-free documentation
views that preserve SSR, hydration, authored examples, and accessible
theme behavior (feat: add WebUI Press content mode #525 by
@mohamedmansour).
- Automatically support Trusted Types for compiled templates and
generated CSS import maps without promoting arbitrary state HTML to
trusted content (feat: use Trusted Types automatically in the framework
#536 by @mohamedmansour).
- Keep explicit streaming imports lightweight so applications can load
streaming support early and application code later (feat: keep explicit
streaming imports lightweight #539 by @mohamedmansour).
- Render tree-shaped state with file-scoped named `<for id="...">`
bodies, including forward references and recursive reuse without extra
client runtime code. Use unbraced `each="item in items"`; the legacy
`template` spelling and FAST component references produce actionable
diagnostics (feat: add file-scoped recursive for loops #547 by
@mohamedmansour).

Fixes:

- Preserve table-rooted hydration ownership and correctly compile
whitespace-bearing, nested directives, preventing duplicate controls
after reactive updates. Rebuild templates to receive the compiler fix
(fix: preserve table-rooted hydration paths #512 by @mohamedmansour;
fix: align client directive parsing with the HTML scanner #531 by
@mohamedmansour).
- Emit reachable stylesheets and templates in deterministic traversal
order. External plugin implementations must adapt the affected
`HandlerPlugin` and bootstrap component collection interfaces from hash
sets to slices (fix: render reachable-component ordering
deterministically #519 by @janechu).
- Resolve bare CEM module specifiers through their owning packages,
respecting export maps, package boundaries, and cache invalidation when
nearer dependencies appear (fix: resolve bare CEM module specifiers #528
by @janechu).
- Prevent spurious dev-server rebuilds from read-only filesystem
activity and recursive traversal of linked workspace dependencies
(Improve benchmark telemetry and dev-server watching #521 by
@mohamedmansour).
- Update rustls to address TLS 1.3 handshake encryption-level validation
advisory RUSTSEC-2026-0285 (fix: update rustls to address
RUSTSEC-2026-0285 #533 by @mohamedmansour).
- Forward bare boolean and ARIA component inputs into SSR state while
preserving empty literal attributes and existing conditional boolean
bindings (fix: forward HTML component inputs during SSR #540 by
@mohamedmansour).
- Preserve sibling route declaration order across SSR and client routing
so equally specific routes select the correct pending and error
boundaries (fix: preserve route order for pending and error boundaries
#541 by @mohamedmansour).
- Handle skipped or superseded router view transitions without unhandled
animation rejections, while preserving route-commit errors and
responsive subsequent navigation (fix: handle router view transition
rejections #543 by @mohamedmansour).
- Wait for active dev-server rebuilds and their bundler subprocesses
before graceful shutdown, preventing output writes after the server
exits (fix: wait for dev-server rebuilds during shutdown #546 by
@mohamedmansour).
- Preserve global theme defaults when custom properties are overridden
only by scoped selectors or conditional rules, so unmatched component
instances retain their intended colors (fix: preserve theme defaults
under scoped CSS overrides #548 by @mohamedmansour).

Docs:

- Add a data-driven Benchmark Explorer, centralize performance guidance,
distinguish independent SSR/browser metrics, and publish resource
telemetry with accessible methodology details (docs: centralize
performance guidance and benchmark data #486 by @mohamedmansour; Improve
benchmark telemetry and dev-server watching #521 by @mohamedmansour).
- Update AI reference installation and migration guidance while
retaining `/ai`, and clarify plugin-specific discovery and FAST
converted-template requirements (feat: bundle versioned AI guidance with
WebUI #522 by @mohamedmansour; feat: add plugin-aware component
discovery #524 by @mohamedmansour).
- Document owned Rust partial rendering, streaming state ownership, and
watcher hashing benchmarks, including measurement scope and tradeoffs
(perf: reduce partial response allocations #510 by @mohamedmansour;
perf: move streaming command processing off async workers #529 by
@mohamedmansour; perf: bound watcher hashing memory with reusable
scratch #530 by @mohamedmansour).
- Document automatic Trusted Types support, CSP enforcement, and
first-declared precedence for equally specific routes and their
pending/error boundaries (feat: use Trusted Types automatically in the
framework #536 by @mohamedmansour; fix: preserve route order for pending
and error boundaries #541 by @mohamedmansour).
- Explain named recursive loops and their compatibility limits, scoped
CSS token defaults, and router view-transition error handling (feat: add
file-scoped recursive for loops #547 by @mohamedmansour; fix: preserve
theme defaults under scoped CSS overrides #548 by @mohamedmansour; fix:
handle router view transition rejections #543 by @mohamedmansour).

Maintenance:

- Reduce partial-response and per-render allocations through owned state
projection, borrowed graph traversal, scalar formatting, and borrowed
nested route trees. Rust callers use ownership-taking
`Protocol::render_partial(Value, ...)`; JSON boundaries retain
`render_partial_json` (perf: reduce partial response allocations #510 by
@mohamedmansour; perf: cut per-render handler allocations #511 by
@mohamedmansour; perf: avoid cloning nested route trees #513 by
@mohamedmansour).
- Move streaming command deserialization, validation, and default
preparation onto the existing blocking renderer, transferring owned
records and state rather than cloning retained projections (perf: move
streaming command processing off async workers #529 by @mohamedmansour).
- Bound watcher hashing content storage to one reusable 8 KiB buffer
instead of repeated file-sized allocations while preserving invalidation
behavior (perf: bound watcher hashing memory with reusable scratch #530
by @mohamedmansour).
- Parallelize release WASM builds and artifact staging, and consolidate
dependency scanning before release jobs (chore: parallelize release
pipeline work #509 by @mohamedmansour).
- Refresh compatible Rust and JavaScript dependencies and migrate
repository tooling and CI to pnpm 12.3.4 while preserving existing audit
constraints (chore: update dependencies to latest compatible versions
#534 by @mohamedmansour).

## Validation

- `cargo xtask check`
- `pnpm --dir crates/webui-press test` (16 passed).
- `pnpm --dir packages/webui-framework exec playwright test
recursive-repeat --workers=2 --reporter=line` (6 passed).
- `pnpm --dir packages/webui-router exec playwright test --grep "view
transition rejection ownership" --workers=2 --reporter=line` (4 passed).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

2 participants