Description
Provide a general summary of the issue here
We noticed that in one of our production apps (nextjs) after SSR hydration, the refs inside collection components do not point to their actual rendered DOM elements but to the rendered nodes in the hidden tree. In the following example, the groupRef is broken after the initial hydration, causing the popover to be positioned incorrectly. This is a significant issue for us because refs on inputs and buttons are also broken.
function MyComboBox<T extends object>({
label,
description,
errorMessage,
children,
...props
}: MyComboBoxProps<T>) {
const groupRef = React.useRef(null); // this ref is pointing to the hidden node after SSR
return (
<ComboBox {...props}>
<Label>{label}</Label>
<div ref={groupRef} className="my-combobox-container">
<Input />
<Button>▼</Button>
</div>
<Popover triggerRef={groupRef}>
<ListBox>{children}</ListBox>
</Popover>
</ComboBox>
);
}
Note: This does not happen when the component is client rendered only.
🤔 Expected Behavior?
All refs should point to their actually rendered dom element and not their hidden counterpart.
😯 Current Behavior
Refs above the collection point to their hidden node after server-side-rendering the component.
💁 Possible Solution
🔦 Context
No response
🖥️ Steps to Reproduce
https://stackblitz.com/edit/stackblitz-starters-cz1x8k?file=app%2Fbroken-ref-combobox.tsx
Version
1.4.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
Could reproduce this on safari, chrome and edge
What operating system are you using?
MacOS 14.6.1