-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Warning: Function components cannot be given refs in DropdownMenuTrigger #2947
Copy link
Copy link
Open
Description
Bug Description
When using CopilotChat component, React throws a warning about function components not being able to receive refs:
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Check the render method of `Primitive.button.SlotClone`.
at DropdownMenuTrigger
at CopilotChatInput2.AddMenuButton
Steps to Reproduce
- Use
<CopilotChat />component in a React application - Open browser console
- Warning appears on render
Expected Behavior
No warning should appear - all components passed to Radix UI's DropdownMenuTrigger should properly forward refs.
Actual Behavior
Warning is logged to console on every render of the CopilotChat component.
Environment
@copilotkit/react-core: v2 (latest)- React: 18.x
- Browser: Chrome
Root Cause Analysis
The AddMenuButton component inside CopilotChatInput passes a function component to DropdownMenuTrigger that doesn't use React.forwardRef(). Radix UI's DropdownMenuTrigger expects its child to forward refs for accessibility and focus management.
Suggested Fix
Wrap the button component passed to DropdownMenuTrigger with React.forwardRef():
const TriggerButton = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => (
<button ref={ref} {...props} />
));Related Issues
- shadcn/ui #6872 - Similar issue with Sidebar in Dialog
- Radix Primitives #3765 - forwardRef deprecation in React 19
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels