Skip to content
Source
Sign inSign up
TanStack/router

fix: ensure context is consistent on concurrent match loads #1891

Closedfreshgiammi(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/1891/headopened

If a match has multiple load routines running (such as navigation happening while preload isn't finished yet), we might start the loader function too early when the context isn't ready for consumption yet.

This happens because execution flow is skipped when a route already in beforeLoad fetching state is re-loaded.

This patch adds beforeLoad tracking to matched routes, so that we can eventually await any pending beforeLoad function and ensure we have up to date context to feed into the loader function.

Fixes https://github.com/TanStack/router/issues/1886

    1. ☁️ Nx Cloud Report

      CI is running/has finished running commands for commit 11e02da3120c98ccea508b813ebaccd45feb538d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

      📂 See all runs for this CI Pipeline Execution


      ✅ Successfully ran 4 targets

    2. Sent with 💌 from NxCloud.

  • packages/react-router/src/router.ts line 1985
    @@ -1982,4 +1996,3 @@
    19821996 checkLatest()
    19831997
    19841998 // Kick off the loader!
    1985- loaderPromise = route.options.loader?.(loaderContext)

    Weirdly enough, doing

    matches[index] = match = updateMatch(
      match.id,
      (prev) => ({
        ...prev,
        loaderPromise: route.options.loader?.(loaderContext),
       }),
    )

    instead of this breaks navigate from working 🤔

  • closing in favor of https://github.com/TanStack/router/pull/1907 I copied the test out of this PR, so thanks for this!

  • Sign in to join this conversation.