Skip to content

perf(history): avoid generating unused location keys - #8349

Open
LadyBluenotes wants to merge 1 commit into
mainfrom
perf/history-lazy-location-key
Open

perf(history): avoid generating unused location keys#8349
LadyBluenotes wants to merge 1 commit into
mainfrom
perf/history-lazy-location-key

Conversation

@LadyBluenotes

@LadyBluenotes LadyBluenotes commented Sep 11, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Generate a fallback history key in parseHref only when no state is supplied. Parsing a location with existing state no longer creates and discards a random key.

Performance

Local Node.js 24.12.0 microbenchmark comparing 6494e75362 with 9eeb94f921. Nine alternating baseline/candidate rounds per case, with 100,000 warmup calls and 2,000,000 timed calls per sample. The URL is /items/123?tab=details#top; times below are medians.

Case Before After Change
parseHref with existing state 375.41 ms 115.24 ms About 69% less elapsed time
parseHref without state 382.24 ms 382.98 ms About +0.2%; within observed run variation
Minimal React Router bundle, gzip 85,993 bytes 85,996 bytes +3 bytes

Existing-state parsing removes one discarded key-generation operation per call. These are isolated runtime results, not an end-to-end navigation speedup or a retained-heap measurement.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Existing location state is now preserved without generating an unnecessary history key.
    • Locations created without state continue to receive independent initial state, including a unique key and index.
  • Tests
    • Added coverage for preserving supplied state and isolating automatically generated location state.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 4a2f714b-2348-4553-a958-f69a81dd9cb3

📥 Commits

Reviewing files that changed from the base of the PR and between 6494e75 and 9eeb94f.

📒 Files selected for processing (3)
  • .changeset/lazy-locations-listen.md
  • packages/history/src/index.ts
  • packages/history/tests/parseHref.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

parseHref now creates a default history state only when no state is supplied. Tests verify supplied state identity and independent generated states. A patch changeset documents the fix for @tanstack/history.

Changes

History state preservation

Layer / File(s) Summary
Conditional history state creation
packages/history/src/index.ts, .changeset/lazy-locations-listen.md
parseHref preserves supplied state and creates a keyed default state only when state is absent. The changeset records a patch release.
State preservation tests
packages/history/tests/parseHref.test.ts
Tests verify exact preservation of supplied frozen state and independence of generated default states.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: sheraff

Merge Risk: ⚪ Minimal · up to 9eeb9

The change avoids unnecessary key generation while preserving existing history-state behavior. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the change and motivation. It includes all required template sections, completed checklist items, testing confirmation, and changeset information.
Title check ✅ Passed The title clearly and concisely describes the main change: avoiding generation of unused location keys in history parsing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ 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 perf/history-lazy-location-key

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.

@nx-cloud

nx-cloud Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 9eeb94f

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 12m 11s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 11s View ↗

☁️ Nx Cloud last updated this comment at 2026-09-11 02:33:53 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 23 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/history 1.162.3 → 1.162.4 Changeset
@tanstack/react-router 1.170.35 → 1.170.36 Dependent
@tanstack/react-start 1.168.52 → 1.168.53 Dependent
@tanstack/react-start-client 1.168.33 → 1.168.34 Dependent
@tanstack/react-start-rsc 0.1.51 → 0.1.52 Dependent
@tanstack/react-start-server 1.167.40 → 1.167.41 Dependent
@tanstack/router-cli 1.167.35 → 1.167.36 Dependent
@tanstack/router-core 1.171.29 → 1.171.30 Dependent
@tanstack/router-generator 1.167.35 → 1.167.36 Dependent
@tanstack/router-plugin 1.168.37 → 1.168.38 Dependent
@tanstack/router-vite-plugin 1.167.37 → 1.167.38 Dependent
@tanstack/solid-router 1.170.33 → 1.170.34 Dependent
@tanstack/solid-start 1.168.50 → 1.168.51 Dependent
@tanstack/solid-start-client 1.168.32 → 1.168.33 Dependent
@tanstack/solid-start-server 1.167.39 → 1.167.40 Dependent
@tanstack/start-client-core 1.170.29 → 1.170.30 Dependent
@tanstack/start-plugin-core 1.171.42 → 1.171.43 Dependent
@tanstack/start-server-core 1.169.34 → 1.169.35 Dependent
@tanstack/start-static-server-functions 1.167.34 → 1.167.35 Dependent
@tanstack/start-storage-context 1.167.31 → 1.167.32 Dependent
@tanstack/vue-router 1.170.32 → 1.170.33 Dependent
@tanstack/vue-start 1.168.49 → 1.168.50 Dependent
@tanstack/vue-start-client 1.167.35 → 1.167.36 Dependent
@tanstack/vue-start-server 1.167.39 → 1.167.40 Dependent

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 1d2719acf09e
  • Measured at: 2026-09-11T02:22:32.709Z
  • Baseline source: history:6494e75362ff
  • Dashboard: bundle-size history

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

Scenario Current (gzip) Initial (gzip) Raw Brotli Trend
react-router.minimal 84.0 KiB
+3 B
83.8 KiB
-1 B
262.3 KiB
+12 B
73.2 KiB
-25 B
▁▁███████▄▄▄
react-router.full 87.5 KiB
+2 B
87.3 KiB
+3 B
274.0 KiB
+12 B
76.2 KiB
-92 B
▁▁███████▅▅▅
solid-router.minimal 33.5 KiB
-2 B
33.3 KiB
+2 B
96.8 KiB
+12 B
30.3 KiB
+15 B
▁▁██████████
solid-router.full 38.3 KiB
-1 B
38.2 KiB
0 B
111.4 KiB
+12 B
34.4 KiB
-56 B
▁▁██████████
vue-router.minimal 49.6 KiB
-1 B
49.5 KiB
+2 B
138.3 KiB
+12 B
44.9 KiB
+14 B
▁▂███████▁▁▁
vue-router.full 55.2 KiB
+1 B
55.1 KiB
+1 B
156.5 KiB
+12 B
49.8 KiB
-19 B
▂▂███████▁▁▁
react-start.minimal 96.9 KiB
-1 B
96.8 KiB
-1 B
304.6 KiB
+12 B
84.1 KiB
-33 B
▁▁███████▄▄▄
react-start.query-integration 104.2 KiB
-3 B
104.1 KiB
+1 B
331.1 KiB
+12 B
90.4 KiB
+69 B
▁▁███████▅▅▅
react-start.deferred-hydration 97.6 KiB
+3 B
96.8 KiB
+2 B
306.0 KiB
+12 B
84.8 KiB
+75 B
▁▁███████▄▄▄
react-start.full 100.1 KiB
+4 B
99.9 KiB
+1 B
314.3 KiB
+12 B
86.7 KiB
+9 B
▁▁███████▄▄▄
react-start.rsbuild.minimal 100.1 KiB
+1 B
100.0 KiB
+1 B
314.9 KiB
+12 B
86.4 KiB
-16 B
▁▁███████▃▃▃
react-start.rsbuild.minimal-iife 100.5 KiB
+1 B
100.4 KiB
+1 B
315.8 KiB
+12 B
86.7 KiB
-149 B
▁▁███████▃▃▃
react-start.rsbuild.full 103.4 KiB
+3 B
103.2 KiB
+3 B
325.0 KiB
+12 B
89.2 KiB
+24 B
▁▁███████▂▂▂
solid-start.minimal 46.3 KiB
-1 B
46.2 KiB
-2 B
137.9 KiB
+12 B
41.2 KiB
-19 B
▁▁██████████
solid-start.deferred-hydration 49.4 KiB
+1 B
46.3 KiB
+1 B
145.3 KiB
+12 B
44.0 KiB
-26 B
▁▁██▇███████
solid-start.full 51.4 KiB
+1 B
51.3 KiB
0 B
153.3 KiB
+12 B
45.5 KiB
-69 B
▁▁██████████
vue-start.minimal 65.7 KiB
-2 B
65.6 KiB
-2 B
189.2 KiB
+12 B
58.5 KiB
-57 B
▂▂███████▁▁▁
vue-start.full 69.6 KiB
-1 B
69.5 KiB
0 B
201.5 KiB
+12 B
61.8 KiB
+35 B
▁▁███████▁▁▁

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 Sep 11, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 9eeb94f

@nx-cloud nx-cloud 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.

Nx Cloud has identified a possible root cause for your failed CI:

We determined these E2E failures are environment-related and not caused by this PR. The parseHref change is a functionally identical performance optimization, and neither failing project is in the set of projects touched by the diff. The React test shows explicit ECONNRESET network errors from the test server, and the Solid test is a router-idle timeout — both pointing to infrastructure instability rather than a logic regression.

No code changes were suggested for this issue.

Trigger a rerun:

Rerun CI

Nx Cloud View detailed reasoning on Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

@codspeed-hq

codspeed-hq Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 5.91%

⚡ 1 improved benchmark
✅ 179 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ssr server-route (vue) 155.2 ms 146.5 ms +5.91%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/history-lazy-location-key (9eeb94f) with main (6494e75)

Open in CodSpeed

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.

1 participant