Zampa
Zampa
Explore posts from servers
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
maybe instead I can use the defineRouteRules as if it should always be cached, and then bypass the cache using server middleware for all paths
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
but Nitro should only serve that cached version if the user is not authenticated
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
No description
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
No description
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
It's just a compiler macro
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
I guess this is because Nuxt's compiler can only statically analyze this code during build time and correctly apply these rules to the route. It's not dynamic.
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
nope - the page is never cached by Nitro
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
Maybe something like this would work as a composable called on a given Nuxt page...?
export function usePageCaching() {
const { loggedIn } = useUserSession();

if (!loggedIn.value) {
defineRouteRules({
cache: {
swr: true,
maxAge: 1,
staleMaxAge: 59
},
});
}
}
export function usePageCaching() {
const { loggedIn } = useUserSession();

if (!loggedIn.value) {
defineRouteRules({
cache: {
swr: true,
maxAge: 1,
staleMaxAge: 59
},
});
}
}
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
15 replies
NNuxt
Created by Zampa on 3/7/2025 in #❓・help
If I have several routes cached with swr, how do I bypass that cache if the user is authenticated?
Thanks - this works well for caching a server API response, but I'm wanting to actually cache the entire Nuxt page/route itself... so you hit /blog not logged in, it gets served from cache you hit /blog while logged in, it bypasses cache
15 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
but I may experiment with it and see
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
and I was concerned about how performant setting ALL the components to .server.vue might be
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
but there are "islands" of user-content that should never be cached
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
My use case is that most of the pages I wanted heavily cached
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Right - but I have like 400+ components 🙂
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
and use the nuxt-client on the ones that are different
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Like, a global config to set all components as server components
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Yeah, I've watched that! I kind of would almost like to see a reverse Server Components option in Nuxt. Where all components are server components, and some select few are Client.
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Maybe wrapping all user-specific content in ClientOnly would circumvent that, but I'm not sure
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
so if you use isr or swr, it ends up caching the user state
54 replies