Headers missing on initial load from server
Anybody else seen cases where on the initial load of the app when calling a server function in loaders the headers are not complete, particularly things like cookies and auth headers. It seems on initial load my auth headers are missing, but then as soon as I navigate around or even just clicking try again button on the on the client it works fine.
8 Replies
fair-rose•6mo ago
which version of start are you using? is this in prod, dev... some more context please
ratty-blushOP•6mo ago
GImme a bit I'll try to make a minimal repro. This is in dev and version is 1.114.32
Hey sorry my computer died yesterday: https://codesandbox.io/p/devbox/pedantic-mestorf-3lrrdq This is an example repro @Manuel Schiller
Seems to be what occurs is the headers that get sent on the initial request are headers made internally within the server but stripped of all the browser headers from the initial request, but then subsequent requests include the browsers headers since they are made from the client directly to the api endpoint. But I would normally expect to see the headers from the browser even on the initial request.
fair-rose•6mo ago
we fixed that some time ago so I wonder why this appeared again
ratty-blushOP•6mo ago
Yeah I did see some issues on github from the past that mentioned this was fixed and were closed, but I was seeing it. Tried seeing if it was something on my end but seemed to stick around no matter what I tried
stormy-gold•6mo ago
I'm noticing this too, seems to be only for API routes though
fair-rose•6mo ago
thats not really surprising though
you call fetch on the server, how would fetch know to include the client headers
you would need to stuff them in manually
btw that is what we do when calling server functions from the server
there we can do it automatically as we handle the whole chain
but here... you need to do it
ratty-blushOP•6mo ago
In my real example for an app I'm doing I'm using trpc which makes a fetch call. I guess I'll need to always in loaders detect whether I'm on the client or the server then.
fair-rose•6mo ago
yep. there is a yet undocumented feature for providing different function impls based on the env
createIsomorphicFn