Skip to content

Bug: useEffect runs before DOM changes are painted #29584

Closed
@rachitiitr

Description

@rachitiitr

React version: ^18.0.0

Steps To Reproduce

  1. Refer the attached codesandbox link
  2. Consider the click that leads to a winner in tic-tac-toe game
  3. We get an alert that a player has won, however, the board is not yet painted on the browser.
  4. The expectation of browser painting the click first followed by the effect execution is broken.

Video Link explaining the bug:
https://www.youtube.com/watch?v=v8KLOx_Mm48

Link to code example:
https://codesandbox.io/p/sandbox/tic-tac-toe-gpjn57

The current behavior

The expectation of browser painting the click first followed by the effect execution is broken.
We get an alert first, then the updated board is painted by browser.

The expected behavior

We expect the board to update first, then the effect should run which should cause the alert.

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