Skip to content

fix(react-aria): release removed transition targets without completion events - #10973

Closed
whatisyourname0 wants to merge 1 commit into
adobe:mainfrom
whatisyourname0:fix/transition-removal-cleanup
Closed

whatisyourname0 wants to merge 1 commit into
adobe:mainfrom
whatisyourname0:fix/transition-removal-cleanup

Conversation

@whatisyourname0

@whatisyourname0 whatisyourname0 commented Nov 16, 2026 •

Copy link
Copy Markdown

Closes #10972

Summary

When a tracked element is removed after a callback has already been queued, that callback can remain pending if React Aria does not receive a completion event. A later call to runAfterTransition sweeps detached targets, but no later call is guaranteed. A stale target also prevents callbacks from draining when other connected transitions finish.

The intended behavior is to release detached targets and queued work without requiring another interaction, while continuing to wait for connected transitions.

Observe document child removals only while transitions are tracked. Batches with removals trigger the existing disconnected-target sweep, including cancellation-listener cleanup, and drain callbacks when idle. The observer disconnects when the registry empties; the existing frame-time sweep remains as a fallback. This avoids permanent document observation, but the cost of observing document-subtree child mutations during active transitions is a review consideration; no performance benchmark is claimed.

This follows #8004. The multiple-property cancellation fix from #10730 is already on the tested main and is not repeated here. The browser reproduction uses a real CSS transition whose transitioncancel event is intercepted by an earlier application handler. Ordinary removal is a passing control; the tests do not claim that browsers normally omit cancellation events.

Implementation, tests, and this PR description were prepared with OpenAI Codex assistance.

📝 Test Instructions

Baseline: main at 360e35170568dfc99a2baaa78e6b7bdd36458d91, macOS Apple silicon.

Regression verification:

  • Jest: three new regressions fail before the fix (removed subtree, mixed detached/connected targets, repeated removals); all 11 utility tests pass after it. Controls cover reparenting and callback cancellation.
  • Real CSS transitions in Chromium 143.0.7499.4, Firefox 144.0.2, and WebKit 26.0: intercepted-cancellation reproduction fails on original main in all three engines; ordinary removal passes. All six browser cases pass with the fix.
  • Run the regression tests with yarn test packages/react-aria/test/utils/runAfterTransition.test.ts --runInBand and yarn vitest run --config=vitest.browser.config.ts packages/react-aria/test/utils/runAfterTransition.browser.test.ts.

Full validation:

  • yarn test --maxWorkers=4: 382 suites passed, 2 failed; 8,287 tests passed, 4 failed, 16 skipped; 262 snapshots passed. All four failures are DatePicker/DateRangePicker expectations for narrow no-break spaces before AM. Running those two suites with the original main source reproduced the same four failures.
  • yarn test:ssr: all 60 suites / 74 tests passed.
  • yarn test:browser: latest full run: 64 files passed, 1 failed, 16 skipped; 472 tests passed, 2 failed, 63 skipped. The two failures are WebKit Chat scroll-button tests and also fail on original main. The first fixed full run additionally failed the WebKit nested Tabs animation assertion; it passed on a focused recheck and on the second full fixed run. The original-main full browser run also had a WebKit Modal failure that did not occur in either fixed full run. These intermittent results are reported rather than claiming a fully green browser suite.
  • yarn lint: passed (format check, TypeScript, oxlint, package lint, constraints). Changed files were formatted with yarn format and git diff --check passed.

This is an internal utility change. No new public API, user-facing strings, or visual states were added. Separate manual mouse/touch/screen-reader, RTL/theme/zoom, and constrained-device performance testing was not performed.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

The contributor understanding checkbox is left for human review. The assistant read AGENTS.md and the testing, tooling, and PR guidance.

🧢 Your Project

Long-running applications using React Aria.

@yihuiliao

Copy link
Copy Markdown
Member

You'll need to sign the CLA

@isihussain isihussain left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Introducing a lifecycle-managed MutationObserver in runAfterTransition.ts prevents callback starvation when transitioning elements are detached before transitionend or transitioncancel fire.

Architectural Evaluation:

  1. Observer Lifecycle & Overhead: Lazily instantiating removalObserver when transitionsByElement.size === 0 and disconnecting it once all transitions finish ensures zero idle overhead when animations are inactive.
  2. Memory Leak Prevention: Calling eventTarget.removeEventListener('transitioncancel', onTransitionEnd) in cleanupDetachedElements() releases listener references on disconnected nodes.
  3. Shadow DOM Consideration: Because removalObserver.observe(document, ...) attaches to the document root, node removals inside deeply encapsulated shadow roots or separate documents/iframes may not bubble mutation records to document. The fallback in requestAnimationFrame mitigates this, but documenting shadow root constraints could be helpful.
  4. Test Quality: Both the browser Vitest test (runAfterTransition.browser.test.ts) and unit tests in runAfterTransition.test.ts provide robust coverage across intercepted events, moved elements, and repetitive removals.

@whatisyourname0

Copy link
Copy Markdown
Author

Sorry for bothering, but I doubled checked the browser OOM and it comes with using the older version of react-aria (not included version of the fix in #10730). Updating the version including #10730 patch solved this issue.

I'm closing the issue and PR. Thanks for checking again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runAfterTransition leaves callbacks pending when removed targets miss completion events

3 participants