Felix
Felix
Explore posts from servers
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
and filed a bug. we'll see what comes of it.. https://github.com/nuxt/nuxt/issues/27909
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
ok. so idk if this is a bug in nuxt or not. but check this out:
const x = useAsyncData(
() => {
// this will NOT retain context in SSR call:
const fetch = $fetch;

// this retains context in SSR call:
// const fetch = useRequestFetch();

return fetch("/api/user");
},
{
immediate: true,
server: true,
watch: false,
},
);
const x = useAsyncData(
() => {
// this will NOT retain context in SSR call:
const fetch = $fetch;

// this retains context in SSR call:
// const fetch = useRequestFetch();

return fetch("/api/user");
},
{
immediate: true,
server: true,
watch: false,
},
);
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
I noticed that when I do a $fetch from my middleware/01.auth.global.ts middleware, the initial event context is retained! That is what I want. But why is this not happening for $fetch requests issued in page components is what I am trying to figure out. I cloned nuxt and will start digging...
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
Yes... So on the server why can't I get access to state established in the initial request object
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
For SSR pages
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
Yup but $fetch short-circuits and runs the code immediately on the server during the initial request. No client involved
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
Sorry if I come across rude but I don't understand how sth so simple can be made to be so difficult it can't be explained in one sentence . Kind of baffling. I'm surprised I also couldn't find answers on google. I love working with Nuxt overall. This is the first hol'on a minute moment. I'll give the video a watch tonight.
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
Which brings me back to why and how
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
What I am seeing is that for every $fetch the entire server/Middleware runs again on a fresh event object. Wouldn't getRequestEvent just return that?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
Right. I'm taking about a single initial request. I made sure no other xhr requests show in the network tab. But event.context is always cleared and I don't know how I can access the initial request context
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
I really don't get it. So request flies in, route is matched, handler runs, some $fetch calls happen and since we are on the server a FN runs instead of a http req. In that FN all the context should be available no?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
But if initial request binds to user a then for that request context how could it ever be user b?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
What is cross state pollution?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
Oh why is that
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
what i don't understand is it's just a function call; the context is already on the stack somehwere. is it not possible to somehow access this?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
assuming that it will soon get evicted because the lambda dies?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
right i see... just store it in memory somewhere to fake the db lookup?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
by what key?
44 replies
NNuxt
Created by Felix on 6/27/2024 in #❓・help
How to keep state in SSR requests?
So I have a 00.auth.ts middleware in server/middleware. It seems this middleware runs for every SSR request. My understanding that since it's server rendered all the state of the original request should be available. But the middleware runs repeatedly and the event object is a new object so I cannot cache state on it either
44 replies