fix(tooltip): Let ariakit merge the child ref to avoid React ref warning#1079
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
doistbot
left a comment
There was a problem hiding this comment.
This PR simplifies Tooltip by removing manual child ref extraction and letting Ariakit handle ref merging via its render prop, eliminating a React 18 dev warning about accessing props.ref.
Few things worth tightening:
- The new test doesn't actually lock in the regression this PR fixes—consider spying on
console.errorduring render and asserting the special-props warning is never logged, so the test would catch it if the warning comes back. - The hover interaction in the test relies on real timers and blocks for the full 500ms
showTimeout; switching to fake timers withflushMicrotasks()would keep it in line with repo conventions and speed up the suite.
I also included a few optional follow-up notes in the details below.
Optional follow-up note (1)
- [P3] src/tooltip/tooltip.test.tsx:175: This hover interaction relies on real timers, causing
findByRoleto block for the duration of the tooltip's 500msshowTimeout. To avoid slowing down the test suite and to align with the repository guidelines for Ariakit interactions, consider using fake timers andflushMicrotasks():tsx jest.useFakeTimers() const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }) await user.hover(button) act(() => { jest.advanceTimersByTime(500) }) await flushMicrotasks() expect(screen.getByRole('tooltip', { name: 'tooltip content here' })).toBeInTheDocument() jest.useRealTimers()
| expect(buttonRef.current).toBe(button) | ||
|
|
||
| const user = userEvent.setup() | ||
| await user.hover(button) |
There was a problem hiding this comment.
🟡 P2 This still doesn't exercise the bug this PR fixes. The failure mode was a React 18 dev warning during render when props.ref is accessed, but these assertions only verify ref forwarding and hover behavior—both can still pass if that warning comes back. Please spy on console.error around the render and assert that the special-props warning is not logged.
There was a problem hiding this comment.
Honestly, I'm not sure if it warrants an extra test 🤔
## [33.2.2](v33.2.1...v33.2.2) (2026-06-19) ### Bug Fixes * **tooltip:** Let ariakit merge the child ref to avoid React ref warning ([#1079](#1079)) ([bd2db2d](bd2db2d))
|
🎉 This PR is included in version 33.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Short description
In #1074, we tried to match
Tooltip's previous implementation where we extract and pass along its child's ref to Ariakit, while keeping React 18 and 19 compatibility.. However, this causes a dev mode warning in React 18 when we try to testprops.ref:Turns out, Ariakit already merges the child element's ref and check for
props.refthrough itsrenderprop:So we can remove this logic and let Ariakit handle it:
<TooltipAnchor render={child} store={tooltip} />PR Checklist