A Page that fetches data from route handler rendered as SSR, but route handler rendered as Static.
Answered
Plott Hound posted this in #help-forum
Plott HoundOP
I'm trying to use SSR fetch/rendering for a page by using cache: 'no-store', when i build the page is correctly flagged as λ. But the route handler is being rendered as static ○ /api/routines. This results in the page never updating when i modify the data. it only changes when i run a build. What am i doing wrong? Thanks
Answered by joulev
To answer your question, add export const revalidate = 0 to that route handler.
That being said, [don’t fetch route handlers in server components](https://nextjs-faq.com/fetch-api-in-rsc)
That being said, [don’t fetch route handlers in server components](https://nextjs-faq.com/fetch-api-in-rsc)
14 Replies
@Plott Hound I'm trying to use SSR fetch/rendering for a page by using cache: 'no-store', when i build the page is correctly flagged as λ. But the route handler is being rendered as static ○ /api/routines. This results in the page never updating when i modify the data. it only changes when i run a build. What am i doing wrong? Thanks
To answer your question, add export const revalidate = 0 to that route handler.
That being said, [don’t fetch route handlers in server components](https://nextjs-faq.com/fetch-api-in-rsc)
That being said, [don’t fetch route handlers in server components](https://nextjs-faq.com/fetch-api-in-rsc)
Answer
@joulev To answer your question, add export const revalidate = 0 to that route handler.
That being said, [don’t fetch route handlers in server components](<https://nextjs-faq.com/fetch-api-in-rsc>)
Plott HoundOP
thank you. I just tried 'export const dynamic = 'force-dynamic';' and it rendered as SSR. is revalidate = 0 a better approach? thanks for replying, reading the article now
@Plott Hound thank you. I just tried 'export const dynamic = 'force-dynamic';' and it rendered as SSR. is revalidate = 0 a better approach? thanks for replying, reading the article now
revalidate = 0 is slightly better because force-dynamic will force all fetches and queries in that handler to be dynamic, including the ones that explicitly opts into static fetching
Plott HoundOP
the article you shared is very helpful. I'm also using prisma and fetching my own endpoint in a server component. thanks so much!
@joulev To answer your question, add export const revalidate = 0 to that route handler.
That being said, [don’t fetch route handlers in server components](<https://nextjs-faq.com/fetch-api-in-rsc>)
Plott HoundOP
I tried to implement the method suggested in your link but I can't get it to use SSR fetching, I have to rebuild everytime the page changes.
@Plott Hound I tried to implement the method suggested in your link but I can't get it to use SSR fetching, I have to rebuild everytime the page changes.
Add the export const revalidate = 0 to the page
Plott HoundOP
thank you, final question i promise!! Is that the equivalent of export const revalidate = false;
@Plott Hound thank you, final question i promise!! Is that the equivalent of export const revalidate = false;
No they are not the same. revalidate = false is the default value where it tries to cache everything including your prisma query
revalidate = 0 is the polar opposite
Yeah both are falsy values but they are opposite
Plott HoundOP
I can;t thank you enough, you a re a true hero! lifesaver
@joulev Yeah both are falsy values but they are opposite
Now that I think about it it makes no sense but well it is what it is :P
@Plott Hound I can;t thank you enough, you a re a true hero! lifesaver
You’re welcome, have fun coding
Plott HoundOP
you have an awesome day and thank you again!!!