I think this is quite a vanilla question but I can't find anything on Google.
I'm learning NextJs (using TypeScript) and I've got a site successfully working with dynamic routes, SSR, and incremental regeneration all setup and deployed to Vercel. Here's an example of the GetStaticProps
and GetStaticPaths
code in my dynamic route handler:
export const getStaticPaths: GetStaticPaths = async () => {
const routes = new CmsHelper().GetRoutes();
const paths = (await routes).items.map((item, index, items) => {
return item.fields.urlPath;
})
return {
paths: paths,
fallback: 'blocking',
};
}
export const getStaticProps: GetStaticProps = async (context) => {
const urlParts = context.params?.url as string[] || [];
const urlPath = `/${urlParts.join('/')}`;
const article = await new CmsHelper().GetArticle(urlPath);
return {
props: {
article
},
revalidate: 10,
}
}
If I request a new path that was published in the cms after build time, it successfully regenerates on the server and returns the page.
So far so good.
However, if I unpublish a route in my CMS... it is still returned by the app, unless I rebuild and redeploy (or otherwise cause the process to restart, in dev).
So my question is: how do I dynamically cause NextJs to remove a dynamic route from its GetStaticPaths cache?
I understand that GetStaticProps
is going to be called at most once every 10 seconds because of the revalidate
configuration. But as far as I know, GetStaticPaths
will only be called if a request comes in from a route that is not currently cached(?)
In other words, for an integration with a headless CMS, how can I support unpublishing or renaming pages with NextJs without triggering a rebuild/deploy?
Thanks in advance!