fix(QTooltip): guard MutationObserver against detached innerRef#18316
Open
mathsgod wants to merge 1 commit into
Open
fix(QTooltip): guard MutationObserver against detached innerRef#18316mathsgod wants to merge 1 commit into
mathsgod wants to merge 1 commit into
Conversation
When the component unmounts before the next-tick callback in `handleShow` runs (e.g. fast route change while hovering an anchor that triggers tooltip show), `innerRef.value` is `null` and `observer.observe(null)` throws: TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'. Add a null check and wrap the observe call in a try/catch so that a detached ref during navigation silently aborts positioning instead of throwing an uncaught error.
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.
What & Why
QTooltip.handleShowregisters aMutationObserverinside anextTickcallback. If the component unmounts before that microtask runs (e.g. fast route change while hovering an anchor that triggers a tooltip show),innerRef.valueisnulland the call throws:The thrown error is unhandled and surfaces in the console. It is most visible in apps that pair
QTooltipwith quick navigation (table action buttons, tabs, dialogs).Reproduction
<q-tooltip>.MutationObserverTypeError.Fix
Add a null check and wrap
observer.observe(...)in a try/catch. If the ref is detached when the tick fires, silently abort positioning instead of throwing. The component is on its way out anyway.registerTick(() => { observer = new MutationObserver(() => updatePosition()) - observer.observe(innerRef.value, { - attributes: false, - childList: true, - characterData: true, - subtree: true - }) + if (innerRef.value === null) { + observer = void 0 + return + } + try { + observer.observe(innerRef.value, { + attributes: false, + childList: true, + characterData: true, + subtree: true + }) + } catch (_e) { + observer = void 0 + } updatePosition() configureScrollTarget() })Notes
useTickcomposable already callsremoveTickononBeforeUnmount, so the pending tick is cancelled when possible. The null guard covers the remaining race where the tick fires afterinnerRefis detached but the VM is not yet considered destroyed (e.g.<keep-alive>deactivation, sibling unmount).