Repository navigation
fix(react-aria): release removed transition targets without completion events - #10973
Closed
whatisyourname0 wants to merge 1 commit into
Closed
whatisyourname0 wants to merge 1 commit into
whatisyourname0 wants to merge 1 commit into
Conversation
Member
|
You'll need to sign the CLA |
isihussain
reviewed
Nov 16, 2026
isihussain
left a comment
Contributor
There was a problem hiding this comment.
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:
- Observer Lifecycle & Overhead: Lazily instantiating
removalObserverwhentransitionsByElement.size === 0and disconnecting it once all transitions finish ensures zero idle overhead when animations are inactive. - Memory Leak Prevention: Calling
eventTarget.removeEventListener('transitioncancel', onTransitionEnd)incleanupDetachedElements()releases listener references on disconnected nodes. - 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 todocument. The fallback inrequestAnimationFramemitigates this, but documenting shadow root constraints could be helpful. - Test Quality: Both the browser Vitest test (
runAfterTransition.browser.test.ts) and unit tests inrunAfterTransition.test.tsprovide robust coverage across intercepted events, moved elements, and repetitive removals.
Author
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.
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
runAfterTransitionsweeps 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
transitioncancelevent 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:
yarn test packages/react-aria/test/utils/runAfterTransition.test.ts --runInBandandyarn 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 withyarn formatandgit diff --checkpassed.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
✅ PR Checklist
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.