Skip to content

Conversation

OnurGvnc
Copy link
Contributor

@OnurGvnc OnurGvnc commented Jul 10, 2025

Hi! This PR fixes a bug where server function urls are incorrect when the app uses a basePath.

The Problem:

The createServerRpc function (on the server) was creating URLs without the base path. However, the createClientRpc
function (on the client) was including it.

const url = `/${sanitizeBase(serverBase)}/${functionId}`

const sanitizedAppBase = sanitizeBase(process.env.TSS_APP_BASE || '/')
const sanitizedServerBase = sanitizeBase(serverBase)
const url = `${sanitizedAppBase ? `/${sanitizedAppBase}` : ``}/${sanitizedServerBase}/${functionId}`

For example, with a base path of '/app':

  • Server URL: /_serverFn/<function_id>
  • Client URL: /app/_serverFn/<function_id>

<form action={loginFn.url} method="POST">
hydration error:

  <LoginPage>
    <div>
      <h1>
        <form
+         action="/app/_serverFn/src_routes_auth_login_tsx--loginFn_createServerFn_handler"
-         action="/_serverFn/src_routes_auth_login_tsx--loginFn_createServerFn_handler"
           method="POST"
        >

This difference caused two main problems:

  • A hydration error
  • Broken forms, because submitting a form would go to the wrong URL (without the /app prefix).

The Solution:

I've updated createServerRpc to also use the base path when it creates the URL, just like the client version does.

File changed: packages/start-server-functions-server/src/index.ts

// Before
const url = `/${sanitizeBase(serverBase)}/${functionId}`

// After
const sanitizedAppBase = sanitizeBase(process.env.TSS_APP_BASE || '/')
const sanitizedServerBase = sanitizeBase(serverBase)

const url = `${sanitizedAppBase ? `/${sanitizedAppBase}` : ``}/${sanitizedServerBase}/${functionId}`

Now, both the client and server create the same correct URL.

@schiller-manuel
Copy link
Contributor

thanks for this!
can you please add an e2e test for this in the e2e/react-start/custom-basepath project?

@OnurGvnc
Copy link
Contributor Author

Thanks! I've added the e2e test.

Without this PR's changes, the test would fail with:

  Expected: "/custom/basepath/_serverFn/src_routes_logout_tsx--logoutFn_createServerFn_handler"
  Received: "/_serverFn/src_routes_logout_tsx--logoutFn_createServerFn_handler"

The test now passes with the PR's fix, confirming that server function URLs correctly include the app's basepath.

Copy link

nx-cloud bot commented Jul 11, 2025

View your CI Pipeline Execution ↗ for commit 61a7e61

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 4m 30s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-11 03:58:55 UTC

Copy link

pkg-pr-new bot commented Jul 11, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@4619

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@4619

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@4619

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@4619

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@4619

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@4619

@tanstack/react-router-with-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-with-query@4619

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@4619

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@4619

@tanstack/react-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@4619

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@4619

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@4619

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@4619

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@4619

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@4619

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@4619

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@4619

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@4619

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@4619

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@4619

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@4619

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@4619

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@4619

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@4619

@tanstack/solid-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@4619

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@4619

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@4619

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@4619

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@4619

@tanstack/start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@4619

@tanstack/start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@4619

@tanstack/start-server-functions-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@4619

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@4619

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@4619

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@4619

commit: 61a7e61

@SeanCassiere SeanCassiere changed the title fix: Add app base path to createServerRpc url fix(start-server-functions-server): add base path to the RPC URL Jul 11, 2025
@SeanCassiere SeanCassiere merged commit bbc480a into TanStack:main Jul 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants