Skip to content

fix(router): reuse resolved lazy route components - #8054

Open
Sheraff wants to merge 2 commits into
mainfrom
fix/issue-8049-lazy-route-revisit
Open

fix(router): reuse resolved lazy route components#8054
Sheraff wants to merge 2 commits into
mainfrom
fix/issue-8049-lazy-route-revisit

Conversation

@Sheraff

@Sheraff Sheraff commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • skip client preload work after a lazy route component has already resolved
  • preserve SSR promise reuse and failed-import retry behavior across React, Solid, and Vue
  • add unit coverage and a React Start painted-state regression fixture for route revisits

Testing

  • CI=1 NX_DAEMON=false pnpm nx run @tanstack/react-router:test:unit --outputStyle=stream --skipRemoteCache -- tests/component-preload-retry.test.tsx
  • CI=1 NX_DAEMON=false pnpm nx run @tanstack/solid-router:test:unit --outputStyle=stream --skipRemoteCache
  • CI=1 NX_DAEMON=false pnpm nx run @tanstack/vue-router:test:unit --outputStyle=stream --skipRemoteCache -- tests/component-preload-retry.test.tsx
  • CI=1 NX_DAEMON=false pnpm nx run-many --target=test:types --projects=@tanstack/router-core,@tanstack/react-router,@tanstack/solid-router,@tanstack/vue-router --outputStyle=stream --skipRemoteCache
  • CI=1 NX_DAEMON=false pnpm nx run-many --target=test:eslint --projects=@tanstack/router-core,@tanstack/react-router,@tanstack/solid-router,@tanstack/vue-router --outputStyle=stream --skipRemoteCache
  • CI=1 pnpm test:e2e in e2e/react-start/issue-8049
  • pnpm build in e2e/react-start/issue-8049

Fixes #8049

Summary by CodeRabbit

  • Bug Fixes

    • Improved lazy-loaded route navigation across React, Solid, and Vue applications.
    • Previously loaded route components are now reused when revisiting code-split pages.
    • Prevented unnecessary loading indicators, pending states, or blank content during navigation.
    • Preserved server-side loading behavior while avoiding duplicate client-side requests.
  • Tests

    • Added regression coverage confirming resolved components load only once and remain visible during subsequent navigation.

@nx-cloud

nx-cloud Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 8d93118

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 6m 56s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 37s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-12 15:04:26 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

4 package(s) bumped directly, 19 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.27 → 1.170.28 Changeset
@tanstack/router-core 1.171.22 → 1.171.23 Changeset
@tanstack/solid-router 1.170.25 → 1.170.26 Changeset
@tanstack/vue-router 1.170.24 → 1.170.25 Changeset
@tanstack/react-start 1.168.44 → 1.168.45 Dependent
@tanstack/react-start-client 1.168.25 → 1.168.26 Dependent
@tanstack/react-start-rsc 0.1.43 → 0.1.44 Dependent
@tanstack/react-start-server 1.167.32 → 1.167.33 Dependent
@tanstack/router-cli 1.167.28 → 1.167.29 Dependent
@tanstack/router-generator 1.167.28 → 1.167.29 Dependent
@tanstack/router-plugin 1.168.30 → 1.168.31 Dependent
@tanstack/router-vite-plugin 1.167.30 → 1.167.31 Dependent
@tanstack/solid-start 1.168.42 → 1.168.43 Dependent
@tanstack/solid-start-client 1.168.24 → 1.168.25 Dependent
@tanstack/solid-start-server 1.167.31 → 1.167.32 Dependent
@tanstack/start-client-core 1.170.22 → 1.170.23 Dependent
@tanstack/start-plugin-core 1.171.34 → 1.171.35 Dependent
@tanstack/start-server-core 1.169.26 → 1.169.27 Dependent
@tanstack/start-static-server-functions 1.167.27 → 1.167.28 Dependent
@tanstack/start-storage-context 1.167.24 → 1.167.25 Dependent
@tanstack/vue-start 1.168.41 → 1.168.42 Dependent
@tanstack/vue-start-client 1.167.27 → 1.167.28 Dependent
@tanstack/vue-start-server 1.167.31 → 1.167.32 Dependent

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6adb7b87-ea6a-45ba-baae-d75543523483

📥 Commits

Reviewing files that changed from the base of the PR and between 6c4edd5 and 8d93118.

📒 Files selected for processing (2)
  • packages/vue-router/src/lazyRouteComponent.tsx
  • packages/vue-router/tests/component-preload-retry.test.tsx

📝 Walkthrough

Walkthrough

The change reuses resolved client-side lazy route components during preload. React, Solid, and Vue router types accept undefined preload results. Tests cover repeated preloads and route revisits without pending UI.

Changes

Lazy route preload reuse

Layer / File(s) Summary
React preload contract and reuse
packages/router-core/src/route.ts, packages/react-router/src/..., packages/react-router/tests/component-preload-retry.test.tsx
React lazy route components skip loading when already resolved. Preload types allow undefined. Tests cover repeated preload calls and revisiting lazy routes without pending UI.
Solid and Vue preload parity
packages/solid-router/src/..., packages/solid-router/tests/component-preload-retry.test.tsx, packages/vue-router/src/..., packages/vue-router/tests/component-preload-retry.test.tsx
Solid and Vue lazy route components reuse resolved client components. Vue retains resolved preload promises during SSR. Their preload types allow undefined.
React Start reproduction and E2E validation
e2e/react-start/issue-8049/..., .changeset/fuzzy-pandas-smile.md
Adds a React Start fixture with home and test routes, router and build configuration, and a Playwright test that checks route revisits without pending, shell, or empty states. Adds patch release entries for the affected packages.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Router
  participant LazyRouteComponent
  participant Importer
  User->>Router: Navigate to code-split route
  Router->>LazyRouteComponent: Preload route component
  LazyRouteComponent->>LazyRouteComponent: Check resolved client component
  alt Component already resolved
    LazyRouteComponent-->>Router: Return without importing
  else Component unresolved
    LazyRouteComponent->>Importer: Load component
    Importer-->>LazyRouteComponent: Resolve component
    LazyRouteComponent-->>Router: Complete preload
  end
  Router-->>User: Render route without pending flicker
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: reusing resolved lazy route components.
Linked Issues check ✅ Passed The changes address issue #8049 by reusing resolved components and preventing pending UI when revisiting code-split routes.
Out of Scope Changes check ✅ Passed The changeset, cross-framework fixes, tests, and React Start fixture directly support the lazy route reuse objective.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-8049-lazy-route-revisit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: a0083985394f
  • Measured at: 2026-08-12T15:00:08.946Z
  • Baseline source: history:38485038c52f
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes compared with the baseline:

Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 83.85 KiB +6 B (+0.01%) 83.71 KiB 262.50 KiB 73.03 KiB ▆██████▁▁▁▁▂
react-router.full 87.36 KiB +8 B (+0.01%) 87.22 KiB 274.21 KiB 76.12 KiB ▅█████▇▁▁▁▁▂
solid-router.minimal 33.18 KiB +10 B (+0.03%) 33.06 KiB 96.29 KiB 29.88 KiB ▅██████▁▁▁▁▂
solid-router.full 38.00 KiB +4 B (+0.01%) 37.88 KiB 110.92 KiB 34.17 KiB ▆██████▁▁▁▂▂
vue-router.minimal 49.59 KiB +11 B (+0.02%) 49.47 KiB 138.48 KiB 44.77 KiB ▃▄▄▄▄▄▄▁▁▁▇█
vue-router.full 55.21 KiB +22 B (+0.04%) 55.08 KiB 156.69 KiB 49.65 KiB ▂▄▄▄▄▄▄▁▁▁▇█
react-start.minimal 96.67 KiB +7 B (+0.01%) 96.53 KiB 304.71 KiB 83.76 KiB ▄█████▇▁▁▁▁▂
react-start.deferred-hydration 97.39 KiB +14 B (+0.01%) 96.55 KiB 306.07 KiB 84.38 KiB ▅█████▇▁▁▁▁▂
react-start.full 99.85 KiB +12 B (+0.01%) 99.71 KiB 314.43 KiB 86.51 KiB ▄██████▁▁▁▁▂
react-start.rsbuild.minimal 99.98 KiB +10 B (+0.01%) 99.80 KiB 315.13 KiB 86.24 KiB ▆██████▁▁▁▁▂
react-start.rsbuild.minimal-iife 100.38 KiB +10 B (+0.01%) 100.21 KiB 316.06 KiB 86.62 KiB ▆██████▁▁▁▁▂
react-start.rsbuild.full 103.29 KiB +8 B (+0.01%) 103.12 KiB 325.22 KiB 89.03 KiB ▆██████▁▁▁▁▂
solid-start.minimal 45.96 KiB +5 B (+0.01%) 45.83 KiB 137.35 KiB 40.83 KiB ▅██████▁▁▁▂▂
solid-start.deferred-hydration 49.03 KiB +7 B (+0.01%) 45.90 KiB 144.80 KiB 43.73 KiB ▄█████▇▁▁▁▂▂
solid-start.full 51.04 KiB +6 B (+0.01%) 50.91 KiB 152.73 KiB 45.23 KiB ▄██████▁▁▁▂▃
vue-start.minimal 65.64 KiB +12 B (+0.02%) 65.52 KiB 189.30 KiB 58.43 KiB ▃▄▄▄▄▄▄▁▁▁██
vue-start.full 69.45 KiB +16 B (+0.02%) 69.33 KiB 201.61 KiB 61.66 KiB ▂▄▄▅▅▅▄▁▁▁▇█

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@8054

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8054

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8054

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@8054

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8054

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@8054

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@8054

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8054

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@8054

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@8054

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@8054

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@8054

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@8054

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@8054

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@8054

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@8054

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@8054

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@8054

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8054

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@8054

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8054

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@8054

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8054

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8054

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@8054

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@8054

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@8054

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@8054

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8054

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@8054

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@8054

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8054

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@8054

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@8054

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8054

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@8054

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8054

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8054

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@8054

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@8054

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@8054

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@8054

