fix(website): Make custom tooltips clickable on mobile#6427
Conversation
|
Claude finished @tombch's task in 2m 5s —— View job Code Review
Good fix overall. The approach of using SSR/Hydration mismatch — the most significant concern. const [isTouchOnly, setIsTouchOnly] = useState(false);
useEffect(() => {
setIsTouchOnly(window.matchMedia('(pointer: coarse)').matches);
}, []);Accessibility — the help icon DateRangeField interaction — |
|
|
||
| export const CustomTooltip: FC<ComponentProps<typeof Tooltip>> = ({ className, ...props }) => ( | ||
| export const CustomTooltip: FC<ComponentProps<typeof Tooltip>> = ({ className, ...props }) => { | ||
| const isTouchOnly = typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches; |
There was a problem hiding this comment.
This runs during render and causes an SSR/hydration mismatch in Astro — the server renders with isTouchOnly = false (no window), but a touch client re-renders with true. Between SSR and hydration, hover events briefly fire on touch devices. Prefer useState(false) + useEffect:
| const isTouchOnly = typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches; | |
| const [isTouchOnly, setIsTouchOnly] = useState(false); | |
| useEffect(() => { | |
| setIsTouchOnly(window.matchMedia('(pointer: coarse)').matches); | |
| }, []); |
And update the import to import { type ComponentProps, type FC, useEffect, useState } from 'react';
There was a problem hiding this comment.
This doesn't cause a SSR issue as far as I understand, as isTouchOnly doesn't affect the rendered DOM. So I think adding state and an effect here is unnecessary. I also tested this with firefox's mobile browsing simulator and it didn't come up with any hydration errors
There was a problem hiding this comment.
Yeah I think it's because the tooltip isn't rendered until you mouseover
CustomTooltipcomponent to be clickable on touchscreen only, and hover-able otherwise.PR Checklist
🚀 Preview: https://multifieldsearch-tooltip.loculus.org