Skip to content

Bug: useEffect does not run after changed dependencies due to startTransition #34556

@daniele-orlando

Description

@daniele-orlando

React version: 19.1.0

useEffect does not run after changed dependencies, due to startTransition.

Steps To Reproduce

  1. Open the StackBlitz reproduction
  2. open the terminal
  3. npm install
  4. npm run start:dev
  5. Open the browser Developer Tools
  6. Select Console tab from the Developer Tools
  7. Load/reload the StackBlitz preview page
  8. Watch the Developer Tools console logs.

Link to code reproductions:

The current behavior

File src/main.hooks.ts contains an hook named useData. Inside this hook, the useEffect at line 53 should be executed 2 times because dependencies change 2 times (first with value undefined and second time with value 1), but it is executed only once.

Following Developer Tools Console screenshot shows the issue.
Image

The expected behavior

The useEffect at line 53 should be executed 2 times because dependencies change 2 times (first with value undefined and second time with value 1).

Following Developer Tools Console screenshot shows the correct behavior.
Image

Correct behavior can be achieved with one of these two workarounds:

  • comment line 32 disabling the setExample(ExampleInitialValue)
  • de-comment line 38 enabling setExample(ExampleInitialValue + 1)

More Details

In this screenshot I show a brief explanation of the hook flow.

Image

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