Shared layout auth fetch still slows soft navigatio
Unanswered
Expensiveee posted this in #help-forum
I’m using Next.js 15 App Router with TanStack Query in a dashboard app.
My route structure is roughly:
The root app/layout.tsx has a QueryClientProvider.
In app/(app)/layout.tsx, I currently fetch the session server-side:
This was done to avoid a layout shift in the welcome banner, e.g. avoiding Welcome back, Operator changing to Welcome back, John. This is supposed to load the sessiong server-side once, then hydrate the queryclient witht the data, and NEVER run again on soft navs, but it still kinda does.
The problem is that every soft navigation still seems to wait on the RSC payload. I still see loading.tsx mount for 200–700ms on route changes. I'd need it to be snappy, which it is when I remove the auth check service side.
My route structure is roughly:
app/(app)/layout.tsx
app/(app)/shop/page.tsx
app/(app)/residentials/page.tsx
app/(app)/isps/page.tsx
app/(app)/(homepage)/page.tsxThe root app/layout.tsx has a QueryClientProvider.
In app/(app)/layout.tsx, I currently fetch the session server-side:
const session = await requireDashboardSession();
const query_client = new QueryClient();
query_client.setQueryData(currentUserKey, session.user);
return (
<HydrationBoundary state={dehydrate(query_client)}>
<AppShell>{children}</AppShell>
</HydrationBoundary>
);This was done to avoid a layout shift in the welcome banner, e.g. avoiding Welcome back, Operator changing to Welcome back, John. This is supposed to load the sessiong server-side once, then hydrate the queryclient witht the data, and NEVER run again on soft navs, but it still kinda does.
The problem is that every soft navigation still seems to wait on the RSC payload. I still see loading.tsx mount for 200–700ms on route changes. I'd need it to be snappy, which it is when I remove the auth check service side.
5 Replies
I think I can confirm that the server-side check runs ONCE and that the issue is purely from the rsc ?
In my requireDashboardSession() I sent a wehook to discord to notify me when it actually runs, and it did it once, and when I soft nav it didn't send it. So only on hard/refresh
Update:
Adding this in my sidebar works, but.. why?
<Link href={props.url} prefetch={true} onClick={handleClick}>
prefetch true is what I added
Adding this in my sidebar works, but.. why?
<Link href={props.url} prefetch={true} onClick={handleClick}>
prefetch true is what I added
Still kinda slow, I don't get why isn't it just snappy
Think I know why now, the layout was saync so it made the routes dynamic, which default links don't actual prefetch up to page.tsx but rather loading.tsx