Next.js Discord

Discord Forum

The new "use cache"

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I've enable the cache components in nextjs 16 and I also have in my root layout the shadcn sidebar that use the cookies to store if the sidebar is open or close and since I'm calling cookies they say I have to wrap the layout with suspense, do you think this is the best thing to do?
Answered by B33fb0n3
It looks more like that you using your auth api to get your session instead of the cookies for the sidebar. However, to answer your question: I would still wrap it with a suspense boundary. Of course you are free to cache this value. I would do that if its not auth based. Keep in mind, that its still an experimental feature (like caching private content)

You app is still vulnable to two 7.5/10 scored CVEs. You should upgrade.
View full answer

14 Replies

West African LionOP
@B33fb0n3 what do you think?
## Error Type
Blocking Route

## Error Message
Route "/project": Uncached data was accessed outside of <Suspense>. This delays the entire page from rendering, resulting in a slow user experience. Learn more: https://nextjs.org/docs/messages/blocking-route


    at <anonymous> (src/lib/auth/dal.ts:9:26)
    at <anonymous> (src/lib/auth/dal.ts:16:25)
    at <anonymous> (src/lib/auth/dal.ts:26:25)
    at AppProvidersWrapper (src/components/providers/app-providers-wrapper.tsx:11:40)
    at RootLayout (src/app/(app)/layout.tsx:15:5)
    at LogSafely (<anonymous>:null:null)

## Code Frame
   7 |
   8 | export const getSession = cache(async () => {
>  9 |   const h = await headers();
     |                          ^
  10 |   const session = await auth.api.getSession({ headers: h });
  11 |
  12 |   return session;

Next.js version: 16.0.7 (Turbopack)
also we call getSession
It looks more like that you using your auth api to get your session instead of the cookies for the sidebar. However, to answer your question: I would still wrap it with a suspense boundary. Of course you are free to cache this value. I would do that if its not auth based. Keep in mind, that its still an experimental feature (like caching private content)

You app is still vulnable to two 7.5/10 scored CVEs. You should upgrade.
Answer
@West African Lion and so do you think for a production app I should not enable cache components?
I wait with my pages for now. I let others test and see where are common mistakes and then I try it somewhen, see how they work and when I have no issues with it, I'll use it in production as well, yes
West African LionOP
but in the docs they don't say it's an experimental feature
what makes you say that? @B33fb0n3
yes its not an experimental feature, but it wasnt there before. Like it didnt exists in next15 and like that I am careful on what I am doing on production. I dont want to break my customers platforms just because I want to test something.

I rather test on small and personal projects. Then small work projects. Then medium work projects and so on
West African LionOP
o yes thanks!
happy to help