Skip to content

react-dom logs error to console when form.checkValidity() is called during render #17448

@nwoltman

Description

@nwoltman

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

react-dom logs an error to the console when .checkValidity() is called on a form element (from a ref) inside the render part of a function component. The error is only logged when .checkValidity() returns false. This is the error message:

Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.

CodeSandbox: https://codesandbox.io/s/pensive-colden-ipuwi

What is the expected behavior?

Nothing should be logged to the console.

A more informative error should be logged to the console (see comment).

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React/ReactDOM: 6.10.0 - 6.12.0 (this worked as expected in 6.9.0)
Browser: Chrome 78, Firefox 70
OS: any

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions