#Cannot access session/user data from staticly generate pages in nextjs 13

20 messages · Page 1 of 1 (latest)

rancid tartan
#

I making an ecommerce site, I have made SSG product pages for faster speeds. So for the cart option we need to have cookies but generateStaticParams restricts the use of it. And I have to store user id to the cart too.

Please suggest any work around?

golden lichenBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vestal fiber
rancid tartan
#

I want to understand it for the same question I had before.

thin grotto
#

As above mentioned, it's impossible to keep it fully static.
Basically, in your use case, your app can't be fully static due to personalized data.
Then, how to keep it fast while it is a dynamic route (rendered at request time)? Cache, You can cache the product data.
Hence, you won't have to re-fetch the data every time the user enters your site.

rancid tartan
thin grotto
#

no, go to the cache section. Next.js only caches fetch by default.

rancid tartan
#

And imo, export const dynamic="auto" should perform better than other as well as giving access to dynamic functions. Please correct me if I am wrong.

thin grotto
#

No, auto is just the default behaviour. By default, your page is cached and statically generated. You can try testing it locally.

#

For now, you can’t cache third party libraries. unstable_cache is not yet stable

rancid tartan
rancid tartan
thin grotto
#

Only dynamic, you can’t cache it since you are reading cookies (as you mentioned)

#

These are dynamic functions

rancid tartan
thin grotto
#

Not encouraged because that can cause error during pre-rendering

#

When Next.js builds your app, route handlers won’t be available

golden lichenBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer