Skip to content

Commit 594c713

Browse files
authored
fix: useHoverOverlay swallowing refs (#88094)
in React 18, we were not able to access the ref prop as it used to throw due to refs being a reserved prop. With react 19, the ref is just a prop, meaning we can compose it correctly
1 parent ced9757 commit 594c713

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

static/app/utils/useHoverOverlay.spec.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,23 @@ describe('useHoverOverlay', () => {
3333
await userEvent.tab();
3434
expect(componentProps.onBlur).toHaveBeenCalled();
3535
});
36+
37+
it('skipWrapper=true does not swallow refs', () => {
38+
function InnerComponent(
39+
props: Partial<React.HTMLAttributes<HTMLDivElement>> &
40+
React.RefAttributes<HTMLDivElement>
41+
) {
42+
return <div {...props} />;
43+
}
44+
45+
const ref = jest.fn();
46+
47+
const WrappedComponent = () => {
48+
const {wrapTrigger} = useHoverOverlay({skipWrapper: true});
49+
return wrapTrigger(<InnerComponent ref={ref} />);
50+
};
51+
52+
render(<WrappedComponent />);
53+
expect(ref).toHaveBeenCalled();
54+
});
3655
});

static/app/utils/useHoverOverlay.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import type {PopperProps} from 'react-popper';
1212
import {usePopper} from 'react-popper';
1313
import {useTheme} from '@emotion/react';
14-
import {mergeProps} from '@react-aria/utils';
14+
import {mergeProps, mergeRefs} from '@react-aria/utils';
1515

1616
import type {ColorOrAlias} from 'sentry/utils/theme';
1717

@@ -292,6 +292,7 @@ function useHoverOverlay({
292292
return cloneElement<any>(
293293
triggerChildren,
294294
Object.assign(mergeProps(triggerChildren.props as any, providedProps), {
295+
ref: mergeRefs((triggerChildren.props as any).ref, setTriggerElement),
295296
style: triggerStyle,
296297
})
297298
);
@@ -301,6 +302,7 @@ function useHoverOverlay({
301302
return cloneElement<any>(
302303
triggerChildren,
303304
Object.assign(mergeProps(triggerChildren.props as any, providedProps), {
305+
ref: mergeRefs((triggerChildren.props as any).ref, setTriggerElement),
304306
style: (triggerChildren.props as any).style,
305307
})
306308
);

0 commit comments

Comments
 (0)