Skip to content

Fix TypeError when a component is disposed mid-transition - #42858

Open
MizouziE wants to merge 2 commits into
twbs:mainfrom
MizouziE:fix/tooltip-dispose
Open

Fix TypeError when a component is disposed mid-transition#42858
MizouziE wants to merge 2 commits into
twbs:mainfrom
MizouziE:fix/tooltip-dispose

Conversation

@MizouziE

@MizouziE MizouziE commented Aug 21, 2026

Copy link
Copy Markdown

Description

Skip a component's queued transition-completion callback if the instance was disposed before the transition finished.

dispose() nulls every property on the instance but cannot cancel a callback already queued via executeAfterTransition as that helper registers a transitionend listener plus a setTimeout fallback, and neither can be cancelled. The callback then runs against a gutted instance and throws.

This deliberately does not null-guard Tooltip._isWithActiveTrigger(), the fix proposed in #37474. As noted there, that is only a defensive patch, and it just relocates the crash two lines down to this._element.removeAttribute('aria-describedby'). Better the queued callback not run at all.

Since every component routes transition completion through BaseComponent._queueCallback, guarding that single method fixes it for all of them at once. _element is already nulled by dispose(), so it doubles as the disposed flag and no new state, and executeAfterTransition's signature is untouched. Nothing leaks by skipping the callback: Modal and Offcanvas already dispose their backdrop and focustrap explicitly in their own dispose().

Motivation & Context

Fixes the long-standing Uncaught TypeError: Cannot convert undefined or null to object from Tooltip._isWithActiveTrigger() when a component is disposed mid-transition. Reported repeatedly since 2022 and typically worked around with a setTimeout before dispose().

dispose() is public API with no documented restriction against calling it during a transition, and the common trigger is not misuse: a MutationObserver disposing a tooltip whose trigger element was just removed from the DOM has no way to know a fade is still in flight.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Live previews

Related issues

Closes #37474 (if reopened, I have added a comment/request there)
Related: #39743

@MizouziE
MizouziE requested a review from a team as a code owner August 21, 2026 15:17
@MizouziE MizouziE changed the title Fix/tooltip dispose Fix TypeError when a component is disposed mid-transition Aug 21, 2026
@mdo mdo added this to v5.4.0 Aug 21, 2026
@github-project-automation github-project-automation Bot moved this to Needs review in v5.4.0 Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

function _isWithActiveTrigger in tooltip.js is causing an uncaught error

2 participants