fix(tooltip): destroy tooltip instance on component removal#4382
Merged
Conversation
When `container` is set to `"body"` (or any element other than the
trigger's natural parent), Bootstrap appends the tooltip DOM node
directly to that container element rather than adjacent to the trigger.
When Mithril subsequently removes the trigger element from the DOM
(e.g. closing the notification dropdown), Bootstrap is never informed
and the tooltip DOM node is left stranded in the container — visible
forever, impossible to dismiss.
Without `container`, Bootstrap places the tooltip adjacent to the
trigger element; it is removed as part of normal DOM cleanup and the
issue does not manifest.
The fix adds an `onremove` lifecycle hook that calls `tooltip('destroy')`
on the child DOM node before Mithril removes it. This is identical to
the destroy call already used in `recreateTooltip()` when the tooltip
text changes, so the approach is consistent with the existing pattern.
Fixes the regression introduced by #4375 (adding `container="body"` to
the notification list tooltips to fix positioning inside the
overflow-clipped dropdown).
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
imorland
added a commit
that referenced
this pull request
Feb 21, 2026
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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.
Problem
When the
containerprop is set to"body"(or any element other than the trigger's natural parent), Bootstrap appends the tooltip's DOM node directly to that container rather than adjacent to the trigger element.When Mithril subsequently removes the trigger element from the DOM — for example, when the notification dropdown is closed — Bootstrap is never informed. The tooltip DOM node is left stranded in
<body>, remains visible on screen, and cannot be dismissed. The tooltip stays there permanently until the page is reloaded.This was introduced as a regression by #4375, which correctly added
container="body"to the notification list tooltips to fix their positioning inside the overflow-clipped dropdown. The positioning fix works, but exposed the missing cleanup.Without
container, Bootstrap places the tooltip adjacent to the trigger element in the normal DOM tree; it is removed as part of Mithril's standard DOM cleanup and the problem does not occur.Root cause
Tooltip.tsxhad noonremovelifecycle hook. The Bootstrap tooltip instance was never explicitly destroyed when the Mithril component was removed.Fix
Add an
onremovehook that callstooltip('destroy')on the child DOM node before Mithril removes it. This is identical to thedestroycall already used inrecreateTooltip()when the tooltip text changes, so the approach is consistent with the existing pattern in this component.Impact
Tooltipusages on removal, not justcontainer="body"— this is the right behaviour regardlesscontaineris not set, since Bootstrap already handles cleanup naturally in that caseTesting