Replies: 1 comment
|
There are two coupled reasons why this happens, caused by the interaction between TanStack Start's SSR streaming and TanStack Query's dehydration lifecycle during a cold page load (direct URL navigation). 1. Root Cause: SSR Stream Closes Before Query FinishesWhen you navigate on the client, TanStack Router renders in the browser where the DOM stream is already settled. But when you directly access the URL in the address bar:
2. Cookie / Header Forwarding on Server SideNotice your hooks: {
beforeRequest: [
async (req) => {
const { auth } = await getAuthSessionFn();
if (auth?.accessToken) {
req.headers.set("Authorization", `Bearer ${auth.accessToken.token}`);
}
},
],
},When running in the browser, If To fix this on the server side in TanStack Start, ensure your session getter extracts cookies from the active request: import { getWebRequest } from '@tanstack/start/server'
export async function getAuthSessionFn() {
// If running on the server, extract cookie/token from the incoming web request
if (typeof window === 'undefined') {
const req = getWebRequest()
const cookieHeader = req?.headers.get('cookie')
// extract auth token from cookieHeader or forward Authorization header
return parseAuthFromCookies(cookieHeader)
}
// Client side implementation
return getClientSession()
}3. Ensure Route Auth Strictly Guards the Loader in
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm consistently running into an error when trying to directly access an authenticated page by URL. The error message is:
client : "Cannot read properties of undefined (reading 'isDehydrated')"

server : "tried to stream query ["all-users"] after stream was already closed"

(authenticated)/test.tsx
(authenticated)/-query/index.ts
integrations/tuyau.ts
All reactions