fix(start-plugin-core): compile env-only and isomorphic fns before server fns #8493
main fromrefs/pull/8493/head·opened 🎯 Changes#
fixes #8446
passing createServerOnlyFn(...) or createIsomorphicFn()... straight into createServerFn().handler() produced a broken server fn. the server-only case compiled to .handler("<id>") and took the whole app down on load, the isomorphic one silently returned undefined.
cause is the handler order in the compiler. ServerFn ran first and replaced (caller) or cloned (provider) the handler argument, so the env-only and isomorphic transforms then edited stale or detached nodes. same ordering also left a createClientOnlyFn inside a handler body uncompiled in the provider file, so client-only code ran on the server with no guard. that one isn't an odd pattern, it's a normal thing to write.
fix runs the in-place rewrites (IsomorphicFn, ServerOnlyFn, ClientOnlyFn) before ServerFn and Middleware. one line, plus a comment on why.
tests:
- unit test in
compiler.test.tscovering client, ssr caller and server provider for all three shapes, fails on main - e2e: an inline handler case added to the existing
env-onlyandisomorphic-fnsroutes inreact-start/server-functions react-start.minimalbundle is byte identical before and after
not covered here: leaf kinds nested in each other (createIsomorphicFn().server(createServerOnlyFn(f))) still hit the same stale path problem. happy to follow up if you want that handled too.
✅ 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#
- Bug Fixes
- Server-only, client-only, and isomorphic functions nested in server-function handlers are now compiled correctly.
- Inline functions now retain the appropriate behavior for server and client execution, including when used directly as a handler.
- This resolves cases where nested environment-specific functions could be missed when preparing server functions and middleware.
- 1
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: TanStack/router/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
520d1429-af23-4591-89db-b77d5984bf8d📥 Commits
Reviewing files that changed from the base of the PR and between ddad69a4a4b18c19e3fcc510ac1e21f9dab883a7 and ac766961c3e58e16445db217db78ab8f0f02358d.
📒 Files selected for processing (6)
.changeset/swift-radios-battle.mde2e/react-start/server-functions/src/routes/env-only.tsxe2e/react-start/server-functions/src/routes/isomorphic-fns.tsxe2e/react-start/server-functions/tests/server-functions.spec.tspackages/start-plugin-core/src/start-compiler/compiler.tspackages/start-plugin-core/tests/compiler.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The compiler now processes isomorphic, server-only, and client-only function calls before server functions and middleware. Compiler tests and end-to-end routes cover inline calls used as server-function handlers and calls nested in handler bodies.
Changes#
Inline handler compilation
Layer / File(s) Summary Compile environment functions before server functions
packages/start-plugin-core/src/start-compiler/compiler.ts,packages/start-plugin-core/tests/compiler.test.ts,.changeset/swift-radios-battle.mdThe handler order now processes isomorphic, server-only, and client-only functions before server functions and middleware. Compiler tests cover direct and nested inline calls across caller and provider builds. The changeset records the patch. Exercise inline handlers in routes
e2e/react-start/server-functions/src/routes/env-only.tsx,e2e/react-start/server-functions/src/routes/isomorphic-fns.tsx,e2e/react-start/server-functions/tests/server-functions.spec.tsThe routes call inline server-only and isomorphic handlers, store and display their results, and the end-to-end tests assert the displayed values. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
schiller-manuelMerge Risk: ⚪ Minimal · up to
ac766The inline environment-function handler cases are covered without an identified regression. The change is ready to merge.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Linked Issues check ✅ Passed The compiler now runs IsomorphicFn,ServerOnlyFn, andClientOnlyFnrewrites beforeServerFnandMiddleware. This prevents later handlers from using paths after.handler()arguments are rep…Out of Scope Changes check ✅ Passed The changes stay within the linked issue scope. The compiler ordering change is the implementation. The compiler tests, end-to-end tests, and changeset verify the fix and its related environment-only … Title check ✅ Passed The title clearly summarizes the main compiler-ordering fix for environment-only and isomorphic functions before server functions. It is concise and specific. Description check ✅ Passed The description explains the problem, root cause, implementation, tests, scope limitation, checklist items, and release impact. It includes the required changeset information. Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (1 skipped: 1 unsupported.)
- Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
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.
Comment `@coderabbitai help` to get the list of available commands.ossaidqadri(GitHub profile, opens in a new tab) linked this to fix #8446
Sign in to join this conversation.
copilot-pull-request-reviewer[bot](GitHub profile, opens in a new tab) reviewed
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.