commit: 8d93118

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vue-router/src/lazyRouteComponent.tsx`:
- Around line 69-70: Update the preload logic around the preload function and
load so SSR retains the resolved loadPromise instead of invoking importer()
again; only clear the promise after successful browser-side loading, while
preserving unconditional clearing on rejection to allow failed-import retries.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: be92081d-50d3-48fd-a0bc-a549d1747866

📥 Commits

Reviewing files that changed from the base of the PR and between 3848503 and 6c4edd5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (21)
  • .changeset/fuzzy-pandas-smile.md
  • e2e/react-start/issue-8049/package.json
  • e2e/react-start/issue-8049/playwright.config.ts
  • e2e/react-start/issue-8049/src/routeTree.gen.ts
  • e2e/react-start/issue-8049/src/router.tsx
  • e2e/react-start/issue-8049/src/routes/__root.tsx
  • e2e/react-start/issue-8049/src/routes/index.tsx
  • e2e/react-start/issue-8049/src/routes/test.tsx
  • e2e/react-start/issue-8049/tests/issue-8049.spec.ts
  • e2e/react-start/issue-8049/tsconfig.json
  • e2e/react-start/issue-8049/vite.config.ts
  • packages/react-router/src/lazyRouteComponent.tsx
  • packages/react-router/src/route.tsx
  • packages/react-router/tests/component-preload-retry.test.tsx
  • packages/router-core/src/route.ts
  • packages/solid-router/src/lazyRouteComponent.tsx
  • packages/solid-router/src/route.tsx
  • packages/solid-router/tests/component-preload-retry.test.tsx
  • packages/vue-router/src/lazyRouteComponent.tsx
  • packages/vue-router/src/route.ts
  • packages/vue-router/tests/component-preload-retry.test.tsx

Comment thread packages/vue-router/src/lazyRouteComponent.tsx
@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 5.02%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 12 improved benchmarks
❌ 13 regressed benchmarks
✅ 155 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem server error-paths not-found (vue) 467.2 KB 2,279.9 KB -79.51%
Memory mem server peak-large-page (react) 1.2 MB 2.1 MB -43.73%
Memory mem client unique-location-churn (solid) 346.5 KB 449.3 KB -22.87%
Memory mem client unique-location-churn (react) 667.3 KB 757.6 KB -11.92%
Memory mem client navigation-churn (vue) 1.5 MB 1.7 MB -8.97%
Simulation client-nested-params navigation loop (react) 212.5 ms 228.4 ms -6.99%
Memory mem client preload-churn (vue) 758.9 KB 802.1 KB -5.39%
Memory mem client interrupted-navigations (vue) 435.8 KB 459.9 KB -5.24%
Memory mem server peak-large-page (vue) 1 MB 1.1 MB -4.93%
Memory mem server peak-large-page (solid) 1 MB 1.1 MB -4.27%
Memory mem client navigation-churn (solid) 650.1 KB 672.4 KB -3.32%
Memory mem server aborted-requests (vue) 1,012.4 KB 1,046.7 KB -3.28%
Memory mem server error-paths error (vue) 945.3 KB 974.9 KB -3.04%
Memory mem server error-paths redirect (vue) 648.5 KB 401.6 KB +61.48%
Memory mem server error-paths not-found (solid) 911.2 KB 580.5 KB +56.97%
Memory mem server error-paths unmatched (react) 629.2 KB 435.7 KB +44.41%
Memory mem client unique-location-churn (vue) 576.1 KB 523.1 KB +10.12%
Memory mem server request-churn (react) 710.7 KB 666.5 KB +6.62%
Simulation client-route-tree-scale navigation loop (react) 172.3 ms 164.1 ms +4.97%
Memory mem server aborted-requests (solid) 1.2 MB 1.2 MB +4.34%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/issue-8049-lazy-route-revisit (8d93118) with main (3848503)

Open in CodSpeed

defaultPendingMinMs: 0,
defaultPendingComponent: () => <div role="status">Loading page</div>,
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please use data-testid instead of roles?

also, how does this assert that the pending component is NOT shown?

can we use faketimers and a defaultPendingMinMs > 0 and then check inbetween that the pending component (by id) is not visible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pendingComponent flicker on every route navigation

2 participants