What exactly does `unstable_noStore` do?

I'm developing on the t3 stack with clerk as the auth. When I try to call one of my protected endpoints, I get the following error when building
[cause]: a [Error]: Dynamic server usage: Page couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
[cause]: a [Error]: Dynamic server usage: Page couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
I don't really understand why this error occurs when only the auth method is being used from Clerk in the trpc context, but using unstable_nostore in the components that do call the endpoints, fixes this issue. Does anyone know what exactly is going on here?
1 Reply
Matvey
Matvey10mo ago
By default Nextjs wants to cache all responses, but if the endpoint requires auth it can't cache it (or it might expose cached the data to a wrong/not authed user). If you put noStore() it tells Next to never cache this endpoint or server component.
Want results from more Discord servers?
Add your server