TanStackT
TanStackโ€ข7mo agoโ€ข
3 replies
sacred-emerald

Handle persisted state

Hey everyone! ๐Ÿ‘‹

I'm trying to implement persistent sidebar state
using cookies in Tanstack Start to avoid hydration
flashes. I need to read a cookie value during SSR
so the initial render matches the client state.

I tried using a loader like this:
```js
loader: async ({ request }) => {
const cookieHeader =
request?.headers?.get("cookie") || "";
// parse cookie...
}

But request is undefined in the loader context.

What's the correct way to access cookies during SSR
in Tanstack Start loaders? I want to read a
sidebar_state cookie on the server so I can pass
the correct initial state to avoid the open/close
flash on hydration.

Any guidance would be appreciated! ๐Ÿ™

This gives them the context of what you're trying
to achieve and shows what you've already tried.
Was this page helpful?