Skip to content

perf: reduce repeated Zod validation work - #8305

Open
LadyBluenotes wants to merge 12 commits into
mainfrom
perf/zod-validation-fast-path
Open

LadyBluenotes wants to merge 12 commits into
mainfrom
perf/zod-validation-fast-path

Conversation

@LadyBluenotes

@LadyBluenotes LadyBluenotes commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

🎯 Changes

Replaces #8301 with only the Zod validation work, based directly on main.

Compile the code-splitting grouping schema and check duplicates without flattening or copying arrays. Skip Zod parsing for Rspack modules without server-function metadata. Preserve grouping diagnostics and valid metadata parsing, including cloned output and unknown-key stripping.

Add behavior tests and Vitest benchmarks for grouping validation and metadata restoration.

✅ 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

  • Performance

    • Improved validation efficiency for code-splitting group configurations.
    • Reduced unnecessary processing when reading server-function metadata during builds.
  • Bug Fixes

    • Modules without server-function metadata are now handled safely during builds.
    • Code-splitting configurations continue to reject duplicate or invalid entries with clearer validation results.
  • Documentation

    • Updated Zod examples and usage guidance to reflect current import conventions.
  • Tests

    • Added coverage and performance benchmarks for validation and metadata handling.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: c8a27c51-6f88-4377-9af6-37562963f1d8

📥 Commits

Reviewing files that changed from the base of the PR and between 572e1ad and 0a079c5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • docs/router/how-to/share-search-params-across-routes.md

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

Walkthrough

The router plugin compiles split-group validation and detects duplicate nodes incrementally. The Start plugin tests guarded server-function metadata parsing. The change also standardizes Zod namespace imports, updates Seroval ranges, and adds benchmark scripts.

Changes: Plugin performance updates

Layer / File(s) Summary
Split groupings validation
packages/router-plugin/src/core/config.ts, packages/router-plugin/tests/split-groupings.*, packages/router-plugin/package.json
The schema uses compiled validation and incremental duplicate detection. Tests cover valid, invalid, and duplicate groupings. Benchmarks compare compiled and uncompiled parsing.
Server-function metadata parsing
packages/start-plugin-core/src/rsbuild/start-compiler-host.ts, packages/start-plugin-core/tests/rsbuild/start-compiler-metadata.*, packages/start-plugin-core/package.json
Tests cover absent, invalid, empty, and valid metadata. Benchmarks compare guarded and unguarded parsing.
Package and import alignment
.changeset/sweet-lions-share.md, packages/*/package.json, benchmarks/ssr/package.json, docs/**, e2e/**, examples/**
The changeset declares patch releases. Benchmark scripts are added. Seroval ranges are updated. Zod examples, fixtures, source files, and tests use namespace imports.

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

Merge Risk: Low · up to 0a079

The change improves validation and metadata parsing performance. One documentation page may lack a visible H1 if no generated title is provided, making this a minor follow-up rather than a functional blocker.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 5…
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.
Title check ✅ Passed The title clearly summarizes the primary change: reducing repeated Zod validation work through performance optimizations.
Description check ✅ Passed The description follows the repository template, explains the changes and motivation, completes all checklist items, and identifies the release impact with a changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/zod-validation-fast-path
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 9, 2026 •

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 16d9487

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 46s View ↗

☁️ Nx Cloud last updated this comment at 2026-10-24 22:10:27 UTC

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

6 package(s) bumped directly, 17 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-core 1.171.39 → 1.171.40 Changeset
@tanstack/router-plugin 1.168.48 → 1.168.49 Changeset
@tanstack/start-client-core 1.170.39 → 1.170.40 Changeset
@tanstack/start-plugin-core 1.171.55 → 1.171.56 Changeset
@tanstack/start-server-core 1.169.45 → 1.169.46 Changeset
@tanstack/start-static-server-functions 1.167.44 → 1.167.45 Changeset
@tanstack/react-router 1.170.46 → 1.170.47 Dependent
@tanstack/react-start 1.169.4 → 1.169.5 Dependent
@tanstack/react-start-client 1.168.44 → 1.168.45 Dependent
@tanstack/react-start-rsc 0.1.65 → 0.1.66 Dependent
@tanstack/react-start-server 1.167.52 → 1.167.53 Dependent
@tanstack/router-cli 1.167.46 → 1.167.47 Dependent
@tanstack/router-generator 1.167.46 → 1.167.47 Dependent
@tanstack/router-vite-plugin 1.167.48 → 1.167.49 Dependent
@tanstack/solid-router 1.170.43 → 1.170.44 Dependent
@tanstack/solid-start 1.169.4 → 1.169.5 Dependent
@tanstack/solid-start-client 1.168.42 → 1.168.43 Dependent
@tanstack/solid-start-server 1.167.50 → 1.167.51 Dependent
@tanstack/start-storage-context 1.167.41 → 1.167.42 Dependent
@tanstack/vue-router 1.170.42 → 1.170.43 Dependent
@tanstack/vue-start 1.169.4 → 1.169.5 Dependent
@tanstack/vue-start-client 1.167.45 → 1.167.46 Dependent
@tanstack/vue-start-server 1.167.50 → 1.167.51 Dependent

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 16d9487

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

This pull request does not affect bundle size in any measured scenario.

@codspeed

codspeed Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 37 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 194 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing perf/zod-validation-fast-path (16d9487) with main (6b9fe6d)2

Open in CodSpeed

Footnotes

  1. 3 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 (78caf5f) during the generation of this report, so 6b9fe6d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@LadyBluenotes
LadyBluenotes force-pushed the perf/zod-validation-fast-path branch from 572e1ad to 0a079c5 Compare September 10, 2026 16:48

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

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've reverted the seroval/seroval-plugins bump from ^1.6.2 to ^1.6.7 that was introduced on this branch (not present on main) but never mentioned in the PR's stated intent of reducing Zod validation work. This dependency handles promise/stream serialization for SSR, and it was the only plausible source of the tanstack-solid-start-e2e-serialization-adapters:test:e2e failure, where the "stream" test hung for 30s waiting on a suspended Await boundary to resolve. Restoring 1.6.2 removes the incidental regression risk while keeping the actual Zod code-splitting/metadata compilation changes intact.

Tip

✅ We verified this fix by re-running tanstack-solid-start-e2e-serialization-adapters:test:e2e.

Warning

The suggested diff is too large to display here, but you can view it on Nx Cloud ↗


Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally 5Syb-JdUf

Apply fix locally with your editor ↗   View interactive diff ↗



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

Main upgraded to Vitest 5 (#8723), which removed the top-level `bench`
export. Compare the uncompiled and compiled schemas with `bench.compare`
inside a test, matching how main migrated its other benchmarks.
Zod 4.6.2 keeps `undefined` in `.prefault()` output types when the inner
schema's output allows it (colinhacks/zod#6587). The Start options schemas
used `.optional().prefault({})`, so every parsed config section became
possibly undefined. `.prefault()` already accepts undefined input, so drop
the redundant `.optional()`; input types and parsed values are unchanged.
@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 16d9487

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@tanstack/router-core Patch
@tanstack/router-plugin Patch
@tanstack/start-client-core Patch
@tanstack/start-plugin-core Patch
@tanstack/start-server-core Patch
@tanstack/start-static-server-functions Patch
@tanstack/react-router Patch
@tanstack/react-start-client Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start-server Patch
@tanstack/router-generator Patch
@tanstack/solid-router Patch
@tanstack/solid-start-client Patch
@tanstack/solid-start-server Patch
@tanstack/start-storage-context Patch
@tanstack/vue-router Patch
@tanstack/vue-start-client Patch
@tanstack/vue-start-server Patch
@tanstack/router-vite-plugin Patch
@tanstack/react-start Patch
@tanstack/solid-start Patch
@tanstack/vue-start Patch
@tanstack/router-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

## Examples

```tsx
import { z } from 'zod'

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.

why were thoses imports changed?

@schiller-manuel

Copy link
Copy Markdown
Collaborator

please split this into separate PRs (e.g. one for zod upgrade, ...)

This branch has not been deployed

No deployments
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