Skip to content

feat: add isServer - #4648

Merged
schiller-manuel merged 5 commits into
mainfrom
is-server
Jan 24, 2026
Merged

feat: add isServer#4648
schiller-manuel merged 5 commits into
mainfrom
is-server

Conversation

@schiller-manuel

@schiller-manuelschiller-manuel commented Jul 13, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Router now respects an optional runtime isServer override for consistent server/client behavior across frameworks, preserving existing SSR/CSR flows.
  • Chores
    • Introduced a small support package providing per-environment isServer values and adjusted test/build resolution to favor a development variant during test runs.

✏️ Tip: You can customize this high-level summary in your review settings.

@nx-cloud

nx-cloudBot commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit fabb267

CommandStatusDurationResult
nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded9m 36sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 46sView ↗

☁️ Nx Cloud last updated this comment at 2026-01-24 10:27:32 UTC

@pkg-pr-new

pkg-pr-newBot commented Jul 13, 2025

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-is-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-is-server@4648

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@4648

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@4648

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@4648

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@4648

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@4648

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@4648

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@4648

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: fabb267

@nick-potts

Copy link
Copy Markdown

Is there a way to override this in the router config?

@schiller-manuel

Copy link
Copy Markdown
CollaboratorAuthor

@nick-potts no. what would you need this for?

@coderabbitai

coderabbitaiBot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a new package @tanstack/router-is-server exporting environment-specific isServer values and updates router core and framework integrations to prefer (isServer ?? router.isServer) for server/client detection across SSR, hydration, loaders, transitions, and scroll restoration.

Changes

Cohort / File(s)Summary
New package: router-is-server
packages/router-is-server/package.json, packages/router-is-server/tsconfig.json, packages/router-is-server/vite.config.ts, packages/router-is-server/eslint.config.js
Add package scaffolding, multi-environment exports (server=true, client=false, development=undefined), build/test config, and lint overrides.
router-is-server sources
packages/router-is-server/src/server.ts, packages/router-is-server/src/client.ts, packages/router-is-server/src/development.ts
Three entry modules exporting isServer with env-specific values (true / false / undefined).
Core: re-export & dependency
packages/router-core/package.json, packages/router-core/src/isServer.ts, packages/router-core/src/index.ts
Add dependency on @tanstack/router-is-server, introduce isServer re-export on router-core public API.
Core logic updates
packages/router-core/src/router.ts, packages/router-core/src/load-matches.ts, packages/router-core/src/scroll-restoration.ts, packages/router-core/src/isServer.ts
Import and use (isServer ?? this.isServer) across history init, origin detection, loader/preload/hydration logic, SSR branches, and scroll restoration guards.
React integrations
packages/react-router/src/... (Asset.tsx, Match.tsx, Matches.tsx, ScriptOnce.tsx, scroll-restoration.tsx), packages/react-router/vite.config.ts
Import isServer and replace router.isServer checks with (isServer ?? router.isServer) in SSR/hydration, pending/error rendering, script emission; add Vite resolve condition for tests.
Solid integrations
packages/solid-router/src/... (Asset.tsx, Match.tsx, Matches.tsx, ScriptOnce.tsx, Transitioner.tsx, scroll-restoration.tsx), packages/solid-router/vite.config.ts
Same pattern: prefer isServer when defined for SSR/no-SSR gates and test-time resolution.
Vue integrations
packages/vue-router/src/... (Asset.tsx, Match.tsx, Matches.tsx, ScriptOnce.tsx, Transitioner.tsx, scroll-restoration.tsx), packages/vue-router/vite.config.ts
Same pattern applied to Title/Script, pending promise creation, transition and scroll logic; Vite test resolve adjustments.
SSR query integration
packages/router-ssr-query-core/src/index.ts
Use (isServer ?? router.isServer) for SSR detection in SSR-query glue code.
Framework misc files
packages/*-router/src/Asset.tsx, Match.tsx, Matches.tsx, ScriptOnce.tsx, Transitioner.tsx, scroll-restoration.tsx
Broad update across framework adapters to coalesce isServer with router server flag.
Config & tooling
packages/*-router/vite.config.ts, labeler-config.yml
Add test-time resolve.condition overrides for VITEST and labeler entry for new package.

Sequence Diagram(s)

sequenceDiagram
participant Component
participant isServerModule as isServer (module)
participant Router
participant Env as Server/Browser
Component->>isServerModule: import isServer
Component->>Router: read router.isServer
Component->>isServerModule: evaluate (isServer ?? router.isServer)
alt resolved true
Component->>Env: run server-branch (SSR render)
else resolved false
Component->>Env: run client-branch (hydrate/mount)
else resolved undefined
Component->>Router: fallback to router.isServer decision
Router->>Env: run appropriate branch
end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • birkskyum

Poem

🐰 I nibble code beneath the moon,
I bring isServer — true or false or soon.
Servers shout "true", browsers hum "no",
Tests can pause with undefined glow.
Hop, hydrate, render — off we go! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 28.57% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title 'feat: add isServer' accurately describes the main change: introducing a new isServer feature across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/react-router/vite.config.ts`:
- Around line 8-12: The Vite config currently unconditionally sets
resolve.conditions to an empty array when VITEST is unset, which overrides
Vite's defaults; change the resolve block so that the conditions property is
only added when process.env.VITEST is truthy (use ['development'] then) and omit
or leave conditions undefined for non-test builds so Vite's default resolution
is preserved; update the resolve object where "conditions" is set in the vite
config (refer to resolve.conditions and process.env.VITEST) to only supply the
conditions key during test runs.

Comment threadpackages/react-router/vite.config.ts Outdated
Comment on lines +246 to +250
define: {
// Replace __TSR_IS_SERVER__ with false for client builds
// This enables tree-shaking of server-only code branches
__TSR_IS_SERVER__: 'false',
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I saw this variable anywhere, it is a remainder of a previous attempt?

@schiller-manuel
schiller-manuel merged commit e79ad7e into mainJan 24, 2026
6 checks passed
@schiller-manuel
schiller-manuel deleted the is-server branch January 24, 2026 10:28
Sign up for freeto 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

@schiller-manuel@nick-potts@Sheraff