Serverless function runs right after edge middleware is invoked, overriding built-time data
Answered
Morelet’s Crocodile posted this in #help-forum
Morelet’s CrocodileOP
Hi all, I'm running a content focused website for my company using sanity for cms (with groqd for type-safe query building) and next-intl for i18n.
Since going live I saw that the sanity api request bill is racking up even though I've set the request to sanity to be cached.
Checking out the logs on vercel's dashboard. I noticed that it runs the serverless function again right after everytime the middleware cached is invoked and call the data from sanity again. This is different from what how it is in the POC project I mocked up with similar packages where only the middleware is called and there's no additional request to sanity
Have anyone ran into this sort of issue? I would really appreciate the help. Thanks in advance
Since going live I saw that the sanity api request bill is racking up even though I've set the request to sanity to be cached.
Checking out the logs on vercel's dashboard. I noticed that it runs the serverless function again right after everytime the middleware cached is invoked and call the data from sanity again. This is different from what how it is in the POC project I mocked up with similar packages where only the middleware is called and there's no additional request to sanity
Have anyone ran into this sort of issue? I would really appreciate the help. Thanks in advance
Answered by Morelet’s Crocodile
I've cracked it, I created a brand new route and render a
new Date()
on the server and it persisted. After that I added the metadata by using the generateMetadata
and it started to render a new date every few refresh. Now I just need to see how to remedy it.5 Replies
Sounds like your pages do not get statically generated as they are supposed to. Are you using cookies, headers or search parameters some place?
And for next-intl you need to use their
unstable_setRequestLocale
Function in both layout.tsx and page.tsx files. Otherwise they will be serverside rendered
And for next-intl you need to use their
unstable_setRequestLocale
Function in both layout.tsx and page.tsx files. Otherwise they will be serverside rendered
Morelet’s CrocodileOP
The build output is shown like this so it should mean the page is ssg right?
As for next-intl, I'm using
There are some logic in the middleware to get and set a few cookies, I tried commenting them out but it still runs the serverless function.
As for next-intl, I'm using
unstable_setRequestLocale
in layout.tsx
, page.tsx
and faq/page.tsx
There are some logic in the middleware to get and set a few cookies, I tried commenting them out but it still runs the serverless function.
here's the build output
Hmm. Try setting the dynamic const to "force-static" on your pages and layouts. And see if it is better
Morelet’s CrocodileOP
I've cracked it, I created a brand new route and render a
new Date()
on the server and it persisted. After that I added the metadata by using the generateMetadata
and it started to render a new date every few refresh. Now I just need to see how to remedy it.Answer