Redirect from an effect during a pending navigation livelocks since router-core 1.171.16 (state.location alternates, nothing commits)

Ouverte
#8,762 1 commentaire 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@Sheraff y travaille déjà.

Depuis le 18/10/2026.

Évaluation

Cette issue n'a pas encore été évaluée.

Description

Which project does this relate to?

Router (in a Start app)

Describe the bug

Seen in a TanStack Start app; a standalone minimal repro is still pending (details below).

Starting with @tanstack/router-core 1.171.16 (#7805, the lane-based scheduler), a redirect issued from a component effect while another navigation is still pending can livelock. state.location keeps alternating between the two destinations, neither navigation commits, and the page stops responding.

The pattern (a root-level "gate" that sends the user to another route):

function Root() {
  const path = useRouterState({ select: (s) => s.location.pathname })
  const navigate = useNavigate()
  useEffect(() => {
    if (path !== '/') return
    navigate({ to: '/step', replace: true })
  }, [path, navigate])
  return <Outlet />
}

The sequence we observe:

  1. On /login, a successful sign-in calls navigate({ to: '/' }). That navigation is still pending (status: 'pending', resolvedLocation = /login).
  2. The root re-renders with location.pathname === '/', and the effect calls navigate({ to: '/step', replace: true }).
  3. From here state.location.pathname alternates /step, /, /step, / … on successive renders. resolvedLocation stays /login, status stays 'pending', and the browser URL never moves. The switch back to / happens before the effect's second navigate call. It looks as though the superseded / navigation re-publishes its location over the newer pending one.
  4. Because the effect is keyed on location.pathname, it sees / again and re-issues the navigation. Each re-issue settles the pending transition as superseded (Transitioner: settleOwner(acknowledgement, false)), and the cycle repeats.

On a production build this showed up as an intermittent hang. On the Vite dev server it happens every time. Measured there, the root component renders about 6,500 times a second and navigate is called about 1,700 times a second. The renderer pins a core, and CDP calls (Runtime.evaluate, Performance.enable) stop answering.

Captured router state per render (loc = state.location.pathname):

loc=/login  resolved=/login status=idle
loc=/       resolved=/login status=pending   <- navigation after sign-in, still pending
loc=/step   resolved=/login status=pending   <- effect: navigate({ to: '/step', replace: true })
loc=/       resolved=/login status=pending   <- reverted before any second navigate call
loc=/step   resolved=/login status=pending
loc=/       resolved=/login status=pending
… (indefinitely)
Bisect

We bisected over @tanstack/react-start releases (each pins its router packages). Same app code throughout:

react-start react-router / router-core result
1.168.35 1.170.18 / 1.171.15 redirect commits
1.168.36 1.170.19 / 1.171.16 livelock
1.168.42 1.170.25 / 1.171.21 (react-store still 0.9.3) livelock
1.168.60 1.170.41 / 1.171.34 livelock
1.168.61 1.170.42 / 1.171.35 livelock
react-router 1.170.45 / router-core 1.171.38 (forced) livelock

router-core 1.171.16 is the release that contains #7805.

Standalone repro attempts (none reproduce yet)

All on a bare Vite + React app with @tanstack/react-router 1.170.41, code-based routes, and the effect above, with /step having a 50 ms loader:

  1. Start at /. The redirect commits (4 renders).
  2. Start at /login; a button navigates to /, whose loader takes 50 ms, then 2 s, so the effect fires while / is pending. The redirect commits.
  3. As (2), plus an unrelated setState in the root every 20 ms. The redirect commits (308 renders).

Ingredients present in the Start app and absent from these attempts:

  • the Start client entry, with hydration of a server-rendered first document;
  • a beforeLoad on / that can throw redirect(). Disabling it did not stop the loop in the app, so it is probably not required;
  • the redirect target being a lazily loaded file route.

We'll update this issue if we get a standalone repro.

Expected behavior

While navigations overlap, state.location moves toward the latest requested navigation and does not revert to a superseded one. The latest navigation commits.

Workaround

Decide the redirect on the committed location (resolvedLocation?.pathname ?? location.pathname), and issue at most one navigation per (committed route, target). With that, our previously hanging cases pass every time.

Platform
  • @tanstack/react-start 1.168.60, @tanstack/react-router 1.170.41, @tanstack/router-core 1.171.34
  • React 19, Vite 7, Chromium (Playwright), macOS and Linux CI
Langage dominant
TypeScript
Étoiles
15.3k
Forks
1.9k
Merge moyen
1 j 5 h
PR mergées (30 j)
46

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de TanStack/router

Toutes les issues de TanStack/router

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.