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): tooltip stays open on fast movement #4482

Open
wants to merge 10 commits into
base: canary
Choose a base branch
from

Conversation

Connorelsea
Copy link

@Connorelsea Connorelsea commented Jan 2, 2025

Closes #4301

📝 Description

This PR fixes an issue where tooltips when hovered in quick succession would sometimes remain open in NextUI. It updates AnimatePresence and motion key handling to comply with motion's typical usage patterns.

⛳️ Current behavior (updates)

When moving a cursor quickly across a screen with many tooltips, some tooltips would stay open after mouse has left. This can be easily replicated by making a list of tooltips and moving the cursor up and down them at medium-quick speed, especially when closeDelay and openDelay are set to zero to increase the chance that interruptions of the close animation will occur.

🚀 New behavior

Tooltip no longer stays open on fast mouse movements across a list of tooltips. This ensures AnimatePresence is not prematurely unrendered on tooltip close by ensuring AnimatePresence is always rendered when disableAnimation is false, and not unrendered when isOpen is false. Previously animate presence was being unrendered on close due to the conditional combining isOpen and disableAnimation checks. This also adds the proper keys that allow framer-motion to properly track these animations. Removing the keys causes the regression to return.

💣 Is this a breaking change (Yes/No):

No breaking changes, small internal fix to tooltip with no effect on current usage patterns.

📝 Additional Information

I tried to think of a way to test this programatically, but I could not think of anything good. I added a storybook where I was able to test manually and replicate this issue locally on the canary branch. You can replicate by removing the keys and moving your cursor quickly up and down the list. Adding the keys back, alongside the change in AnimatePresence rendering, seemingly eliminates this behavior.

If someone can think of a better way to write a test for this, or wants to remove the storybook (or present it differently) as it was mostly used for testing this issue, let me know! I am available to make changes to this PR.

Replicated on public docs:

Screen.Recording.2024-12-29.at.2.59.07.PM.mov

Replicated on the storybook I added (pre-fix)

telegram-cloud-photo-size-1-5168126915008114304-y

Summary by CodeRabbit

  • New Features

    • Enhanced tooltip rendering with improved animation handling.
    • Added a new story template demonstrating multiple tooltips with immediate open/close behavior.
  • Improvements

    • Simplified tooltip content rendering logic.
    • Improved element identification during tooltip transitions.
    • Fixed an issue where tooltips remained open during fast movements.

Copy link

changeset-bot bot commented Jan 2, 2025

🦋 Changeset detected

Latest commit: 6336424

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@heroui/tooltip Patch
@heroui/slider Patch
@heroui/snippet Patch
@heroui/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 2, 2025

@Connorelsea is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request modifies the Tooltip component to enhance its rendering and animation logic. Key props are added to improve element identification during transitions, and conditional rendering for tooltip content is streamlined for better control over animation and visibility. Additionally, the MultipleTemplate function is updated to support dynamic rendering of multiple tooltips. A patch update to the @heroui/tooltip package addresses an issue where tooltips remained open during rapid movements.

Changes

File Change Summary
packages/components/tooltip/src/tooltip.tsx - Added key prop to animated content derived from id
- Simplified conditional rendering for tooltip content
- Improved handling of disableAnimation and isOpen states
packages/components/tooltip/stories/tooltip.stories.tsx - Updated MultipleTemplate to include ManyTooltipComponent for dynamic tooltip rendering
- Maintained original functionality while allowing for a larger number of tooltips
.changeset/two-insects-provide.md - Updated @heroui/tooltip package to fix tooltip behavior during fast movements

Assessment against linked issues

