Fix TypeError when a component is disposed mid-transition - #42858
Open
MizouziE wants to merge 2 commits into
Open
Fix TypeError when a component is disposed mid-transition#42858MizouziE wants to merge 2 commits into
MizouziE wants to merge 2 commits into
Conversation
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.
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 tothis._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._elementis already nulled bydispose(), so it doubles as the disposed flag and no new state, andexecuteAfterTransition's signature is untouched. Nothing leaks by skipping the callback: Modal and Offcanvas already dispose their backdrop and focustrap explicitly in their owndispose().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 beforedispose().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
Checklist
npm run lint)Live previews
Related issues
Closes #37474 (if reopened, I have added a comment/request there)
Related: #39743