Repository navigation
fix: remove a tooltip that closes before it shows - #1293
Conversation
A tooltip is rendered first and shown 10ms later. The fallback that removes a closed tooltip was armed when `show` changed, so a tooltip that closed before that timer ran, or that a controlled `isOpen` never let show, stayed in the DOM with the closing class. Removal now has its own hook with one rule: a tooltip that is neither showing nor asked to show leaves the DOM. The timer and the transition end only mark the removal as due, and it is carried out where `show` is current. A tooltip that is hovered again while it closes is no longer removed just before it shows. Refs ReactTooltip#1292
A clickable tooltip took pointer events from the moment it was rendered: before it was positioned, before it was visible, and while it faded out. An invisible tooltip in the top-left corner could be hovered and clicked. Refs ReactTooltip#1292
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Hello! Thanks for the PR, I do prefer that approach. About the Esc edge case, I do believe it's ok for now since it's not common to keep the pointer in the tooltip and press Esc, it is an edge case, if it impacts someone and they report it, then I believe it worth it to work on it |
Summary
Fixes #1292.
A tooltip is rendered at once and shown 10 ms later. The fallback that takes a closed tooltip out of the DOM was armed only when
showchanged. A tooltip that never got to show had no change ofshow, so it stayed in the DOM withreact-tooltip__closingand opacity 0. Withclickableit also took clicks.use-tooltip-removal.tsx(new) owns removal, with one rule: a tooltip that is neither showing nor asked to show leaves the DOM.Tooltip.tsxpasses itrendered,showand whether a show was requested, and gets theonTransitionEndhandler back. The fallback timer, the delay lookup and theafterHidecall moved into the hook.showis current. Either of them can run just before a tooltip shows again, and removing it right there leftshowtrue with nothing in the DOM..clickable.showreplaces.clickableforpointer-events: auto. A tooltip that is not showing is invisible, and it could be hovered and clicked before it was positioned.What changes for users
Headless Chromium, built
dist, React 19. "Stuck" means still in the DOM 1.5 s later.open()andclose()in the same tickopen(),close()3 ms later, during a 30 ms long taskisOpentrue, then false 3 ms laterisOpen={false}, pointer moves onto the anchorclose(), thenopen()120 to 200 ms later (21 delays, 4 runs each)clickable+delayShow, pointer where the unpositioned tooltip mountsUnchanged on both: an ordinary close still fades (opacity between 0 and 0.9 at 85 ms, removed by 485 ms, 10 of 10), an open tooltip stays open, and a click inside a showing
clickabletooltip reaches it (10 of 10).Behavior to know about
afterHideis not called for a tooltip that never showed.afterShowwas not called for it either.afterHideis now called from an effect, asafterShowalready is. It used to be called from the timer or thetransitionendhandler.transitionendfor a property other thanopacityno longer cancels the fallback timer. On master that left the tooltip in the DOM when no opacity transition followed.clickabletooltip stops taking the pointer when it starts to fade out, about 150 ms earlier than before.A correction to the issue
The first sketch in #1292 removed the tooltip straight from a timer. That is wrong: after a long task the timer can run before a pending
setShow(true)renders, and the tooltip is removed just as it shows. In Chromium it lost the tooltip 3 of 10 times, and four existing tests failed. This PR decides in an effect instead.Tests
src/test/tooltip-removal.spec.js: 10 tests. On master 8 fail. The other 2 pin behavior that must not change (afterHideonce when the anchor is removed, none after unmount).imperative ref reports open for numeric zero contentfails on master too.scripts/configure-react-version.mjs. Each version fails only the tests that fail on master for that version.tooltip props › basic tooltipfails in some full-suite runs on master and on this branch, and passes on its own on both. I did not run it enough times to compare the two rates.tsc,yarn buildandbundlesizepass (react-tooltip.min.mjs9.18 kB gzip, limit 10 kB).Not in this PR
One thing I saw on master and left alone to keep this focused. I can open an issue for it if useful:
clickabletooltip while the pointer is on it, the next hover does not close on leave (10 of 10, same on this branch).If you would rather have a smaller patch that keeps the logic inline in
Tooltip.tsx, I am happy to restack it that way.I used an AI coding assistant to help write and test this change, and reviewed all of it myself.
Summary by CodeRabbit