fix: compile directive replacements #5450
main fromrefs/pull/5450/head·merged by schiller-manuel(GitHub profile, opens in a new tab) Summary by CodeRabbit#
New Features
- Improved handling when directives are split into separate parameter exports, including conditional default-export support.
Bug Fixes
- More robust export transformation to preserve declarations and handle varied export forms without breaking generated output.
Refactor
- Directive compilation now propagates split-param context through processing and uses safer AST-based export manipulation.
Tests
- Added tests for server functions referencing exported values (including a public schema) and updated snapshots for aliased export naming.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: directive-functions-plugin
View your CI Pipeline Execution ↗ for commit c67f4ded4bbc83148f70ed9338e19a87b2533201
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 52s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-12 05:33:49UTCMore templates
- tanstack-router-solid-example-basic
- 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-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
- 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-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- 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/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5450@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5450@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5450@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5450@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5450@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5450@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5450@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5450@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5450@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5450@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5450@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5450@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5450@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5450@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5450@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5450@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5450@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5450@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5450@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5450@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5450@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5450@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5450@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5450@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5450@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5450@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5450@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5450@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5450@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5450@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5450@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5450@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5450@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5450commit:
c67f4deActionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 1a74e31cb89d39c130cb300a0449696544a9daf9 and 80c9ad2f8fdf1c33be749a810a12c1ddb20ca586.
📒 Files selected for processing (1)
packages/directive-functions-plugin/tests/compiler.test.ts(6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/directive-functions-plugin/tests/compiler.test.ts
🧬 Code graph analysis (1)
packages/directive-functions-plugin/tests/compiler.test.ts (1)
packages/directive-functions-plugin/src/compilers.ts (1)
compileDirectives(58-118)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test
@@ -903,3 +907,21 @@903907 export { asyncGenerator_1 };"904908 `)905909 })910+911+ test('server function references exported value', () => {912+ const code = `913+914+ import z from "zod";915+916+ export const zExampleSchema = z.object({917+ name: z.string(),918+ age: z.number(),919+ });920+921+ export const namedFunction = createServerFn(() => {922+ 'use server'923+ zExampleSchema.safeParese({ name: 'test', age: 123 })924+ return 'hello'925+ })926+ `927+⚠️ Potential issue | 🟠 Major
Fix typo when invoking zod schema
safePareseis misspelled—this should callsafeParse. As written, the generated server bundle would throw at runtime if executed. Please correct the invocation.- zExampleSchema.safeParese({ name: 'test', age: 123 }) + zExampleSchema.safeParse({ name: 'test', age: 123 })📝 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.
'use server' zExampleSchema.safeParse({ name: 'test', age: 123 }) return 'hello' }) `🤖 Prompt for AI Agents
In packages/directive-functions-plugin/tests/compiler.test.ts around lines 922 to 927, the test calls zExampleSchema.safeParese which is misspelled; change the invocation to zExampleSchema.safeParse to fix the typo so the generated server bundle won't throw at runtime, and run tests to confirm no other references to the misspelling remain.✅ Addressed in commit c67f4de
Sign in to join this conversation.
Walkthrough#
Propagates an isDirectiveSplitParam flag through directive compilation, extends compileDirective to accept compileDirectiveOpts, updates export-swapping to handle named and conditional default exports, refactors safeRemoveExports to return/replace AST nodes, and adds tests for server functions referencing exported values.
Changes#
packages/directive-functions-plugin/src/compilers.tsisDirectiveSplitParamfromcompileDirectivesintofindDirectivesandcompileDirectivevia acompileDirectiveOptsobject; updatecompileDirectivesignature and call sites; adjust export-swapping logic to support named and conditional default exports when flag is set; refactorsafeRemoveExportsto return/replace AST nodes (no path-based removals); update helper types and wiring.packages/directive-functions-plugin/tests/compiler.test.tsSequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~60 minutes
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 80c9ad2f8fdf1c33be749a810a12c1ddb20ca586 and c67f4ded4bbc83148f70ed9338e19a87b2533201.
📒 Files selected for processing (1)
packages/directive-functions-plugin/tests/compiler.test.ts(6 hunks)🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/directive-functions-plugin/tests/compiler.test.ts🧬 Code graph analysis (1)
packages/directive-functions-plugin/tests/compiler.test.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
Comment `@coderabbitai help` to get the list of available commands and usage tips.