Russ
03/23/2022, 5:03 AMNextjsSite
construct.
A key use case for us is the ability to handle Incremental Static Regeneration, which is listed as one of the supported features.
I have a simple NextJS site setup that has a page with a dynamic route configured (ie /test/[id]
) and the following for getStaticPaths
and getStaticProps
-
export const getStaticProps: GetStaticProps = async () => {
return {
props: {
date: new Date().toString(),
},
revalidate: 10,
};
};
export const getStaticPaths: GetStaticPaths = async () => ({
paths: [],
fallback: true,
});
The page simply displays the date.
When running NextJS locally it behaves as expected; none of the pages are generated at build time, when you access a page you receive the same date for up to 10 seconds before it is re-validated and you receive a new date.
However when I deploy to AWS the date for the page never changes after the initial generation. It stays the same.
The headers are showing a CloudFront miss, and I can see the behaviour for the data
route has a lambda configured. However I am unable to view logs for that lambda as there doesn't seem to be any log group that has been created, so I can't really tell if it's even being called.
Any ideas?
I am running Next 12.
Thanks!Derek Kershner
03/23/2022, 2:07 PMDerek Kershner
03/23/2022, 2:12 PMfallback
to blocking
instead of true. This is unlikely to solve it, but perhaps worth a troubleshooting step.Derek Kershner
03/23/2022, 2:45 PMfallback: "blocking"
.Derek Kershner
03/23/2022, 2:46 PMDerek Kershner
03/23/2022, 2:48 PMDerek Kershner
03/23/2022, 2:48 PMFrank
Derek Kershner
03/23/2022, 5:13 PMDerek Kershner
03/23/2022, 5:18 PM"next": "^12.1.0",
Russ
03/23/2022, 10:06 PMRuss
03/25/2022, 6:27 AMfallback: "blocking"
and re-deployed, now the site was acting as expected; and as you described.
I could request a page and it would be generated, then another request after the revalidate
period would return the same page, but a subsequent refresh would show the newly generated date.
I checked SQS and could see messages being processed.
I swapped back to fallback: true
and re-deployed, and it this actually now appears to work as well, except one page of my 3 doesn't update, a little strange. I will investigate further to see what is going on there.
Have you experimented with the new On-Demand Revalidation feature introduced in Next 12.1?
https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration#using-on-demand-revalidation
In the code it appears to just call the page URL with a special header to trigger regeneration -
https://github.com/vercel/next.js/blob/57702cb2a9a9dba4b552e0007c16449cf36cfb44/packages/next/server/api-utils/node.ts#L310-L329
I'm hoping this may "just work" if the api route just calls the page route, which triggers the regenerate lambda which should include the relevant code? Or am I over simplifying things, haha.
This is an important use case for me, we have a data set that has critical information in it that needs to be accurate.
A situation where a page hasn't been accessed for some time (perhaps an hour) and a user receives a stale version is not really acceptable for our implementation.
I guess the alternative is that we just go full SSR with these pages and adjust caching for them to take some heat of the lambda in high load.Derek Kershner
03/26/2022, 4:20 PMHave you experimented with the new On-Demand Revalidation feature introduced in Next 12.1?I have not, but I also am hoping it will “just work”.
Derek Kershner
03/26/2022, 4:21 PM