Which project does this relate to?
Router
Describe the bug
When using @tanstack/react-router-devtools in a TanStack Start SSR application, the server crashes with:
ReferenceError: window is not defined
at delegateEvents (server-_libs/@tanstack/react-router-devtools-C28X7FL_.js:1255:48)
at loadEntries (server-ssr-ParBoa2f.js:658:52)
at startRequestResolver (server-ssr-ParBoa2f.js:848:20)
at Object.fetch (server-ssr-ParBoa2f.js:1028:10)
The root cause is in @tanstack/router-devtools-core. The BaseTanStackRouterDevtoolsPanel module contains top-level (module scope) calls to delegateEvents():
// BaseTanStackRouterDevtoolsPanel-BbL4h7yi.js, line 1410
delegateEvents(["click"]);
// line 1475
delegateEvents(["click"]);
// line 2169
delegateEvents(["click", "mousedown"]);
The delegateEvents function (from the bundled SolidJS runtime in context-D56_tqst.js) unconditionally accesses window.document:
function delegateEvents(eventNames, document = window.document) {
// ...
}
When the bundler (rolldown/nitro) includes @tanstack/react-router-devtools in the SSR bundle, these calls execute during module initialization on the server, where window is not defined.
Your Example Website or App
https://github.com/arelia/repro-trdevtools
Steps to Reproduce the Bug or Issue
- Initialize a new directory
npm init -y
npm install @tanstack/router-devtools-core
- Create
repro.mjs with this single line
import "./node_modules/@tanstack/router-devtools-core/dist/BaseTanStackRouterDevtoolsPanel-BbL4h7yi.js";
- Run with
- Observe crash
file:///…/node_modules/@tanstack/router-devtools-core/dist/context-D56_tqst.js:1380
function delegateEvents(eventNames, document = window.document) {
^
ReferenceError: window is not defined
Expected behavior
The devtools module should be safe to import in a server environment. Either:
- The
delegateEvents() calls should be guarded with typeof window !== 'undefined' / isServer check, so they're no-ops on the server.
- The SolidJS
delegateEvents function itself should handle server environments by checking for window before accessing window.document in its default parameter.
- The devtools package should provide a separate server-safe entry point (e.g., via
exports conditions in package.json) that stubs out DOM-dependent code.
Screenshots or Videos
No response
Platform
@tanstack/react-router-devtools: 1.166.13
@tanstack/router-devtools-core: 1.167.3
@tanstack/react-start: 1.167.40
@tanstack/react-router: 1.168.22
- Node.js:
v25.8.2
- Vite:
8.0.0-beta.14
- Nitro:
node-server preset
Additional context
No response
Which project does this relate to?
Router
Describe the bug
When using
@tanstack/react-router-devtoolsin a TanStack Start SSR application, the server crashes with:The root cause is in
@tanstack/router-devtools-core. TheBaseTanStackRouterDevtoolsPanelmodule contains top-level (module scope) calls todelegateEvents():The
delegateEventsfunction (from the bundled SolidJS runtime in context-D56_tqst.js) unconditionally accesseswindow.document:When the bundler (rolldown/nitro) includes
@tanstack/react-router-devtoolsin the SSR bundle, these calls execute during module initialization on the server, wherewindowis not defined.Your Example Website or App
https://github.com/arelia/repro-trdevtools
Steps to Reproduce the Bug or Issue
repro.mjswith this single lineExpected behavior
The devtools module should be safe to import in a server environment. Either:
delegateEvents()calls should be guarded withtypeof window !== 'undefined'/isServercheck, so they're no-ops on the server.delegateEventsfunction itself should handle server environments by checking forwindowbefore accessingwindow.documentin its default parameter.exportsconditions in package.json) that stubs out DOM-dependent code.Screenshots or Videos
No response
Platform
@tanstack/react-router-devtools:1.166.13@tanstack/router-devtools-core:1.167.3@tanstack/react-start:1.167.40@tanstack/react-router:1.168.22v25.8.28.0.0-beta.14node-serverpresetAdditional context
No response