Skip to content

fix(tooltip): Let ariakit merge the child ref to avoid React ref warning#1079

Merged
frankieyan merged 1 commit into
mainfrom
frankie/react-18-ref-fix
Jun 19, 2026
Merged

fix(tooltip): Let ariakit merge the child ref to avoid React ref warning#1079
frankieyan merged 1 commit into
mainfrom
frankie/react-18-ref-fix

Conversation

@frankieyan

@frankieyan frankieyan commented Jun 19, 2026

Copy link
Copy Markdown
Member

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 test props.ref:

Warning: ref is not a prop. Trying to access it will result in undefined being returned.
If you need to access the same value within the child component, you should pass it as a different
prop. (https://reactjs.org/link/special-props)

Turns out, Ariakit already merges the child element's ref and check for props.ref through its render prop:

So we can remove this logic and let Ariakit handle it: <TooltipAnchor render={child} store={tooltip} />

PR Checklist

  • Added tests for bugs / new features
  • Reviewed and approved Chromatic visual regression tests in CI

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.error during 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 with flushMicrotasks() 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 findByRole to block for the duration of the tooltip's 500ms showTimeout. To avoid slowing down the test suite and to align with the repository guidelines for Ariakit interactions, consider using fake timers and flushMicrotasks(): 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()

Share FeedbackReview Logs

expect(buttonRef.current).toBe(button)

const user = userEvent.setup()
await user.hover(button)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Honestly, I'm not sure if it warrants an extra test 🤔

@frankieyan frankieyan added the 👀 Show PR Used for PRs that need a review, but can be merged when CI is green. label Jun 19, 2026
@frankieyan frankieyan requested review from a team and gnapse and removed request for a team June 19, 2026 20:47
@frankieyan frankieyan merged commit bd2db2d into main Jun 19, 2026
11 checks passed
@frankieyan frankieyan deleted the frankie/react-18-ref-fix branch June 19, 2026 20:53
doist-release-bot Bot pushed a commit that referenced this pull request Jun 19, 2026
## [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))
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 33.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@doist-release-bot doist-release-bot Bot added the Released PRs that have been merged and released label Jun 19, 2026

@gnapse gnapse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Released PRs that have been merged and released 👀 Show PR Used for PRs that need a review, but can be merged when CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants