Skip to content

fix(plugin): faster hashing#7338

Open
Sheraff wants to merge 6 commits into
mainfrom
fix-plugin-faster-hashing
Open

fix(plugin): faster hashing#7338
Sheraff wants to merge 6 commits into
mainfrom
fix-plugin-faster-hashing

Conversation

@Sheraff
Copy link
Copy Markdown
Collaborator

@Sheraff Sheraff commented May 4, 2026

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)

Screenshot 2026-05-04 at 20 59 20

Full benchmark (running full plugin with mocked filesystem)

Screenshot 2026-05-04 at 21 12 58 Screenshot 2026-05-04 at 21 12 50

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.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

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 0afbadb and 970a957.

📒 Files selected for processing (1)
  • docs/start/framework/react/guide/server-functions.md
✅ Files skipped from review due to trivial changes (1)
  • docs/start/framework/react/guide/server-functions.md

📝 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

Layer / File(s) Summary
Utility implementation
packages/router-utils/src/hash.ts, packages/router-utils/src/index.ts
Adds export function hash(algorithm, data, outputEncoding='hex') using crypto.hash when available and re-exports it from the package index.
Start plugin core update
packages/start-plugin-core/src/start-compiler/compiler.ts
Replaces production crypto.createHash('sha256')... with hash('sha256', entryId, 'hex') and adjusts imports accordingly.
Router generator update
packages/router-generator/src/generator.ts
Imports hash as hashString and replaces crypto.createHash('md5')... with hashString('md5', absPath, 'hex') for temp filename hashing.
Documentation examples
docs/start/framework/react/guide/isr.md, docs/start/framework/react/guide/server-functions.md
Examples updated to show `crypto.hash('md5'
Release note
.changeset/many-ads-smile.md
Patch bumps and a note that single-string hashes now prefer node:crypto's hash API.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 From chains of updates to one-call delight,
a helper hops in to make hashing light.
MD5, SHA1, SHA256 in a line,
one gentle call — the code feels fine. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing createHash().update().digest() with the faster crypto.hash() API across multiple packages for improved hashing performance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-plugin-faster-hashing

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

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 4, 2026

View your CI Pipeline Execution ↗ for commit 970a957

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:06 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🚀 Changeset Version Preview

3 package(s) bumped directly, 7 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-generator 1.167.9 → 1.167.10 Changeset
@tanstack/router-utils 1.162.1 → 1.162.2 Changeset
@tanstack/start-plugin-core 1.171.3 → 1.171.4 Changeset
@tanstack/react-start 1.168.10 → 1.168.11 Dependent
@tanstack/react-start-rsc 0.1.10 → 0.1.11 Dependent
@tanstack/router-cli 1.167.9 → 1.167.10 Dependent
@tanstack/router-plugin 1.168.10 → 1.168.11 Dependent
@tanstack/router-vite-plugin 1.167.10 → 1.167.11 Dependent
@tanstack/solid-start 1.168.10 → 1.168.11 Dependent
@tanstack/vue-start 1.168.10 → 1.168.11 Dependent

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

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.minimal 87.29 KiB 0 B (0.00%) 87.16 KiB 274.02 KiB 75.93 KiB █████▁▁▁▁▁▁
react-router.full 90.82 KiB 0 B (0.00%) 90.69 KiB 285.52 KiB 78.75 KiB ▆▆▆▆█▁▁▁▁▁▁
solid-router.minimal 35.53 KiB 0 B (0.00%) 35.41 KiB 106.33 KiB 31.95 KiB ▅████▁▁▁▁▁▁
solid-router.full 40.28 KiB 0 B (0.00%) 40.15 KiB 120.53 KiB 36.20 KiB ▁▂▂▂▃▄▄▄▄██
vue-router.minimal 53.33 KiB 0 B (0.00%) 53.20 KiB 151.46 KiB 47.88 KiB ▇▇▇▇▁▅▅▅▅██
vue-router.full 58.45 KiB 0 B (0.00%) 58.32 KiB 167.63 KiB 52.35 KiB ▆▆▆▆▁▆▆▆▆██
react-start.minimal 102.03 KiB 0 B (0.00%) 101.89 KiB 322.47 KiB 88.29 KiB ▁▄▄▄▃▆▆▆▆██
react-start.deferred-hydration 103.07 KiB 0 B (0.00%) 102.20 KiB 324.12 KiB 89.21 KiB ████▁▁▁▁▂▂
react-start.full 105.43 KiB 0 B (0.00%) 105.29 KiB 332.79 KiB 91.17 KiB ▆████▁▁▁▁▃▃
react-start.rsbuild.minimal 99.64 KiB 0 B (0.00%) 99.46 KiB 316.93 KiB 85.73 KiB ▆▆▆▆▁██████
react-start.rsbuild.full 102.93 KiB 0 B (0.00%) 102.76 KiB 327.34 KiB 88.59 KiB ▇▇▇▇▁▂▂▂▂██
solid-start.minimal 49.67 KiB 0 B (0.00%) 49.54 KiB 152.46 KiB 43.87 KiB ▁███▇▄▄▄▄▄▄
solid-start.deferred-hydration 53.74 KiB 0 B (0.00%) 50.40 KiB 161.00 KiB 47.74 KiB ███▇▁▁▁▁▁▁
solid-start.full 55.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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 4, 2026

More templates

@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@7338

commit: 970a957

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 `@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 ed3152a and 1b97a15.

📒 Files selected for processing (5)
  • .changeset/many-ads-smile.md
  • docs/start/framework/react/guide/isr.md
  • docs/start/framework/react/guide/server-functions.md
  • packages/router-generator/src/generator.ts
  • packages/start-plugin-core/src/start-compiler/compiler.ts

Comment thread docs/start/framework/react/guide/server-functions.md
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 4, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing fix-plugin-faster-hashing (970a957) with main (b47b338)2

Open in CodSpeed

Footnotes

  1. 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.

  2. No successful run was found on main (31f5684) during the generation of this report, so b47b338 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

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

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 exports Map variable in extractModuleInfo to namedExports to fix the five import/no-commonjs ESLint errors introduced when the PR removed the blanket /* eslint-disable import/no-commonjs */ comment from compiler.ts. The rule was incorrectly flagging exports.set(...) calls as CommonJS patterns because the identifier exports is reserved by the rule, even though the variable is a plain local Map<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)

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally 69ER-lBKK

Apply fix locally with your editor ↗   View interactive diff ↗



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

}
if (!functionId) {
functionId = crypto.createHash('sha256').update(entryId).digest('hex')
functionId = hash('sha256', entryId, 'hex')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 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.

2 participants