Skip to content

Popper component causing react error due to repeated setState calls #3546

@LordZardeck

Description

@LordZardeck

Bug report

When rapidly updating react component state, such as when a user is updating text in an input, anything that uses the popper anchor will throw a react error (and crash if you don't have error boundaries). This can be simulated on a Mac easily by adjusting the key repeat rate and delay until repeat to be fast and short respectively.

Current Behavior

React throws an error and crash the app whenever rapid re-renders happen

Expected behavior

State would not be updated during a render, therefore no crash or error would occur.

Reproducible example

CodeSandbox Template

Suggested solution

This line is the culprit I believe: https://github.com/radix-ui/primitives/blob/main/packages/react/popper/src/popper.tsx#L84

That line will call a setState function every re-render, which is against react practices.

Additional context

Here's an example of the crash, just by holding down the paste shortcut:
https://github.com/user-attachments/assets/b90cd54e-e4a3-4987-ad09-0967865836a8

Your environment

Software Name(s) Version
Radix Package(s) @radix-ui/react-dropdown-menu 2.1.6
React n/a 19.1.0
Browser Google Chrome 135.0.7049.117

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