Skip to content

Bug: state updates in ResizeObserver callback are not batched, causing multiple re-rendering of component #21119

@szhsin

Description

@szhsin

React version: 17.0.2
Browser: recent versions of Chrome/Safari/Firefox

Steps To Reproduce

  1. Write multiple state updates in ResizeObserver callback.
  2. Cause observer target to change size.

Link to code example: https://codesandbox.io/s/resizeobserver-not-batch-state-update-6rb6y

The current behavior

Each state update in ResizeObserver callback leads to an individual re-rendering of component.
In my example, calling addCounter() three times in ResizeObserver callback results in the component being re-rendered three times.
In contrast, calling addCounter() three times in button onClick event causes only a single re-rendering of component.

The expected behavior

Multiple state updates in ResizeObserver callback are batched and cause a single re-rendering of component, which helps improve performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions