fix(plugin): faster hashing #7338
main fromfix-plugin-faster-hashing·opened Yagiz said it was faster, let's see.
crypto.hash(algorithm, data[, options])
nodejs docs
Added in: v21.7.0, v20.12.0
History: v25.4.0 | This API is no longer experimental.
Benchmarks#
Isolation micro-benchmark (just comparing node native modules)
Full benchmark (running full plugin with mocked filesystem)
Summary by CodeRabbit#
- Chores
- Switched internal hash computation to use Node.js’ modern hashing API across packages and build tooling.
- Added and published a reusable hash utility in the router utilities package.
- Documentation
- Updated examples and guides (ISR ETag generation and server-function ID examples) to reflect the new hashing approach.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsdocumentation
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-generator
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
View your CI Pipeline Execution ↗ for commit 970a9579d87eefa7d2aee6dbe8bbe08d94d6c79c
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 7m 49s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2m 19s View ↗
☁️ Nx Cloud last updated this comment at
2026-05-22 18:52:06UTC🚀 Changeset Version Preview#
3 package(s) bumped directly, 7 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/router-generator1.167.9 → 1.167.10 Changeset @tanstack/router-utils1.162.1 → 1.162.2 Changeset @tanstack/start-plugin-core1.171.3 → 1.171.4 Changeset @tanstack/react-start1.168.10 → 1.168.11 Dependent @tanstack/react-start-rsc0.1.10 → 0.1.11 Dependent @tanstack/router-cli1.167.9 → 1.167.10 Dependent @tanstack/router-plugin1.168.10 → 1.168.11 Dependent @tanstack/router-vite-plugin1.167.10 → 1.167.11 Dependent @tanstack/solid-start1.168.10 → 1.168.11 Dependent @tanstack/vue-start1.168.10 → 1.168.11 Dependent Bundle Size Benchmarks#
- Commit:
dd246ca8bcf3 - Measured at:
2026-05-22T18:45:15.116Z - Baseline source:
history:b47b338d15de - Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend react-router.minimal87.29 KiB 0 B (0.00%) 87.16 KiB 274.02 KiB 75.93 KiB █████▁▁▁▁▁▁ react-router.full90.82 KiB 0 B (0.00%) 90.69 KiB 285.52 KiB 78.75 KiB ▆▆▆▆█▁▁▁▁▁▁ solid-router.minimal35.53 KiB 0 B (0.00%) 35.41 KiB 106.33 KiB 31.95 KiB ▅████▁▁▁▁▁▁ solid-router.full40.28 KiB 0 B (0.00%) 40.15 KiB 120.53 KiB 36.20 KiB ▁▂▂▂▃▄▄▄▄██ vue-router.minimal53.33 KiB 0 B (0.00%) 53.20 KiB 151.46 KiB 47.88 KiB ▇▇▇▇▁▅▅▅▅██ vue-router.full58.45 KiB 0 B (0.00%) 58.32 KiB 167.63 KiB 52.35 KiB ▆▆▆▆▁▆▆▆▆██ react-start.minimal102.03 KiB 0 B (0.00%) 101.89 KiB 322.47 KiB 88.29 KiB ▁▄▄▄▃▆▆▆▆██ react-start.deferred-hydration103.07 KiB 0 B (0.00%) 102.20 KiB 324.12 KiB 89.21 KiB ████▁▁▁▁▂▂ react-start.full105.43 KiB 0 B (0.00%) 105.29 KiB 332.79 KiB 91.17 KiB ▆████▁▁▁▁▃▃ react-start.rsbuild.minimal99.64 KiB 0 B (0.00%) 99.46 KiB 316.93 KiB 85.73 KiB ▆▆▆▆▁██████ react-start.rsbuild.full102.93 KiB 0 B (0.00%) 102.76 KiB 327.34 KiB 88.59 KiB ▇▇▇▇▁▂▂▂▂██ solid-start.minimal49.67 KiB 0 B (0.00%) 49.54 KiB 152.46 KiB 43.87 KiB ▁███▇▄▄▄▄▄▄ solid-start.deferred-hydration53.74 KiB 0 B (0.00%) 50.40 KiB 161.00 KiB 47.74 KiB ███▇▁▁▁▁▁▁ solid-start.full55.46 KiB 0 B (0.00%) 55.33 KiB 169.35 KiB 48.80 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.
- Commit:
More templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@7338@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7338@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7338@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@7338@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7338@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@7338@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@7338@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7338@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@7338@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@7338@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@7338@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@7338@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@7338@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@7338@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@7338@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@7338@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@7338@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@7338@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7338@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@7338@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7338@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@7338@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7338@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7338@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@7338@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@7338@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@7338@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@7338@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7338@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@7338@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@7338@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7338@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@7338@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@7338@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7338@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@7338@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7338@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7338@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@7338@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@7338@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@7338@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@7338commit:
970a957Actionable 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 `@docs/start/framework/react/guide/server-functions.md`: - Line 382: The example calls crypto.hash in the snippet but never imports crypto; add an explicit import for Node's crypto module at the top of the example (e.g. import or require the 'crypto' module) so the return statement using crypto.hash(`${filename}--${functionName}`,'hex') is runnable; update the snippet surrounding the function that returns crypto.hash(...) to include that import.🪄 Autofix (Beta)
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
Run ID:
121c8622-6a8f-47eb-9615-e026d715d414📥 Commits
Reviewing files that changed from the base of the PR and between ed3152af205e00d99a262c0e283f7989894219ab and 1b97a1525dd9db2e49537ce4d806935455c3a9a4.
📒 Files selected for processing (5)
.changeset/many-ads-smile.mddocs/start/framework/react/guide/isr.mddocs/start/framework/react/guide/server-functions.mdpackages/router-generator/src/generator.tspackages/start-plugin-core/src/start-compiler/compiler.ts
Resolvedby Sheraff(GitHub profile, opens in a new tab)@@ -379,7 +379,4 @@379379 serverFns: {380380 generateFunctionId: ({ filename, functionName }) => {381381 // Return a custom ID string382- return crypto383- .createHash('sha1')384- .update(`${filename}--${functionName}`)385- .digest('hex')382+ return crypto.hash('sha1', `${filename}--${functionName}`, 'hex')⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Example snippet uses
cryptowithout importing it.Line 382 references
crypto, but the snippet does not import it, so the example is not copy-paste runnable.Proposed fix
// vite.config.ts +import crypto from 'node:crypto' import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { tanstackStart } from '@tanstack/react-start/plugin/vite'📝 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.
// vite.config.ts import crypto from 'node:crypto' import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { tanstackStart } from '@tanstack/react-start/plugin/vite'🤖 Prompt for 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. In `@docs/start/framework/react/guide/server-functions.md` at line 382, The example calls crypto.hash in the snippet but never imports crypto; add an explicit import for Node's crypto module at the top of the example (e.g. import or require the 'crypto' module) so the return statement using crypto.hash(`${filename}--${functionName}`,'hex') is runnable; update the snippet surrounding the function that returns crypto.hash(...) to include that import.Merging this PR will not alter performance#
✅ 4untouched benchmarks⏩ 2skipped benchmarks1
Comparingfix-plugin-faster-hashing(970a957) withmain(b47b338)[^unexpected-base]Footnotes#
-
2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-utils
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:#
We rename the local
exportsMap variable inextractModuleInfotonamedExportsto fix the fiveimport/no-commonjsESLint errors introduced when the PR removed the blanket/* eslint-disable import/no-commonjs */comment fromcompiler.ts. The rule was incorrectly flaggingexports.set(...)calls as CommonJS patterns because the identifierexportsis reserved by the rule, even though the variable is a plain localMap<string, string>.Tip
✅ We verified this fix by re-running
@tanstack/start-plugin-core:test:eslint,tanstack-router-e2e-vue-basepath-file-based:test:e2e.Suggested Fix changes
diff --git a/packages/start-plugin-core/src/start-compiler/compiler.ts b/packages/start-plugin-core/src/start-compiler/compiler.ts index ed75e5be..f86a1b84 100644 --- a/packages/start-plugin-core/src/start-compiler/compiler.ts +++ b/packages/start-plugin-core/src/start-compiler/compiler.ts @@ -764,7 +764,7 @@ export class StartCompiler { id: string, ): ModuleInfo { const bindings = new Map<string, Binding>() - const exports = new Map<string, string>() + const namedExports = new Map<string, string>() const reExportAllSources: Array<string> = [] // we are only interested in top-level bindings, hence we don't traverse the AST @@ -807,7 +807,7 @@ export class StartCompiler { if (t.isVariableDeclaration(node.declaration)) { for (const d of node.declaration.declarations) { if (t.isIdentifier(d.id)) { - exports.set(d.id.name, d.id.name) + namedExports.set(d.id.name, d.id.name) bindings.set(d.id.name, { type: 'var', init: d.init ?? null }) } } @@ -815,7 +815,7 @@ export class StartCompiler { } for (const sp of node.specifiers) { if (t.isExportNamespaceSpecifier(sp)) { - exports.set(sp.exported.name, sp.exported.name) + namedExports.set(sp.exported.name, sp.exported.name) } // export { local as exported } else if (t.isExportSpecifier(sp)) { @@ -823,7 +823,7 @@ export class StartCompiler { const exported = t.isIdentifier(sp.exported) ? sp.exported.name : sp.exported.value - exports.set(exported, local) + namedExports.set(exported, local) // When re-exporting from another module (export { foo } from './module'), // create an import binding so the server function can be resolved @@ -839,11 +839,11 @@ export class StartCompiler { } else if (t.isExportDefaultDeclaration(node)) { const d = node.declaration if (t.isIdentifier(d)) { - exports.set('default', d.name) + namedExports.set('default', d.name) } else { const synth = '__default_export__' bindings.set(synth, { type: 'var', init: d as t.Expression }) - exports.set('default', synth) + namedExports.set('default', synth) } } else if (t.isExportAllDeclaration(node)) { // Handle `export * from './module'` syntax @@ -855,7 +855,7 @@ export class StartCompiler { const info: ModuleInfo = { id, bindings, - exports, + exports: namedExports, reExportAllSources, } this.moduleCache.set(id, info)
Or Apply changes locally with:
Apply fix locally with your editor ↗ View interactive diff ↗npx nx-cloud apply-locally 69ER-lBKK
🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)- packages/start-plugin-core/src/start-compiler/compiler.ts line 635@@ -600,4 +599,4 @@600599 })601600 }602601 if (!functionId) {603- functionId = crypto.createHash('sha256').update(entryId).digest('hex')602+ functionId = hash('sha256', entryId, 'hex')
Since we're on a roll with modernizing things, what do you think about
functionId ??= hash('sha256', entryId, 'hex')? I have a personal vendetta against the ! operator it looks like a tiny person shouting at my code 😂
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
56e5731f-533b-46f2-9329-a52284696268📥 Commits
Reviewing files that changed from the base of the PR and between 0afbadb494866bf685e90ae2fe761318f052433c and 970a9579d87eefa7d2aee6dbe8bbe08d94d6c79c.
📒 Files selected for processing (1)
docs/start/framework/react/guide/server-functions.md✅ Files skipped from review due to trivial changes (1)
📝 Walkthrough
Walkthrough#
Replaces manual crypto.createHash(...).update(...).digest(...) usage with a new exported hash(algorithm, data, encoding) helper that prefers Node’s crypto.hash API; callers in start-plugin-core and router-generator plus docs/examples and the changeset are updated to use it.
Changes#
Hash API Modernization
packages/router-utils/src/hash.ts,packages/router-utils/src/index.tsexport function hash(algorithm, data, outputEncoding='hex')usingcrypto.hashwhen available and re-exports it from the package index.packages/start-plugin-core/src/start-compiler/compiler.tscrypto.createHash('sha256')...withhash('sha256', entryId, 'hex')and adjusts imports accordingly.packages/router-generator/src/generator.tshash as hashStringand replacescrypto.createHash('md5')...withhashString('md5', absPath, 'hex')for temp filename hashing.docs/start/framework/react/guide/isr.md,docs/start/framework/react/guide/server-functions.md.changeset/many-ads-smile.mdnode:crypto'shashAPI.Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~12 minutes
Poem#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.