fix(start-client-core): add safe fallback for TSS_SERVER_FN_BASE in createClientRpc - #8210
Conversation
…reateClientRpc Fixes TanStack#8201 Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesServer-function URL resolution
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change prevents browser-side URL construction failures by safely falling back to 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description clearly explains the problem, root cause, fix, and test coverage. It does not use the template headings or include checklist and release-impact selections, but it remains mostly complete and directly related to the changes.
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Problem
In
createClientRpc(),process.env.TSS_SERVER_FN_BASEis evaluated directly to construct the server function URL. In browser environments whereglobalThis.processis not defined (e.g. Vite dev servers withserver.hmr: falsewhere@vite/clientpreamble is omitted), evaluatingprocess.envthrows aReferenceError: process is not defined. Furthermore, whenprocess.env.TSS_SERVER_FN_BASEis undefined, string concatenation produces"undefined" + functionId, resulting in a relative URL that fails with 500 when called from nested routes.Root Cause
createClientRpcdirectly accessedprocess.env.TSS_SERVER_FN_BASEwithout guarding againstprocessbeing undefined or falling back to the default server function base prefix/_serverFn/.Fix
serverFnBaseby checkingtypeof process !== 'undefined'andtypeof import.meta !== 'undefined'before readingTSS_SERVER_FN_BASE./_serverFn/whenTSS_SERVER_FN_BASEis not set.Testing
packages/start-client-core/tests/createClientRpc.test.tscovering:process.env.TSS_SERVER_FN_BASEresolution/_serverFn/whenTSS_SERVER_FN_BASEis undefinedReferenceErrorwhenglobalThis.processis undefinedstart-client-core(91 passed).Summary by CodeRabbit
Bug Fixes
processobject is unavailable in browser runtimes.Tests
process.