Skip to content

fix(start-client-core): add safe fallback for TSS_SERVER_FN_BASE in createClientRpc - #8210

Open
lx3133584 wants to merge 1 commit into
TanStack:mainfrom
lx3133584:fix/start-client-rpc-server-fn-base-fallback
Open

fix(start-client-core): add safe fallback for TSS_SERVER_FN_BASE in createClientRpc#8210
lx3133584 wants to merge 1 commit into
TanStack:mainfrom
lx3133584:fix/start-client-rpc-server-fn-base-fallback

Conversation

@lx3133584

@lx3133584 lx3133584 commented Sep 1, 2026

Copy link
Copy Markdown

Problem

In createClientRpc(), process.env.TSS_SERVER_FN_BASE is evaluated directly to construct the server function URL. In browser environments where globalThis.process is not defined (e.g. Vite dev servers with server.hmr: false where @vite/client preamble is omitted), evaluating process.env throws a ReferenceError: process is not defined. Furthermore, when process.env.TSS_SERVER_FN_BASE is undefined, string concatenation produces "undefined" + functionId, resulting in a relative URL that fails with 500 when called from nested routes.

Root Cause

createClientRpc directly accessed process.env.TSS_SERVER_FN_BASE without guarding against process being undefined or falling back to the default server function base prefix /_serverFn/.

Fix

  1. Safely resolve serverFnBase by checking typeof process !== 'undefined' and typeof import.meta !== 'undefined' before reading TSS_SERVER_FN_BASE.
  2. Fall back to the standard default /_serverFn/ when TSS_SERVER_FN_BASE is not set.

Testing

  1. Added unit tests in packages/start-client-core/tests/createClientRpc.test.ts covering:
    • Custom process.env.TSS_SERVER_FN_BASE resolution
    • Default fallback /_serverFn/ when TSS_SERVER_FN_BASE is undefined
    • Safe execution without ReferenceError when globalThis.process is undefined
  2. Ran vitest test suite across start-client-core (91 passed).

Summary by CodeRabbit

  • Bug Fixes

    • Improved server-function URL detection across browser and server environments.
    • Prevented errors when the process object is unavailable in browser runtimes.
    • Added support for custom server-function base URLs with a reliable default fallback.
  • Tests

    • Added coverage for custom URLs, default behavior, RPC metadata, and environments without process.

…reateClientRpc

Fixes TanStack#8201

Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 3e7e4a69-6784-462c-912b-0c43c7f92cb9

📥 Commits

Reviewing files that changed from the base of the PR and between 37877da and 5d1b5e5.

📒 Files selected for processing (2)
  • packages/start-client-core/src/client-rpc/createClientRpc.ts
  • packages/start-client-core/tests/createClientRpc.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

createClientRpc now resolves its base URL from available environment variables or a default path. Tests cover URL selection, RPC metadata, marker properties, and execution without process.

Changes

Server-function URL resolution

Layer / File(s) Summary
Environment-safe RPC URL resolution
packages/start-client-core/src/client-rpc/createClientRpc.ts, packages/start-client-core/tests/createClientRpc.test.ts
createClientRpc checks guarded process.env and import.meta.env values before using /_serverFn/. Tests validate configured and default URLs, RPC metadata, marker properties, and missing process handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5d1b5

This change prevents browser-side URL construction failures by safely falling back to /_serverFn/ when no server-function base is configured. No actionable merge-blocking risk remains after normal checks and review.

🚥 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 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: adding safe fallback handling for TSS_SERVER_FN_BASE in createClientRpc.
Description check ✅ Passed 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 comple…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant