Skip to content

@radix-ui/popover: Cannot use anchorRef in React 19 #3635

Description

@marcoms

Bug report

Since updating to React 19, and changing MutableRefObject to RefObject, the following error gets raised by Radix Popover

Current Behavior

const ref = useRef<HTMLDivElement>(null);

return (
	<>
		<div ref={ref} />
		<RadixPopover.Root open>
			<RadixPopover.Anchor virtualRef={ref}>
		</RadixPopover.Root>
	</>
);
Type 'RefObject<HTMLDivElement | null>' is not assignable to type 'RefObject<Measurable>'.
  Type 'HTMLDivElement | null' is not assignable to type 'Measurable'.
    Type 'null' is not assignable to type 'Measurable'.ts(2322)

Expected behavior

Refs returned by useRef() should be usable as a virtualRef

Suggested solution

Update the virtualRef type to RefObject<Measurable | null>

Additional context

Your environment

Software Name(s) Version
Radix Package(s) 1.1.14
React n/a 19.1.0
Browser
Assistive tech
Node n/a
npm/yarn/pnpm
Operating System

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions