Skip to content

fix(router-generator): avoid zod function schema for routeTreeFileFooter#6848

Open
CaliLuke wants to merge 1 commit intoTanStack:mainfrom
CaliLuke:lucacandela/autok-128-router-generator-zod4
Open

fix(router-generator): avoid zod function schema for routeTreeFileFooter#6848
CaliLuke wants to merge 1 commit intoTanStack:mainfrom
CaliLuke:lucacandela/autok-128-router-generator-zod4

Conversation

@CaliLuke
Copy link

@CaliLuke CaliLuke commented Mar 7, 2026

Summary

Replace the routeTreeFileFooter function schema in @tanstack/router-generator with a cross-version callable guard.

The current config schema uses z.function().returns(z.array(z.string())), which is a Zod v3-style function schema API and causes compatibility issues for consumers on Zod v4 in this package context.

This change narrows the fix to the actual runtime requirement for routeTreeFileFooter: it only needs to accept either:

  • string[]
  • a callable that returns string[]

At runtime, the generator only distinguishes between those two shapes:

  • Array.isArray(config.routeTreeFileFooter)
  • otherwise invoke config.routeTreeFileFooter()

So a typed callable guard is sufficient here and avoids consumer-side patching of installed package files.

Changes

  • replace z.function().returns(z.array(z.string())) with z.custom<() => string[]>((value) => typeof value === 'function')
  • add config tests covering both array and function forms of routeTreeFileFooter

Why

A downstream consumer currently has to patch the published package after install to keep their app working with Zod v4. This change removes the need for that workaround in the router-generator config surface.

Verification

Ran locally:

  • pnpm --dir packages/router-generator exec vitest run tests/config.test.ts
  • pnpm --dir packages/router-generator test:types
  • pnpm --dir packages/router-generator test:eslint
  • pnpm --dir packages/router-generator test:build

All passed.

Summary by CodeRabbit

  • New Features

    • The routeTreeFileFooter configuration parameter now accepts both static string arrays and factory functions that dynamically return string arrays, providing greater flexibility in defining route tree footer content at configuration time.
  • Tests

    • Added test coverage to verify correct behavior when routeTreeFileFooter is provided as either a static array or a factory function, ensuring proper value preservation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 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: 3bf8ffa8-1a7f-448b-bf90-0e2c8051644a

📥 Commits

Reviewing files that changed from the base of the PR and between 4ea2a62 and c96cfdb.

📒 Files selected for processing (2)
  • packages/router-generator/src/config.ts
  • packages/router-generator/tests/config.test.ts

📝 Walkthrough

Walkthrough

The pull request introduces schema validation support for routeTreeFileFooter to accept both string arrays and factory functions that return string arrays. A new internal validation schema is added alongside two test cases verifying the updated behavior.

Changes

Cohort / File(s) Summary
Schema Validation
packages/router-generator/src/config.ts
Added internal stringArrayFactorySchema to validate factory functions returning string arrays; updated routeTreeFileFooter union to accept both direct arrays and factory functions.
Test Coverage
packages/router-generator/tests/config.test.ts
Added two test cases verifying getConfig accepts routeTreeFileFooter as a factory function and direct array, with proper value preservation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A schema learns to dance and bend,
Functions and arrays now blend,
Factories spin their clever way,
Validation flourishes today!
✨ One more path, one more friend.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing a Zod function schema with a custom guard for routeTreeFileFooter, which is the primary objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

Bundle Size Benchmarks

  • Commit: 4ea2a62787d0
  • Measured at: 2026-03-07T17:35:16.204Z
  • Baseline source: history:4ea2a62787d0
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 86.84 KiB 0 B (0.00%) 273.33 KiB 75.44 KiB ▁▁▁▁▁██████
react-router.full 89.88 KiB 0 B (0.00%) 283.67 KiB 78.18 KiB ▁▁▁▁▁██████
solid-router.minimal 36.17 KiB 0 B (0.00%) 108.44 KiB 32.49 KiB ▁▁▁▁▁██████
solid-router.full 40.50 KiB 0 B (0.00%) 121.49 KiB 36.40 KiB ▁▁▁▁▁██████
vue-router.minimal 52.03 KiB 0 B (0.00%) 148.42 KiB 46.71 KiB ▁▁▁▁▁██████
vue-router.full 56.85 KiB 0 B (0.00%) 164.01 KiB 51.04 KiB ▁▁▁▁▁██████
react-start.minimal 99.40 KiB 0 B (0.00%) 312.48 KiB 85.98 KiB ▁▁▁▁▁██████
react-start.full 102.78 KiB 0 B (0.00%) 322.29 KiB 88.82 KiB ▁▁▁▁▁██████
solid-start.minimal 48.49 KiB 0 B (0.00%) 146.03 KiB 42.85 KiB ▁▁▁▁▁██████
solid-start.full 53.96 KiB 0 B (0.00%) 161.98 KiB 47.51 KiB ▁▁▁▁▁██████

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

@nx-cloud
Copy link

nx-cloud bot commented Mar 8, 2026

View your CI Pipeline Execution ↗ for commit c96cfdb

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

☁️ Nx Cloud last updated this comment at 2026-03-08 08:19:46 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 8, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: a3356e2

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 8, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing CaliLuke:lucacandela/autok-128-router-generator-zod4 (c96cfdb) with main (4ea2a62)

Open in CodSpeed

@CaliLuke
Copy link
Author

@tannerlinsley anything else I need to do to get this patch upstreamed?

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