Skip to content

fix: tooltip ID cleanup #3096

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

Merged
merged 2 commits into from
Mar 29, 2025
Merged

Conversation

mcmcgrath13
Copy link
Contributor

@mcmcgrath13 mcmcgrath13 commented Feb 28, 2025

Summary

Related Issues or PRs

Cleanup based on PR feedback to #3094

Use hooks properly (per react's rules of hooks) in generating and using the ID for the tooltip component.

How To Test

Pure refactor/bug fix.

Screenshots (optional)

No react hooks warnings when loaded
image

@mcmcgrath13 mcmcgrath13 marked this pull request as ready for review February 28, 2025 15:52
@mcmcgrath13 mcmcgrath13 requested a review from a team as a code owner February 28, 2025 15:52
@brandonlenz
Copy link
Contributor

@mdmower-csnw Does this PR match your expectation?

@mdmower-csnw
Copy link
Contributor

@mdmower-csnw Does this PR match your expectation?

@brandonlenz - This fixes the issues I mentioned in comment #3094 (comment), so from that perspective it's ok (the pull request description could use a little work, though).

As far as what good this PR and #3094 do for users... I'm less clear. The ID is still generated, not definable as requested in #2562. There's a better chance that the ID will be the same each time a test suite runs (for example tooltip-:r3:), but there's plenty of ways it can change, too. Re-rendering the Tooltip component during client-side rendering generates a new ID each time. I'm less experienced with server-side rendering, but I wonder if adding a new use of Tooltip that gets pre-rendered before the Tooltip of interest would also cause the ID to change? If the only goal here is to make the ID a bit more deterministic so that the ID is likely to be the same when the component is rendered for tests, then I guess this is ok.

@mcmcgrath13
Copy link
Contributor Author

mcmcgrath13 commented Mar 4, 2025

The main benefit is that React's useId is designed to play nicely with server side rendering. Hydration handles useId so that it is deterministic between server and client. It's also a much more targeted thing to mock during testing than random number generation.

Making id an optional prop could be a nice improvement down the road, but this fix solves the problems I'm currently hacking around for SSR in a pretty ugly way

@mcmcgrath13
Copy link
Contributor Author

@brandonlenz any remaining concerns?

@ajfarkas ajfarkas force-pushed the mcm-tooltip-id-redux branch from 856f5e8 to 453c3b8 Compare March 29, 2025 00:03
Copy link
Contributor

@ajfarkas ajfarkas left a comment

Choose a reason for hiding this comment

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

lgtm

@ajfarkas ajfarkas merged commit c161e1e into trussworks:main Mar 29, 2025
6 checks passed
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.

4 participants