fix: global events broke on ios#1282
Conversation
📝 WalkthroughWalkthroughThe PR fixes a bug where tooltips on iOS become permanently unresponsive after a scroll closes them. It adds delegated ChangesiOS Tooltip Reopening
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Beta version released with the last commit 🚀 or |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/components/Tooltip/use-tooltip-events.tsx (1)
360-364: ⚡ Quick winConsider adding
{ passive: true }to the touchstart listener for better scroll performance.Touch event listeners that don't call
preventDefaultshould be marked passive to allow the browser to optimize scrolling, especially on mobile devices where this fix is needed.⚡ Proposed performance improvement
if (actualOpenEvents.mouseenter || actualOpenEvents.mouseover || actualOpenEvents.focus) { - addDelegatedListener('touchstart', (event) => { + addDelegatedListener('touchstart', (event) => { debouncedHandleShowTooltip(resolveAnchorElementRef.current(event.target)) - }) + }, { passive: true }) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/Tooltip/use-tooltip-events.tsx` around lines 360 - 364, The touchstart handler added in the conditional that checks actualOpenEvents (inside use-tooltip-events) should be registered as a passive listener to improve scroll performance: update the call to addDelegatedListener('touchstart', ...) to pass { passive: true } (or an options object your helper accepts) so the browser knows preventDefault won't be called; keep the same callback that calls debouncedHandleShowTooltip(resolveAnchorElementRef.current(event.target)) and ensure addDelegatedListener supports an options parameter or overload it accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/test/tooltip-anchor-selection.spec.js`:
- Around line 80-81: The test fires touchStart but never advances fake timers or
asserts the tooltip reopened; update the test around the
fireEvent.touchStart(anchor) + await waitForTooltip('touch-scroll-test')
sequence to advance timers (e.g., jest.advanceTimersByTime or runAllTimers) by
at least the 50ms debounce so the touch handler runs, then assert the tooltip
element is present in the document (from waitForTooltip) and that it does not
have the 'closing' class; apply the same change to the similar block at lines
86-89 so both touch-scroll scenarios advance timers and verify reopen +
non-closing state.
---
Nitpick comments:
In `@src/components/Tooltip/use-tooltip-events.tsx`:
- Around line 360-364: The touchstart handler added in the conditional that
checks actualOpenEvents (inside use-tooltip-events) should be registered as a
passive listener to improve scroll performance: update the call to
addDelegatedListener('touchstart', ...) to pass { passive: true } (or an options
object your helper accepts) so the browser knows preventDefault won't be called;
keep the same callback that calls
debouncedHandleShowTooltip(resolveAnchorElementRef.current(event.target)) and
ensure addDelegatedListener supports an options parameter or overload it
accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d55ce7a2-145f-444a-9130-9f889735182e
📒 Files selected for processing (2)
src/components/Tooltip/use-tooltip-events.tsxsrc/test/tooltip-anchor-selection.spec.js
fix #1281
Summary by CodeRabbit
New Features
Bug Fixes
Tests