Fixes #28608: API account tooltips are broken when table is sorted or refreshed#7061
Conversation
| // remove attributes, handlers left by tooltips: sometimes (with Elm replacing the DOM elements) they are still present | ||
| function disposeBsTooltips() { | ||
| document | ||
| .querySelectorAll('[data-bs-toggle="tooltip"],[data-bs-original-title]') | ||
| .forEach(tooltip => { | ||
| bootstrap.Tooltip.getInstance(tooltip)?.dispose() | ||
| tooltip.removeAttribute("data-bs-original-title") | ||
| tooltip.removeEventListener('hide.bs.tooltip', bsTooltipsRemovalListener) | ||
| tooltip.removeEventListener('show.bs.tooltip', bsTooltipsRemovalListener) | ||
| }) |
There was a problem hiding this comment.
this new function does the "unmounting" of the tooltip from the DOM element (at least in theory, from the doc)
But as explained in the description, several attributes still remain... it won't clean up correctly
| const bsTooltipsRemovalListener = () => removeBsTooltips() | ||
|
|
||
| function initBsTooltips(){ | ||
| var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); | ||
| return tooltipTriggerList.map(function (tooltipTriggerEl) { | ||
| let dataTrigger = $(tooltipTriggerEl).attr('data-bs-trigger'); | ||
| let trigger = dataTrigger === undefined ? 'hover' : dataTrigger; | ||
| tooltipTriggerEl.addEventListener('hide.bs.tooltip', () => { | ||
| removeBsTooltips(); | ||
| }); | ||
| tooltipTriggerEl.addEventListener('show.bs.tooltip', () => { | ||
| removeBsTooltips() | ||
| }); | ||
| tooltipTriggerEl.addEventListener('hide.bs.tooltip', bsTooltipsRemovalListener); | ||
| tooltipTriggerEl.addEventListener('show.bs.tooltip', bsTooltipsRemovalListener); |
There was a problem hiding this comment.
adding a stable reference to the event listener avoids duplicating the event listener function (it appeared several times when I looked in the inspector)
Also, this allows calling removeEventListener(..., registeredListener)
|
I've tried different things that improve the result, here is my conclusion:
So instead of: We should do something like: The last remaining issue (I hope 🤞) is the resolution delay of the MutationObserver's promise, which takes few millisecond to complete. But I can’t see how to improve on that. |
|
Last but not least, we should replace the attribute "title" with "data-bs-original-title"... This makes the generated .tooltip element actually disappeared 💀 |
| model.ui | ||
| cmd = | ||
| if filters /= ui.filters then | ||
| Cmd.batch [ clearTooltips (), initTooltips () ] |
There was a problem hiding this comment.
Cmd.batch is not garanteed to be sequential (clear and init sequentially)
There was a problem hiding this comment.
I found no easy Elm solution for this (other than a rather complex library) : the solution I opted for was to have a single resetTooltips port.
Tooltips are always reset anyway... (and sometimes we want the actual "removeBsTooltips" for frozen ones)
|
PR updated with a new commit |
|
PR updated with a new commit : forgot the |
|
PR updated with a new commit : fix the |
|
OK, squash merging this PR |
a03f6e6 to
233cc06
Compare
https://issues.rudder.io/issues/28608
EDIT : New understanding of tooltips
the only attribute that seems to be universally working is
data-bs-original-title, instead oftitle/data-bs-titleremoveBsTooltipsis only a hack for removing "stale" tooltips in some specific UX concerns ("the tooltip is frozen")we need a new function to properly dispose of tooltips, it's called
disposeBsTooltips:resetTooltipsis a single Port that guarantees that we have "dispose", then "init", and it is used in this PR upon the update of "table filters"to maximize performance, we could restrict tooltips actions to a selector of "tooltips within the Elm app" : just add a
<div id="app-container">and pass to the "dispose" and "init" functionsAdding a new function to dispose of tooltips completely :
removeBsTooltipsis to not work in this context because of how Elm swaps the DOM elements, by leaving tooltips at their previous location (which made the bug appear when : sorting the table, filtering, and adding and API account).I could not get rid of them :
data-bs-original-title:titlethat would remain, even on a-:I tried removing every attributes (including the
title) upon callingdispose()on the tooltip, and this solves the issue, but would make all tooltips not work globally when applying some filters on the table 🙃, so I didn't risk doing that