Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tooltip): regression where hover to open stops working #1371

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Jul 11, 2024

Properly fixes the hover regressions introduced in #1369, causing studio tests to fail, which #1370 attempted to resolve but didn't.

Here's a video demonstrating that moving between tooltips last worked before #1369 merged, how it stopped working, and finally that it's working again in this PR:

tooltip.fix.mov

The root cause is that I didn't understand the significance of eagerly removing the mousemove event listener (line 303) in the original code:

// Detect whether the mouse is moving outside of the reference element. This is sometimes
// necessary, because the tooltip might not always close as it should (e.g. when clicking
// the reference element triggers a CPU-heavy operation.)
useEffect(() => {
if (!showTooltip) return
function handleWindowMouseMove(event: MouseEvent) {
if (!referenceElement) return
const isHoveringReference =
referenceElement === event.target ||
(event.target instanceof Node && referenceElement.contains(event.target))
if (!isHoveringReference) {
handleIsOpenChange(false)
window.removeEventListener('mousemove', handleWindowMouseMove)
}
}
window.addEventListener('mousemove', handleWindowMouseMove)
return () => {
window.removeEventListener('mousemove', handleWindowMouseMove)
}
}, [showTooltip, referenceElement, handleIsOpenChange])

and assumed it was there by mistake.
It's clearly very intentional and I've added a comment so that others don't make the same assumption in the future.

Copy link

vercel bot commented Jul 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sanity-ui-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2024 2:25pm
sanity-ui-workshop ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2024 2:25pm

@stipsan stipsan marked this pull request as ready for review July 11, 2024 14:28
@stipsan stipsan enabled auto-merge (squash) July 11, 2024 14:28
@stipsan stipsan merged commit 038011b into main Jul 11, 2024
11 checks passed
@stipsan stipsan deleted the fix-tooltip-mousemove-regression branch July 11, 2024 14:35
rexxars added a commit that referenced this pull request Jul 11, 2024
rexxars added a commit that referenced this pull request Jul 11, 2024
* Revert "fix(tooltip): regression where hover to open stops working (#1371)"

This reverts commit 038011b.

* Revert "fix(tooltip): use layout effect to calculate width (#1370)"

This reverts commit e39ddbe.

* Revert "fix: reduce layout trashing (#1369)"

This reverts commit 0cb1cb1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants