fix: trace nested server function factory re-export chain #6166
main fromrefs/pull/6166/head·merged by schiller-manuel(GitHub profile, opens in a new tab) also implement perf optimizations
Summary by CodeRabbit#
New Features
- Added support for deeper nested re-export chains for server-side functions, enabling middleware and context to flow through multi-level exports.
Improvements
- Compiler and resolution performance optimizations with parallel candidate resolution and faster lookup paths.
- Internal API and rewrite logic streamlined for more reliable transformation.
Tests
- New end-to-end and unit tests covering nested re-exports and both fast/slow resolution paths.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
🤖 Nx Cloud AI Fix Eligible#
To disable these notifications, a workspace admin can disable them [in workspace settings.](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6442f7de8226a6291646a813/settings/self-healing-ci?utm_source=pull-request&utm_medium=comment)An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.
View your CI Pipeline Execution ↗ for commit 335d039f470b362897797683909ca7154305a2b3
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 13m 57s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 20s View ↗
☁️ Nx Cloud last updated this comment at
2025-12-21 00:43:52UTCMore templates
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
- 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-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@6166@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@6166@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6166@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6166@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6166@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6166@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6166@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6166@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6166@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6166@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6166@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6166@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6166@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6166@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6166@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6166@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6166@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6166@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6166@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6166@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@6166@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6166@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6166@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6166@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6166@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6166@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6166@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6166@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6166@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6166@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6166@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6166@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6166@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6166@tanstack/vue-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6166@tanstack/vue-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6166@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6166@tanstack/vue-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6166@tanstack/vue-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6166@tanstack/vue-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6166@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6166commit:
335d039Actionable comments posted: 0
🧹 Nitpick comments (4)
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts (1)
39-44: Inconsistent guard condition betweeninputValidatorandserverchecks.Line 22 checks
if (inputValidator), but line 39 checksif (server && server.firstArgPath?.node). Theserver.firstArgPath?.nodecheck seems unnecessary since the removal logic (lines 41-43) only usesserver.callPath, notfirstArgPath. This could silently skip valid server call expressions that have no arguments.Consider aligning with the
inputValidatorpattern:Proposed fix
- if (server && server.firstArgPath?.node) { + if (server) { // remove the server call expression if (t.isMemberExpression(server.callPath.node.callee)) { server.callPath.replaceWith(server.callPath.node.callee.object) } }packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts (2)
33-34: Unsafe type assertion on variable declarator id.The assertion
(variableDeclarator.id as t.Identifier).nameassumes the variable declarator always uses a simple identifier. This would fail for destructuring patterns likeconst { fn } = ...orconst [fn] = ....Consider adding a guard:
Proposed fix
const variableDeclarator = path.parentPath.node - const existingVariableName = (variableDeclarator.id as t.Identifier).name + if (!t.isIdentifier(variableDeclarator.id)) { + throw new Error('createServerFn must be assigned to a simple variable, not a destructuring pattern!') + } + const existingVariableName = variableDeclarator.id.name
58-68: Type assertion onfirstArgPath.nodemay be unsafe.Line 68 casts
handlerFnPath.node as t.Expression, butfirstArgPathis typed asbabel.NodePath | nullwhich could point to any node type (e.g.,SpreadElement). While the validation on line 60 checks for existence, it doesn't verify the node type.Consider adding explicit type validation:
Proposed fix
- const handlerFn = handlerFnPath.node as t.Expression + if (!t.isExpression(handlerFnPath.node)) { + throw codeFrameError( + opts.code, + path.node.callee.loc!, + `createServerFn handler must be an expression!`, + ) + } + const handlerFn = handlerFnPath.nodepackages/start-plugin-core/src/create-server-fn-plugin/compiler.ts (1)
359-372: Passing entire objectpinstead of structuredRewriteCandidate.The handlers expect a
RewriteCandidatewithpathandmethodChainproperties. The objectphas{ path, kind, methodChain }, which includes an extrakindproperty. This works due to structural typing, but could be cleaner.Optional: Extract RewriteCandidate explicitly
if (p.kind === 'ServerFn') { - handleCreateServerFn(p, { + handleCreateServerFn({ path: p.path, methodChain: p.methodChain }, { env: this.options.env, code, directive: this.options.directive, isProviderFile, }) } else { - handleCreateMiddleware(p, { + handleCreateMiddleware({ path: p.path, methodChain: p.methodChain }, { env: this.options.env, }) }📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 75e1387159c99aed6e09fe0bb3520047c814247a and b43fe8e50cfa59aaf86ad7047d25a1bdcb66194c.
📒 Files selected for processing (10)
e2e/react-start/server-functions/src/routes/factory/-functions/functions.ts(2 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportA.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportB.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportC.ts(1 hunks)e2e/react-start/server-functions/src/routes/factory/index.tsx(2 hunks)e2e/react-start/server-functions/tests/server-functions.spec.ts(1 hunks)packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts(9 hunks)packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts(2 hunks)packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts(5 hunks)packages/start-plugin-core/src/create-server-fn-plugin/types.ts(1 hunks)
🧰 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/tests/server-functions.spec.tse2e/react-start/server-functions/src/routes/factory/-functions/functions.tspackages/start-plugin-core/src/create-server-fn-plugin/types.tse2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportB.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.tse2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportA.tse2e/react-start/server-functions/src/routes/factory/index.tsxpackages/start-plugin-core/src/create-server-fn-plugin/compiler.tse2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportC.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/tests/server-functions.spec.tse2e/react-start/server-functions/src/routes/factory/-functions/functions.tspackages/start-plugin-core/src/create-server-fn-plugin/types.tse2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportB.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.tse2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportA.tse2e/react-start/server-functions/src/routes/factory/index.tsxpackages/start-plugin-core/src/create-server-fn-plugin/compiler.tse2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportC.ts
🧠 Learnings (1)
📚 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/tests/server-functions.spec.tse2e/react-start/server-functions/src/routes/factory/index.tsx
🧬 Code graph analysis (4)
e2e/react-start/server-functions/src/routes/factory/-functions/functions.ts (1)
e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportC.ts (1)
nestedReexportFactory(18-20)
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts (1)
packages/start-plugin-core/src/create-server-fn-plugin/types.ts (1)
RewriteCandidate(39-42)
e2e/react-start/server-functions/src/routes/factory/index.tsx (1)
e2e/react-start/server-functions/src/routes/factory/-functions/functions.ts (1)
nestedReexportedFactoryFn(123-130)
packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts (3)
packages/start-plugin-core/src/create-server-fn-plugin/types.ts (1)
MethodChainPaths(18-24)
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts (1)
handleCreateServerFn(11-129)
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts (1)
handleCreateMiddleware(10-45)
⏰ 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: Test
- GitHub Check: Preview
🔇 Additional comments (26)
e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportC.ts (2)
1-16: LGTM! Well-documented middleware implementation.The JSDoc clearly explains the position in the re-export chain, and the middleware implementation correctly augments the context with type-safe values using
as const.
18-20: LGTM! Factory configuration is correct.The server function factory is properly configured with the GET method and middleware attachment, following the established pattern in the codebase.
e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportA.ts (1)
1-7: LGTM! Clean re-export with clear documentation.The JSDoc clearly documents this module's role as the top-level entry point in the nested re-export chain, and the re-export syntax is correct.
e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportB.ts (1)
1-7: LGTM! Clean re-export with clear documentation.The JSDoc clearly documents this module's role as the middle link in the nested re-export chain, and the re-export syntax is correct.
e2e/react-start/server-functions/src/routes/factory/index.tsx (2)
15-15: LGTM! Import is correctly added.The import of
nestedReexportedFactoryFnis properly placed with other factory function imports.
156-165: LGTM! Test case configuration is correct and well-documented.The test case properly configures the expected behavior for the nested re-export chain, with expected context matching the middleware output from
nestedReexportC.ts. The comment clearly explains the A -> B -> C chain pattern.e2e/react-start/server-functions/tests/server-functions.spec.ts (1)
595-617: LGTM! Comprehensive e2e test for nested re-export chain.The test properly verifies that middleware executes correctly through the A -> B -> C nested re-export chain. The test pattern is consistent with existing re-export tests and includes appropriate assertions for both the middleware context and result comparison.
e2e/react-start/server-functions/src/routes/factory/-functions/functions.ts (2)
9-10: LGTM! Import correctly references the top of the re-export chain.The import properly starts from
nestedReexportA, which is the entry point of the A -> B -> C chain, and the comment clearly explains the test scenario.
121-130: LGTM! Factory function implementation is correct and consistent.The
nestedReexportedFactoryFnimplementation follows the established pattern for factory-based server functions, properly accessing the middleware context and returning the expected structure for testing.packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts (2)
2-3: LGTM!Clean import structure with the new
RewriteCandidatetype from the types module.
10-18: LGTM!The function signature refactor to accept
RewriteCandidateis well-documented and the server environment guard is appropriate.packages/start-plugin-core/src/create-server-fn-plugin/types.ts (3)
1-12: LGTM!Well-structured type definitions with appropriate JSDoc documentation. The
MethodCallInfointerface cleanly captures the call path and optional first argument path.
14-34: LGTM!The
MethodChainPathsinterface andMETHOD_CHAIN_KEYSconstant provide a clear contract for the method chain structure. UsingReadonlyArraywithas constensures immutability.
36-42: LGTM!The
RewriteCandidateinterface cleanly encapsulates the path and method chain information needed for rewrite operations.packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts (3)
2-3: LGTM!Clean import updates for the new type structure.
11-25: LGTM!Well-documented function signature with the new
directivefield and clear JSDoc forisProviderFile.
103-120: LGTM!The handler replacement logic correctly constructs the arrow function with the
'use server'directive and references the original variable name for__executeServer.packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts (9)
45-53: LGTM!Good performance optimization with pre-computed
IdentifierToKindmap enabling O(1) candidate detection instead of iterating over lookup kinds.
261-276: LGTM!Parallel resolution of candidates using
Promise.allis a sound performance improvement. The subsequent filtering intotoRewriteMapcorrectly handles the resolved results.
288-298: LGTM!Collecting all
CallExpressionpaths into a Map for O(1) lookup is an effective optimization that avoids repeated AST traversals.
316-348: Method chain walking logic looks correct.The downward traversal through the call chain correctly collects method call info for each known method name. The use of
callExprPaths.get(currentNode)!is safe here since these nodes were collected in the prior traversal.One minor observation: if a method appears multiple times in the chain (e.g.,
.handler().handler()), only the outermost occurrence is recorded since the inner one would overwrite. This appears intentional given the fluent API design.
350-355: LGTM!Good defensive check ensuring all candidates were successfully resolved to paths.
429-482: LGTM!The
findExportInModulemethod correctly implements recursive export resolution throughexport * fromchains with:- Cycle detection via
visitedModulesset - Parallel resolution of re-export sources for performance
- First-match-wins semantics appropriate for valid code without duplicate exports
453-478: Parallel resolution may mask errors from failed module loads.If one re-export source fails to resolve while another succeeds, the error is silently ignored and the first valid result is returned. This is likely intentional for robustness, but could mask configuration issues during development.
Consider whether failed resolutions should be logged at debug level for troubleshooting.
543-550: LGTM!Efficiently unwrapping TypeScript wrapper expressions (
TSAsExpression,TSNonNullExpression,ParenthesizedExpression) before processing improves resolution efficiency by avoiding repeated checks.
669-686: LGTM!The refactored
isCandidateCallExpressioncorrectly uses the pre-computedIdentifierToKindmap for O(1) lookup, improving performance over the previous iteration-based approach.
Sign in to join this conversation.
Walkthrough#
Adds a three-stage nested re-export chain (A → B → C) for a server-function factory with middleware and corresponding e2e test; simultaneously refactors the create-server-fn compiler to use precomputed maps, parallel candidate resolution, a MethodChain/RewriteCandidate model, and updates handler/middleware rewrite APIs to accept RewriteCandidate.
Changes#
e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportA.ts,e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportB.ts,e2e/react-start/server-functions/src/routes/factory/-functions/nestedReexportC.tsnestedReexportC.tsdefinesnestedReexportFactory(GET) with a middleware that setscontext.nested,nestedReexportBandnestedReexportAre-export downstream exports.e2e/react-start/server-functions/src/routes/factory/-functions/functions.ts,e2e/react-start/server-functions/src/routes/factory/index.tsxnestedReexportedFactoryFnby wiring the re-exported factory through a handler returning{ name, context }; exposed in the UI/test map with expected context payload.e2e/react-start/server-functions/tests/server-functions.spec.ts'nested-middleware-executed', asserting context equality as in existing tests.packages/start-plugin-core/src/create-server-fn-plugin/compiler.tsfindExportInModuleto follow export * chains, and optimized expression unwrapping and callee resolution.packages/start-plugin-core/src/create-server-fn-plugin/types.tsMethodCallInfo,MethodChainPaths,MethodChainKey,METHOD_CHAIN_KEYS, andRewriteCandidateto represent collected call paths and first-arg paths for rewrite operations.packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts,packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tsRewriteCandidate(withmethodChain) instead of Babel NodePath, removed root traversal logic, and updated rewrite/removal logic to operate directly on candidate.methodChain entries; adjusted signatures and error reporting accordingly.packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts,packages/start-plugin-core/tests/createServerFn/createServerFn.test.tsviusage for mocking.Sequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~50 minutes
Areas requiring extra attention:
packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts— parallel resolution,findExportInModule, and map-based rewrite aggregation.types.ts+ use sites — verifyMethodChainPathsfields andfirstArgPathnullability handling.handleCreateServerFn.ts/handleCreateMiddleware.ts— ensure replacements/removals operate correctly oncandidate.methodChainand maintain correct error locations/codeFrameError usage.Possibly related PRs#
export *chains.Suggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between b43fe8e50cfa59aaf86ad7047d25a1bdcb66194c and 335d039f470b362897797683909ca7154305a2b3.
📒 Files selected for processing (5)
packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts(11 hunks)packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts(2 hunks)packages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.ts(5 hunks)packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.ts(2 hunks)packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts(2 hunks)🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.tspackages/start-plugin-core/tests/createServerFn/createServerFn.test.tspackages/start-plugin-core/src/create-server-fn-plugin/compiler.ts**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.tspackages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/src/create-server-fn-plugin/handleCreateServerFn.tspackages/start-plugin-core/tests/createServerFn/createServerFn.test.tspackages/start-plugin-core/src/create-server-fn-plugin/compiler.ts🧠 Learnings (2)
📚 Learning: 2025-11-02T16:16:24.898Z
Applied to files:
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/tests/createServerFn/createServerFn.test.ts📚 Learning: 2025-10-08T08:11:47.088Z
Applied to files:
packages/start-plugin-core/tests/createMiddleware-create-server-fn-plugin/createMiddleware.test.tspackages/start-plugin-core/tests/createServerFn/createServerFn.test.ts🧬 Code graph analysis (2)
packages/start-plugin-core/src/create-server-fn-plugin/handleCreateMiddleware.ts (1)
packages/start-plugin-core/src/create-server-fn-plugin/compiler.ts (3)
⏰ 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)
🔇 Additional comments (29)
Comment `@coderabbitai help` to get the list of available commands and usage tips.