Objective Addressed Explanation
Prevent tooltips from staying open too long [#4301]
Handle rapid mouse movement over multiple tooltips [#4301]
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jrgarciadev
Copy link
Member

Hey @Connorelsea thanks, please add a changeset

@wingkwong wingkwong changed the title fix(components): tooltip stays open on fast movement fix(tooltip): tooltip stays open on fast movement Jan 3, 2025
@Connorelsea
Copy link
Author

Hello @jrgarciadev, I added a changeset, tried to follow the linked changeset documentation as I have never used that tool before. If it's incorrect I can fix it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/two-insects-provide.md (1)

5-5: Consider enhancing the changeset description.

While the description captures the essence of the change, it would be more helpful for future reference if you could include:

  • The specific motion keys that were added
  • Details about the AnimatePresence rendering changes
  • Any performance implications of these changes
-fix tooltip staying open on fast movement by adding proper motion keys and ensuring AnimatePresence stays rendered, no breaking changes or usage changes required
+fix tooltip staying open on fast movement by:
+- adding unique motion keys to tooltip content for proper animation tracking
+- ensuring AnimatePresence component remains mounted until animations complete
+- improving render performance during rapid tooltip transitions
+
+No breaking changes or usage changes required.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6408d7 and ab7167e.

📒 Files selected for processing (1)
  • .changeset/two-insects-provide.md (1 hunks)
🔇 Additional comments (1)
.changeset/two-insects-provide.md (1)

1-3: LGTM! Version bump is appropriate.

The minor version bump is correctly chosen as this change adds functionality in a backward-compatible manner.

@wingkwong wingkwong modified the milestones: v2.6.11, v2.6.12 Jan 4, 2025
Copy link

vercel bot commented Jan 18, 2025

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

Name Status Preview Comments Updated (UTC)
heroui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2025 7:40am
heroui-sb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2025 7:40am

@Ejdyz
Copy link

Ejdyz commented Jan 24, 2025

Hello, i dont know if its done or not, but in this preview (The build from vercel above) i was still able to replicate the issue.

OS: Ubuntu 24.04.1 LTS x86_64
Browser: 132.0.6834.110 (Official Build) (64-bit)

clideo_editor_c9abb29b475f42639202803dd419dd15.mp4

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still reproducing the issue

image

@wingkwong wingkwong removed their assignment Jan 25, 2025
@wingkwong wingkwong modified the milestones: v2.6.15, v2.7.0 Jan 25, 2025
@Connorelsea
Copy link
Author

Connorelsea commented Jan 28, 2025

@wingkwong Will look into it and see if I can reproduce and fix. And I'll update the Multiple storybook

Edit: apologies for the delay, gonna try to get to this soon

@AntoineArt
Copy link

Just a post to thank @Connorelsea, I use tooltips a lot and this bug was really annoying my users and I, I look forward to have the fix in official release!

Copy link

pkg-pr-new bot commented Feb 23, 2025

Open in Stackblitz

@heroui/accordion

npm i https://pkg.pr.new/@heroui/accordion@4482

@heroui/autocomplete

npm i https://pkg.pr.new/@heroui/autocomplete@4482

@heroui/alert

npm i https://pkg.pr.new/@heroui/alert@4482

@heroui/avatar

npm i https://pkg.pr.new/@heroui/avatar@4482

@heroui/badge

npm i https://pkg.pr.new/@heroui/badge@4482

@heroui/breadcrumbs

npm i https://pkg.pr.new/@heroui/breadcrumbs@4482

@heroui/button

npm i https://pkg.pr.new/@heroui/button@4482

@heroui/calendar

npm i https://pkg.pr.new/@heroui/calendar@4482

@heroui/card

npm i https://pkg.pr.new/@heroui/card@4482

@heroui/checkbox

npm i https://pkg.pr.new/@heroui/checkbox@4482

@heroui/chip

npm i https://pkg.pr.new/@heroui/chip@4482

@heroui/code

npm i https://pkg.pr.new/@heroui/code@4482

@heroui/date-input

npm i https://pkg.pr.new/@heroui/date-input@4482

@heroui/date-picker

npm i https://pkg.pr.new/@heroui/date-picker@4482

@heroui/divider

npm i https://pkg.pr.new/@heroui/divider@4482

@heroui/drawer

npm i https://pkg.pr.new/@heroui/drawer@4482

@heroui/dropdown

npm i https://pkg.pr.new/@heroui/dropdown@4482

@heroui/form

npm i https://pkg.pr.new/@heroui/form@4482

@heroui/image

npm i https://pkg.pr.new/@heroui/image@4482

@heroui/input

npm i https://pkg.pr.new/@heroui/input@4482

@heroui/input-otp

npm i https://pkg.pr.new/@heroui/input-otp@4482

@heroui/kbd

npm i https://pkg.pr.new/@heroui/kbd@4482

@heroui/link

npm i https://pkg.pr.new/@heroui/link@4482

@heroui/listbox

npm i https://pkg.pr.new/@heroui/listbox@4482

@heroui/menu

npm i https://pkg.pr.new/@heroui/menu@4482

@heroui/modal

npm i https://pkg.pr.new/@heroui/modal@4482

@heroui/navbar

npm i https://pkg.pr.new/@heroui/navbar@4482

@heroui/number-input

npm i https://pkg.pr.new/@heroui/number-input@4482

@heroui/pagination

npm i https://pkg.pr.new/@heroui/pagination@4482

@heroui/popover

npm i https://pkg.pr.new/@heroui/popover@4482

@heroui/progress

npm i https://pkg.pr.new/@heroui/progress@4482

@heroui/radio

npm i https://pkg.pr.new/@heroui/radio@4482

@heroui/ripple

npm i https://pkg.pr.new/@heroui/ripple@4482

@heroui/scroll-shadow

npm i https://pkg.pr.new/@heroui/scroll-shadow@4482

@heroui/select

npm i https://pkg.pr.new/@heroui/select@4482

@heroui/skeleton

npm i https://pkg.pr.new/@heroui/skeleton@4482

@heroui/slider

npm i https://pkg.pr.new/@heroui/slider@4482

@heroui/snippet

npm i https://pkg.pr.new/@heroui/snippet@4482

@heroui/spacer

npm i https://pkg.pr.new/@heroui/spacer@4482

@heroui/spinner

npm i https://pkg.pr.new/@heroui/spinner@4482

@heroui/switch

npm i https://pkg.pr.new/@heroui/switch@4482

@heroui/table

npm i https://pkg.pr.new/@heroui/table@4482

@heroui/tabs

npm i https://pkg.pr.new/@heroui/tabs@4482

@heroui/toast

npm i https://pkg.pr.new/@heroui/toast@4482

@heroui/tooltip

npm i https://pkg.pr.new/@heroui/tooltip@4482

@heroui/user

npm i https://pkg.pr.new/@heroui/user@4482

@heroui/react

npm i https://pkg.pr.new/@heroui/react@4482

@heroui/system

npm i https://pkg.pr.new/@heroui/system@4482

@heroui/system-rsc

npm i https://pkg.pr.new/@heroui/system-rsc@4482

@heroui/theme

npm i https://pkg.pr.new/@heroui/theme@4482

@heroui/use-aria-accordion

npm i https://pkg.pr.new/@heroui/use-aria-accordion@4482

@heroui/use-aria-accordion-item

npm i https://pkg.pr.new/@heroui/use-aria-accordion-item@4482

@heroui/use-aria-button

npm i https://pkg.pr.new/@heroui/use-aria-button@4482

@heroui/use-aria-link

npm i https://pkg.pr.new/@heroui/use-aria-link@4482

@heroui/use-aria-modal-overlay

npm i https://pkg.pr.new/@heroui/use-aria-modal-overlay@4482

@heroui/use-aria-multiselect

npm i https://pkg.pr.new/@heroui/use-aria-multiselect@4482

@heroui/use-callback-ref

npm i https://pkg.pr.new/@heroui/use-callback-ref@4482

@heroui/use-clipboard

npm i https://pkg.pr.new/@heroui/use-clipboard@4482

@heroui/use-data-scroll-overflow

npm i https://pkg.pr.new/@heroui/use-data-scroll-overflow@4482

@heroui/use-disclosure

npm i https://pkg.pr.new/@heroui/use-disclosure@4482

@heroui/use-draggable

npm i https://pkg.pr.new/@heroui/use-draggable@4482

@heroui/use-image

npm i https://pkg.pr.new/@heroui/use-image@4482

@heroui/use-infinite-scroll

npm i https://pkg.pr.new/@heroui/use-infinite-scroll@4482

@heroui/use-intersection-observer

npm i https://pkg.pr.new/@heroui/use-intersection-observer@4482

@heroui/use-is-mobile

npm i https://pkg.pr.new/@heroui/use-is-mobile@4482

@heroui/use-is-mounted

npm i https://pkg.pr.new/@heroui/use-is-mounted@4482

@heroui/use-measure

npm i https://pkg.pr.new/@heroui/use-measure@4482

@heroui/use-pagination

npm i https://pkg.pr.new/@heroui/use-pagination@4482

@heroui/use-real-shape

npm i https://pkg.pr.new/@heroui/use-real-shape@4482

@heroui/use-ref-state

npm i https://pkg.pr.new/@heroui/use-ref-state@4482

@heroui/use-resize

npm i https://pkg.pr.new/@heroui/use-resize@4482

@heroui/use-safe-layout-effect

npm i https://pkg.pr.new/@heroui/use-safe-layout-effect@4482

@heroui/use-scroll-position

npm i https://pkg.pr.new/@heroui/use-scroll-position@4482

@heroui/use-ssr

npm i https://pkg.pr.new/@heroui/use-ssr@4482

@heroui/use-theme

npm i https://pkg.pr.new/@heroui/use-theme@4482

@heroui/use-update-effect

npm i https://pkg.pr.new/@heroui/use-update-effect@4482

@heroui/aria-utils

npm i https://pkg.pr.new/@heroui/aria-utils@4482

@heroui/dom-animation

npm i https://pkg.pr.new/@heroui/dom-animation@4482

@heroui/framer-utils

npm i https://pkg.pr.new/@heroui/framer-utils@4482

@heroui/react-rsc-utils

npm i https://pkg.pr.new/@heroui/react-rsc-utils@4482

@heroui/react-utils

npm i https://pkg.pr.new/@heroui/react-utils@4482

@heroui/shared-icons

npm i https://pkg.pr.new/@heroui/shared-icons@4482

@heroui/shared-utils

npm i https://pkg.pr.new/@heroui/shared-utils@4482

@heroui/stories-utils

npm i https://pkg.pr.new/@heroui/stories-utils@4482

@heroui/test-utils

npm i https://pkg.pr.new/@heroui/test-utils@4482

commit: 6336424

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you share more why we wrap LazyMotion even disableAnimation is true?

@Connorelsea
Copy link
Author

@wingkwong Good suggestions, made the changes. I did some testing and it works with all keys removed, so keeping them could go either way. And you are right about loading lazy motion, it's not required if animation is disabled.

@wingkwong wingkwong assigned jrgarciadev and unassigned wingkwong Feb 24, 2025
@wingkwong
Copy link
Member

@Connorelsea seems I couldn't reproduce on the current production. Are you able to reproduce?

@Connorelsea
Copy link
Author

Connorelsea commented Feb 27, 2025

@wingkwong Able to re-produce what exactly? The main scenario I saw with the most recent round was: move lazymotion above animate presence, can't get any tooltips to stick. VS, move lazymotion back to its original location, tooltips start sticking

Edit: Oh you mean tooltips sticking on current prod, I will test

@wingkwong
Copy link
Member

I'm not talking about the PR. I mean the original issue. After the recent release, I could no longer reproduce the issue in the production.

@wingkwong wingkwong closed this Feb 27, 2025
@wingkwong wingkwong reopened this Feb 27, 2025
@Connorelsea
Copy link
Author

@wingkwong I am able to reproduce on the currently deployed doc pages. If that is not running latest I can update my personal project to latest as well and check there.

It is easiest to reproduce on a high refresh rate screen with no other monitors slowing down rendering. Seems like a weird set of constraints but for arbitrary reproductions it happens easiest when I'm just on my laptop, although it does happen but less often in a normal multi-monitor scenario.

image

@wingkwong wingkwong modified the milestones: v2.7.4, v2.7.5 Feb 28, 2025
@jrgarciadev jrgarciadev modified the milestones: v2.7.5, v2.7.6 Mar 8, 2025
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.

[BUG] - Tooltip stays open more than it should
7 participants