UI Elements stop working w/ beforeLoad
I'm encountering a strange bug where if I call getCookie in my route, the UI elements (in this case tabs) don't work.
Here is the code:
If I uncomment getCookie("userId"), suddenly my UI is not interactable anymore and I get this console error:
7 Replies
fascinating-indigo•2w ago
what is
getCookie
?wise-whiteOP•2w ago
import { getCookie, setCookie } from "@tanstack/react-start/server";
fascinating-indigo•2w ago
you cannot call server stuff in beforeLoad since this runs on the client as well
if you want to execute some function on the client always, then wrap in into a server function
wise-whiteOP•2w ago
I see well I want to execute this function on the server to redirect/route clients to specific pages (via createFileRoute) if they have a cookie set.
so where would be the best place to put this?
fascinating-indigo•2w ago
wrap it in a server function then and execute it in beforeLoad
but be aware that this executes for each navigation
so you might want to cache it
wise-whiteOP•2w ago
would I cache it via this:
createServerFnStaticCache
?
I also was looking into middlewares but couldn't figure out how to execute a middleware call into the createFileRoute functionfascinating-indigo•2w ago
you could just use query for this