Skip to content
Source
Sign inSign up
TanStack/router

refactor(router-core): skip beforeLoad and related store updates if options is not defined #4928

MergedSheraff(GitHub profile, opens in a new tab)merged 11 commits intomain fromrefs/pull/4928/headmerged by Sheraff(GitHub profile, opens in a new tab)

Showing 2 changed files with 84 additions and 7 deletions (loading 1).

x
0 of 2 viewed, 2 left
84 additions and 7 deletionspackages/react-router/tests/store-updates-during-navigation.test.tsxModified
View file
@@ -1,12 +1,19 @@
import { afterEach, describe, expect, test, vi } from 'vitest'
-import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from '@testing-library/react'
+import {
Link,
Outlet,
RouterProvider,
createRootRoute,
createRoute,
createRouter,
+ notFound,
Thread on line 16

💡 Verification agent

🧩 Analysis chain

Ensure the notFound export is available from the public entry

If notFound is a new public API, verify it’s exported from the package entry and re-exported where this test imports it.

Run this to confirm the export and its surface:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Looking for notFound exports (direct or re-export):"
rg -nP -C2 '(export\s+function\s+notFound\b)|(export\s+const\s+notFound\b)|(export\s*{\s*notFound\s*})' --type ts --glob '!**/node_modules/**'

echo
echo "Verifying createRouter options include defaultNotFoundComponent & defaultPreload:"
rg -nP -C3 '\b(defaultNotFoundComponent|defaultPreload)\b' --type ts --glob '!**/node_modules/**'

Length of output: 82102


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Import section from the test file ==="
sed -n '1,50p' packages/react-router/tests/store-updates-during-navigation.test.tsx

echo
echo "=== Re-exports of notFound in react-router public entry (index.ts) ==="
rg -nP 'export\s+.*notFound' packages/react-router/src/index.ts || echo "No direct re-exports found in index.ts"

Length of output: 1446


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Files in packages/react-router/src ==="
ls -1 packages/react-router/src

echo
echo "=== Looking for index.* files ==="
find packages/react-router/src -maxdepth 1 -type f -name "index.*" || echo "No index.* files found"

echo
echo "=== Showing contents of any index.* file ==="
for f in packages/react-router/src/index.*; do
  echo "---- $f ----"
  sed -n '1,200p' "$f"
done 2>/dev/null || true

Length of output: 5057


Missing public export of notFound

The test in packages/react-router/tests/store-updates-during-navigation.test.tsx imports notFound, but it isn’t re-exported in the public entry at packages/react-router/src/index.tsx. Add it to the export list:

• File: packages/react-router/src/index.tsx

-export {
-  defer,
-  TSR_DEFERRED_PROMISE,
-  isMatch,
-  joinPaths,
-  cleanPath,
-  trimPathLeft,
-  trimPathRight,
-  trimPath,
-  resolvePath,
-  parsePathname,
-  interpolatePath,
-  matchPathname,
-  removeBasepath,
-  matchByPath,
-  encode,
-  decode,
-  rootRouteId,
-  defaultSerializeError,
-  defaultParseSearch,
-  defaultStringifySearch,
-  parseSearchWith,
-  stringifySearchWith,
-  escapeJSON, // SSR
-  pick,
-  functionalUpdate,
-  replaceEqualDeep,
-  isPlainObject,
-  isPlainArray,
-  deepEqual,
-  shallow,
-  createControlledPromise,
-  retainSearchParams,
-  stripSearchParams,
-} from '@tanstack/router-core'
+export {
+  defer,
+  TSR_DEFERRED_PROMISE,
+  isMatch,
+  joinPaths,
+  cleanPath,
+  trimPathLeft,
+  trimPathRight,
+  trimPath,
+  resolvePath,
+  parsePathname,
+  interpolatePath,
+  matchPathname,
+  removeBasepath,
+  matchByPath,
+  encode,
+  decode,
+  rootRouteId,
+  defaultSerializeError,
+  defaultParseSearch,
+  defaultStringifySearch,
+  parseSearchWith,
+  stringifySearchWith,
+  escapeJSON, // SSR
+  pick,
+  functionalUpdate,
+  replaceEqualDeep,
+  isPlainObject,
+  isPlainArray,
+  deepEqual,
+  shallow,
+  createControlledPromise,
+  retainSearchParams,
+  stripSearchParams,
+  notFound,
+} from '@tanstack/router-core'
📝 Committable suggestion

‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

export {
  defer,
  TSR_DEFERRED_PROMISE,
  isMatch,
  joinPaths,
  cleanPath,
  trimPathLeft,
  trimPathRight,
  trimPath,
  resolvePath,
  parsePathname,
  interpolatePath,
  matchPathname,
  removeBasepath,
  matchByPath,
  encode,
  decode,
  rootRouteId,
  defaultSerializeError,
  defaultParseSearch,
  defaultStringifySearch,
  parseSearchWith,
  stringifySearchWith,
  escapeJSON, // SSR
  pick,
  functionalUpdate,
  replaceEqualDeep,
  isPlainObject,
  isPlainArray,
  deepEqual,
  shallow,
  createControlledPromise,
  retainSearchParams,
  stripSearchParams,
  notFound,
} from '@tanstack/router-core'
🤖 Prompt for AI Agents
packages/react-router/src/index.tsx (export list): The test imports `notFound`
but it is not exported from the package entry; add a named export for `notFound`
to the public export list in packages/react-router/src/index.tsx so it can be
imported by tests and consumers. Ensure the exported identifier matches the
internal symbol (or re-export from its source module), update the export list
accordingly, and run the test suite to verify the import succeeds.
redirect,
useRouterState,