Skip to content

Issues with v7_startTransition and triggering useEffect from current location #12546

@joshkel

Description

@joshkel

I'm using React Router as a...

library

Reproduction

https://stackblitz.com/edit/react-router-timing-om2qkn6g?file=src%2FApp.tsx

  1. Click "Enable slowdown."
  2. Experiment with clicking on the various numbered links.
  3. Note that, sometimes, the resulting link is /n-1/b instead of /n or /n/b - in other words, the redirect takes effect from a previous browser location instead of the current browser location, and the user's manual navigation is lost.

System Info

System:
    OS: macOS 15.1.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 151.58 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.5 - ~/.nvm/versions/node/v18.20.5/bin/node
    Yarn: 4.5.3 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v18.20.5/bin/npm
    bun: 1.1.26 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 131.0.6778.140
    Edge: 131.0.2903.99
    Safari: 18.1.1
    Safari Technology Preview: 18.2

Used Package Manager

yarn

Expected Behavior

Using useEffect to trigger a navigation operation based off of the current location works as expected.

Actual Behavior

Because useLocation is updated asynchronously, by a React transition, it may lag behind the actual browser location.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions