fix: correct compiler plugin order, only handle createMiddleware in a … #6163
main fromrefs/pull/6163/head·merged by schiller-manuel(GitHub profile, opens in a new tab) …single plugin
fixes #5381
Summary by CodeRabbit#
Refactor
- Reordered plugin execution sequence to improve server function compilation and optimization.
Tests
- Removed deprecated test suites and snapshots related to middleware transformation handling.
- Updated test infrastructure to reflect changes in build-time behavior.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
View your CI Pipeline Execution ↗ for commit 2de05a0c9c5dc82bcc42789382d78697497d9714
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 9m 54s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 20s View ↗
☁️ Nx Cloud last updated this comment at
2025-12-20 22:49:40UTCMore 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-rsc
- 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-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/router/@tanstack/arktype-adapter@6163@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@6163@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6163@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6163@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6163@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6163@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6163@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6163@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6163@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6163@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6163@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6163@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6163@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6163@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6163@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6163@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6163@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6163@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6163@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6163@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@6163@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6163@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6163@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6163@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6163@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6163@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6163@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6163@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6163@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6163@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6163@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6163@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6163@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6163@tanstack/vue-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6163@tanstack/vue-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6163@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6163@tanstack/vue-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6163@tanstack/vue-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6163@tanstack/vue-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6163@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6163commit:
2de05a0Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts (1)
5-13: Consider narrowing the type signature or documenting the constraint.The function accepts
env: 'client' | 'server'but immediately throws ifenv === 'server'. While this defensive guard is appropriate for catching misuse, consider either:- Narrowing the type to
env: 'client'if this function should never receive a server env - Adding a JSDoc comment explaining why server is rejected
This would make the API contract clearer to callers.
🔎 Option 1: Narrow the type
export function handleCreateMiddleware( path: babel.NodePath<t.CallExpression>, opts: { - env: 'client' | 'server' + env: 'client' }, ) { - if (opts.env === 'server') { - throw new Error('handleCreateMiddleware should not be called on the server') - }packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts (1)
10-14: Consider whether to preserve the dual-environment type signature.The
compilehelper still acceptsenv: 'client' | 'server', but after this change, only'client'is used in the tests. This isn't necessarily wrong—keeping the flexible signature allows for easier addition of server-side tests in the future if needed.However, if middleware compilation is definitively client-only (per line 53's comment), you might consider either:
- Adding a clarifying comment explaining why the server option remains, or
- Narrowing the type to
env: 'client'to match the actual usage
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 8a205211c51751a4a84db47935fd53df4ef99387 and 2de05a0c9c5dc82bcc42789382d78697497d9714.
📒 Files selected for processing (26)
e2e/react-start/server-functions/src/routeTree.gen.ts(11 hunks)e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsx(1 hunks)e2e/react-start/server-functions/tests/server-functions.spec.ts(0 hunks)packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts(2 hunks)packages/start-plugin-core/src/plugin.ts(2 hunks)packages/start-plugin-core/src/start-compiler-plugin/compilers.ts(0 hunks)packages/start-plugin-core/src/start-compiler-plugin/constants.ts(0 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts(1 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/create-function-middleware.ts(0 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsx(1 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsx(1 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsx(1 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareValidator.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/server/createStart.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/createMiddleware.test.ts(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/createMiddlewareDestructured.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/createMiddlewareDestructuredRename.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/createMiddlewareStarImport.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/factory.ts(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/create-function-middleware.ts(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareDestructured.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareDestructuredRename.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareStarImport.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareValidator.tsx(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/factory.ts(0 hunks)packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/test-files/factory.ts(0 hunks)
💤 Files with no reviewable changes (18)
- packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareValidator.tsx
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareValidator.tsx
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/create-function-middleware.ts
- packages/start-plugin-core/src/start-compiler-plugin/compilers.ts
- packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/server/createStart.tsx
- packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/create-function-middleware.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/createMiddlewareDestructuredRename.tsx
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/createMiddlewareStarImport.tsx
- e2e/react-start/server-functions/tests/server-functions.spec.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/createMiddleware.test.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/factory.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/createMiddlewareDestructured.tsx
- packages/start-plugin-core/src/start-compiler-plugin/constants.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/test-files/factory.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/factory.ts
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareStarImport.tsx
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareDestructured.tsx
- packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/createMiddlewareDestructuredRename.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript strict mode with extensive type safety for all code
Files:
e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsxpackages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsxpackages/start-plugin-core/src/plugin.tse2e/react-start/server-functions/src/routeTree.gen.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Implement ESLint rules for router best practices using the ESLint plugin router
Files:
e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsxpackages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsxpackages/start-plugin-core/src/plugin.tse2e/react-start/server-functions/src/routeTree.gen.ts
🧠 Learnings (4)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsxe2e/react-start/server-functions/src/routeTree.gen.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsxpackages/start-plugin-core/src/plugin.ts
📚 Learning: 2025-12-16T02:59:11.506Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 6104 File: packages/start-plugin-core/tests/split-exports-plugin/snapshots/exports/functionExports.ts:1-1 Timestamp: 2025-12-16T02:59:11.506Z Learning: In transformation test snapshots (e.g., split-exports plugin), comments at the top of snapshot files often describe the original input scenario being tested (e.g., "Multiple function exports") rather than the transformed output in the snapshot itself. This helps document what transformation is being validated.Applied to files:
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsxpackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsx
📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
e2e/react-start/server-functions/src/routeTree.gen.ts
🧬 Code graph analysis (4)
e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsx (2)
packages/start-client-core/src/index.tsx (1)
createClientOnlyFn(12-12)
packages/router-core/src/ssr/tsrScript.ts (1)
p(16-18)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts (1)
packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts (1)
compile(204-282)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsx (6)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsx (4)
withUseServer(2-4)withoutUseServer(5-7)withVariable(8-10)withZodValidator(11-13)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsx (4)
withUseServer(2-4)withoutUseServer(5-7)withVariable(8-10)withZodValidator(11-13)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareValidator.tsx (1)
withUseServer(2-4)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/test-files/createMiddlewareDestructuredRename.tsx (4)
withUseServer(4-12)withoutUseServer(14-22)withVariable(24-26)withZodValidator(45-51)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/test-files/createMiddlewareDestructured.tsx (4)
withUseServer(4-12)withoutUseServer(14-22)withVariable(24-26)withZodValidator(45-51)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/test-files/createMiddlewareStarImport.tsx (4)
withUseServer(4-13)withoutUseServer(15-23)withVariable(25-27)withZodValidator(46-52)
packages/start-plugin-core/src/plugin.ts (1)
packages/start-plugin-core/src/start-compiler-plugin/plugin.ts (1)
startCompilerPlugin(69-111)
⏰ 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). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (13)
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructuredRename.tsx (1)
1-13: LGTM! Test snapshot correctly demonstrates renamed import transformation.This snapshot file properly validates that the plugin handles
createMiddlewarewhen imported with a rename (as middlewareFn). The identical configurations across all four exports are intentional for testing that the transformation uniformly processes different middleware instances under the renamed import pattern.packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts (2)
51-56: LGTM!The simplified logic correctly removes the validator call expression by replacing it with the callee's object. The
isMemberExpressioncheck provides appropriate type safety.
63-70: LGTM!The conditional properly checks for the existence of both
callExpressionPaths.serverandserverFnPath.nodebefore performing the transformation. The simplification is valid since the early guard ensures this only executes in client context.packages/start-plugin-core/src/plugin.ts (1)
388-434: Excellent fix with clear documentation!The plugin reordering correctly addresses issue #5381. The comment clearly explains the critical ordering requirement:
createServerFnPlugininjects'use server'directiveTanStackServerFnPluginextracts and registers functions in manifeststartCompilerPluginruns DCE last
This ensures server functions referenced inside
createClientOnlyFncallbacks are registered in the manifest before DCE can remove them. The detailed comment will help future maintainers understand why this order matters.packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareDestructured.tsx (1)
1-13: LGTM! Client-side transformation snapshot is correct.This test snapshot correctly demonstrates the expected client-side output after the plugin processes
createMiddlewarecalls. Comparing to the test input file, the.server()method chains and their implementations have been properly stripped, leaving only the basecreateMiddleware({ id: 'test' })calls—which is the expected behavior for client bundles.The snapshot aligns with the PR objective of consolidating createMiddleware handling in a single plugin and validates that the plugin ordering fix maintains correct transformation behavior.
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/createMiddlewareStarImport.tsx (1)
1-13: LGTM! Valid test snapshot documenting star import transformation.This snapshot correctly represents the expected client-side output after the plugin transforms
createMiddlewarecalls using a star import pattern. The identical configurations across all four exports (id: 'test') are intentional, as this tests the transformation behavior rather than runtime logic. The filename clearly describes the test scenario being validated.Based on learnings, transformation test snapshots document what transformation is being validated and serve as fixtures for verifying plugin output.
e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsx (5)
1-3: LGTM: Imports are appropriate for the test case.The imports correctly include the necessary TanStack Start primitives (
createServerFn,createClientOnlyFn) and Router utilities to demonstrate the fix for issue #5381.
5-8: LGTM: Server function definition is correct.The server function uses the standard
createServerFn().handler()pattern and returns a simple string, which is appropriate for this test scenario.
10-18: LGTM: Core test case correctly demonstrates the fix.The client-only function properly calls the server function and transforms its result. The inline comment (lines 11-14) provides valuable context about the compilation order issue that this PR addresses, making this an excellent regression test.
20-22: LGTM: Route definition follows standard patterns.The file route is correctly configured with an appropriate path name that describes the test scenario.
24-63: LGTM: Test component is well-structured.The component implementation includes:
- Proper error handling with try/catch
- Clear test-ids for e2e test assertions
- Expected result display that correctly matches the composed output from both functions
- Conditional rendering of result and error states
This provides a robust test case for the compilation order fix.
e2e/react-start/server-functions/src/routeTree.gen.ts (1)
1-705: Autogenerated file - changes are expected.This
routeTree.gen.tsfile is autogenerated by TanStack Router and correctly includes the new/server-fn-in-client-only-fnroute across all type declarations, route mappings, and the route tree structure. No manual modifications are needed.Based on learnings, autogenerated route tree files should not be manually modified or have issues flagged.
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts (1)
53-60: The comment "Middleware compilation only happens on the client" is verified and correct.The
handleCreateMiddlewarefunction explicitly throws an error if called withenv: 'server', confirming that middleware processing is intentionally client-only. Server-side test removal is appropriate since server environment processing is unsupported by design.However, consider whether the compiler should guard against passing server env at the call site (compiler.ts line 270-271) to provide clearer error messaging, rather than relying on the handler rejection. This would shift the error earlier in the compilation pipeline.
- Narrowing the type to
schiller-manuel(GitHub profile, opens in a new tab) changed the title
Sign in to join this conversation.
Walkthrough#
This PR introduces support for calling server functions from within client-only functions by restructuring the build-time server function and middleware plugin pipeline. It adds a new test route demonstrating this pattern, guards against server-side execution of certain transformations, reorders plugin execution to perform server function transformations before dead-code elimination, and removes createMiddleware transformation logic from the start compiler plugin in favor of concentrating that responsibility in the create-server-fn plugin.
Changes#
e2e/react-start/server-functions/src/routeTree.gen.ts/server-fn-in-client-only-fn, updates FileRoutesByFullPath, FileRoutesByTo, FileRoutesById, and module declarations to include the new route.e2e/react-start/server-functions/src/routes/server-fn-in-client-only-fn.tsxe2e/react-start/server-functions/tests/server-functions.spec.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/src/plugin.tspackages/start-plugin-core/src/start-compiler-plugin/compilers.tspackages/start-plugin-core/src/start-compiler-plugin/constants.ts'createMiddleware'from thetransformFuncsconstant array, reducing supported transform functions.packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts./snapshots/client/${filename}.packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/client/*create-function-middleware.tsremoves unused import;createMiddlewareDestructured.tsx,createMiddlewareDestructuredRename.tsx,createMiddlewareStarImport.tsxadded as new client snapshots;createMiddlewareValidator.tsxremoves unused zod import.packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/snapshots/server/createStart.tsxpackages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/createMiddleware.test.tspackages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/client/*packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/snapshots/server/*packages/start-plugin-core/tests/createMiddleware-start-compiler-plugin/test-files/factory.tsEstimated code review effort#
🎯 4 (Complex) | ⏱️ ~45 minutes
plugin.ts): requires understanding the rationale for reordering and impact on build-time manifest generation and dead-code elimination phases.handleCreateMiddleware.ts): the guard and removal of environment-specific conditionals need verification to ensure server-side safety and correct client-side behavior.compilers.ts,constants.ts): consolidation of createMiddleware handling away from start-compiler-plugin requires ensuring no orphaned references remain.Possibly related PRs#
packages/start-plugin-core/src/start-compiler-plugin/compilers.tsto adjust how createMiddleware identifiers are registered and handled.Suggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (2 warnings)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.