Skip to content

fix: defer animation start for add/replace to microtask - #11434

Merged
web-padawan merged 2 commits into
mainfrom
fix/backdrop-animation-overlay
Apr 2, 2026
Merged

web-padawan merged 2 commits into
mainfrom
fix/backdrop-animation-overlay

Conversation

@web-padawan

@web-padawan web-padawan commented Apr 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Two improvements to master-detail-layout animation orchestration:

Fix: defer animation start for add/replace to microtask

_finishTransition defers recalculateLayout to a microtask (so Lit elements render before measurement). But animation params (overlay detection, offscreen value, backdrop fade) were read synchronously before the microtask ran, producing wrong values — most visibly, the backdrop fade-in never triggered.

Fix: defer animation start to a subsequent microtask so the execution order is:

  1. updateCallback — DOM update + queue recalculate microtask
  2. Lit rendering microtask — element content renders
  3. recalculateLayout microtask — sets overlay, caches intrinsic size
  4. Animation start — reads correct CSS state (including [overlay] attribute)

Refactor: convert _startTransition to async/await

Replace nested closures and manual Promise/__transitionResolve management with a linear async flow. Each await is a yield point guarded by a version counter for interruption safety.

  • _startTransition is now async with clear top-to-bottom flow
  • __runAnimations simplified: returns the slide Promise, no version counter or onFinish callback
  • __endTransition: removed __transitionResolve handling (async function's implicit Promise resolves on return)
  • _finishTransition unchanged (still used by React wrapper)

Test plan

  • yarn test --group master-detail-layout — 98 tests pass
  • yarn lint:js — pass
  • Manual: open detail in overlay mode, verify backdrop fades in
  • Manual: close detail, verify backdrop fades out
  • Manual: open detail with Lit element content, verify correct overlay detection
  • Manual: test interruption (click backdrop during slide-in)

🤖 Generated with Claude Code

@web-padawan
web-padawan requested a review from vursen April 1, 2026 07:33
@web-padawan web-padawan changed the title fix: detect overlay from grid tracks for backdrop fade-in fix: defer animation start for add/replace to microtask Apr 1, 2026
@web-padawan
web-padawan force-pushed the fix/backdrop-animation-overlay branch 3 times, most recently from 3641854 to 0636ac4 Compare April 1, 2026 09:05
For add/replace transitions, _finishTransition defers recalculateLayout
to a microtask so Lit elements can render before measurement. But
animation params (overlay detection, offscreen value) were read
synchronously before the microtask ran, producing wrong values.

Defer animation start to a second microtask so the execution order is:
1. updateCallback (DOM update + queue recalculate microtask)
2. Lit rendering microtask
3. recalculateLayout microtask (sets overlay, caches size)
4. Animation start microtask (reads correct CSS state)

Move the version counter from __animateTransition to _startTransition
so deferred animations can check for staleness on interruption.
Rename __animateTransition to __runAnimations (no longer owns the
Promise or version counter).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@web-padawan
web-padawan force-pushed the fix/backdrop-animation-overlay branch from 0636ac4 to 00decff Compare April 1, 2026 09:52
Replace nested closures and manual Promise management with a linear
async flow. Each await is a yield point guarded by a version counter
for interruption safety.

- _startTransition is now async with clear top-to-bottom flow
- __runAnimations simplified: returns the slide Promise, no version
  counter or onFinish callback management
- __endTransition: remove __transitionResolve (async function's
  implicit Promise resolves on return)
- _finishTransition unchanged (still used by React wrapper)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@web-padawan
web-padawan force-pushed the fix/backdrop-animation-overlay branch from 119e42b to 926684d Compare April 1, 2026 12:04
@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown

@web-padawan
web-padawan merged commit 2aad443 into main Apr 2, 2026
10 checks passed
@web-padawan
web-padawan deleted the fix/backdrop-animation-overlay branch April 2, 2026 07:00
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