我有一个带有API端点的Next应用程序,用于编辑资源(使用基于页面的系统,而不是基于应用程序的系统).除了在编辑资源后,当我go 查看(或重新编辑)它时,我看到的是旧版本之外,一切都很好.
在查阅了文档后,我似乎可以使用revalidatePath
告诉NEXT来清除该路由的缓存.然而,当我try 使用它时,就像这样:
// pages/api/resource.js
const handler = async (request, response) => {
const id = await saveStuff(request);
revalidatePath(`/resource/[name]`);
revalidatePath(`/resource/[name]/edit`);
response.send(JSON.stringify({ id }));
}
我得到一个关于completely different函数的错误:revalidateTag
.
> Error: Invariant: static generation store missing in revalidateTag
> /resource/[name]
> at revalidateTag (/home/me/project/next/node_modules/next/dist/server/web/spec-extension/revalidate-tag.js:15:15)
> at revalidatePath (/home/me/project/next/node_modules/next/dist/server/web/spec-extension/revalidate-path.js:13:45)
> at handler (webpack-internal:///(api)/./pages/api/resource.js:83:67)
> at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
我以前从来没有用过revalidatePath
,所以我可能不知何故用错了,但我不知道我可以做什么来导致这个错误.或者,如果有其他机制可以强制NeXT清除特定页面的缓存,这也会很有帮助.
EDIT:个
我查看了源代码,似乎有revalidatePath
个调用revalidateTag
(以路径为标记).错误来自以下代码的末尾:
function revalidateTag(tag) {
const staticGenerationAsyncStorage = fetch.__nextGetStaticStore == null ? void 0 : fetch.__nextGetStaticStore();
const store = staticGenerationAsyncStorage == null ? void 0 : staticGenerationAsyncStorage.getStore();
if (!store || !store.incrementalCache) {
throw new Error(`Invariant: static generation store missing in revalidateTag ${tag}`);
}
换句话说,看起来fetch
上没有staticGenerationAsyncStorage
,这表明Next还没有修补功能.但是这段代码是从API路由函数调用的,所以看起来NeXT应该已经有机会修补fetch
了?