Skip to content

runAfterTransition leaves callbacks pending when removed targets miss completion events #10972

Closed as duplicate

Description

@whatisyourname0

Provide a general summary of the issue here

runAfterTransition can retain a detached transition target and leave already queued callbacks pending when its completion listener does not receive an event. This still reproduces on main at 360e35170568dfc99a2baaa78e6b7bdd36458d91.

This is a follow-up to #7973 / #8004. The multiple-property cancellation problem in #7326 is already fixed on main by #10730; this report concerns the remaining event-independent cleanup path.

🤔 Expected Behavior?

Removing the last transitioning element should release pending callbacks without requiring another call to runAfterTransition. Removed targets and their cancellation listeners should be cleaned up, while transitions on connected elements should still be awaited.

😯 Current Behavior

Detached targets are only checked inside the animation-frame callback of a subsequent runAfterTransition invocation. If a callback is already queued and its target is removed without the library receiving completion, it stays pending. Even a different, connected transition ending does not drain the queue because the detached target is still in the Map.

The browser reproduction below uses a real CSS transition and an earlier application listener that intercepts transitioncancel with stopImmediatePropagation(). Ordinary removal without interception passes on current main in all three tested engines. This report does not claim that those browsers normally omit cancellation events.

StackBlitz Reproduction

Open the runnable reproduction in StackBlitz

Source and detailed instructions

  1. Wait for the preview, then click Run reproduction. The target becomes Removed, the cancellation event Intercepted, the first callback stays Pending, and the result becomes Stuck.
  2. Optionally click Probe again: the follow-up callback completes, but the first callback stays pending. The later sweep removes the detached target without draining previously queued callbacks on this baseline.
  3. Click Reset, then Run control: ordinary cancellation is received and the first callback completes.

The demo bundles the unmodified utility and required helpers from the exact upstream main commit below. It does not substitute an older npm package or synthesize transition events. Source provenance and license are included in the reproduction repository.

🖥️ Steps to Reproduce

Run this in an otherwise idle browser page with the utility imported from this checkout:

import {runAfterTransition} from './packages/react-aria/src/utils/runAfterTransition';

const element = document.createElement('div');
element.style.cssText = 'opacity: 1; transition: opacity 10s linear';
document.body.appendChild(element);

// Register before React Aria attaches its own per-target listener.
element.addEventListener('transitioncancel', event => {
  event.stopImmediatePropagation();
});

getComputedStyle(element).opacity;
const started = new Promise<void>(resolve => {
  element.addEventListener('transitionrun', () => resolve(), {once: true});
});
element.style.opacity = '0';
await started;

let called = false;
runAfterTransition(() => { called = true; });
await new Promise(requestAnimationFrame);
element.remove();

// After subsequent frames, called remains false on main.
// Calling runAfterTransition again triggers the existing detached-target sweep.

Browser regression: the ordinary-removal control passes and the intercepted-cancellation case fails in Chromium, Firefox, and WebKit. Jest regressions also reproduce a removed subtree, mixed connected/detached targets, and repeated removals without completion events.

💁 Possible Solution

Observe child removals only while the transition registry is nonempty, sweep disconnected targets and remove their listeners, then drain callbacks when the registry becomes empty. Disconnect the observer when idle. Keep the existing frame-time sweep as a fallback. The proposed fix and regression tests are in #10973; the observer lifetime and document-subtree observation cost are review considerations.

🔦 Context

This was investigated while addressing detached DOM retention in a long-running application. A downstream patch motivated checking current main separately. The remaining issue is that global transition bookkeeping relies on receiving every completion event, including events from application-owned elements.

Version

react-aria source on main: 360e35170568dfc99a2baaa78e6b7bdd36458d91.
The once-listener fix from #10730 is included in this baseline.

What browsers are you seeing the problem on?

Chromium 143.0.7499.4, Firefox 144.0.2, WebKit 26.0, using the repository's Vitest browser runner.

What operating system are you using?

macOS (Apple silicon)

🧢 Your Company/Team

Not specified

🕷 Tracking Issue

Related: #7973, #8004, #7326, #10730

Activity

  1. snowystinger commented on Nov 16, 2026

    @snowystinger
    Member

    I appreciate the PR and minimal test, but how does this actually happen in real life? How did you come across this issue?

  2. whatisyourname0 commented on Nov 16, 2026

    @whatisyourname0
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions