Ensure non-implicit unstable_cache tags are propagated (#52058)
This ensures we correctly pass up the non-implicit tags for `unstable_cache` so that `revalidateTag` can be triggered for ISR paths properly. x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1687900021175649)
This commit is contained in:
parent
23890fb2c9
commit
934a7da4d7
3 changed files with 25 additions and 1 deletions
|
@ -64,6 +64,17 @@ export function unstable_cache<T extends Callback>(
|
|||
(await incrementalCache?.get(cacheKey, true, options.revalidate))
|
||||
|
||||
const tags = options.tags || []
|
||||
|
||||
if (Array.isArray(tags) && store) {
|
||||
if (!store.tags) {
|
||||
store.tags = []
|
||||
}
|
||||
for (const tag of tags) {
|
||||
if (!store.tags.includes(tag)) {
|
||||
store.tags.push(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
const implicitTags = addImplicitTags(store)
|
||||
|
||||
for (const tag of implicitTags) {
|
||||
|
|
|
@ -34,6 +34,19 @@ createNextDescribe(
|
|||
}
|
||||
})
|
||||
|
||||
if (isNextStart) {
|
||||
it('should propagate unstable_cache tags correctly', async () => {
|
||||
const meta = JSON.parse(
|
||||
await next.readFile(
|
||||
'.next/server/app/variable-revalidate/revalidate-360-isr.meta'
|
||||
)
|
||||
)
|
||||
expect(meta.headers['x-next-cache-tags']).toContain(
|
||||
'unstable_cache_tag1'
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
it('should correctly include headers instance in cache key', async () => {
|
||||
const res = await next.fetch('/variable-revalidate/headers-instance')
|
||||
expect(res.status).toBe(200)
|
||||
|
|
|
@ -28,7 +28,7 @@ export default async function Page() {
|
|||
},
|
||||
['random'],
|
||||
{
|
||||
tags: ['thankyounext'],
|
||||
tags: ['thankyounext', 'unstable_cache_tag1'],
|
||||
revalidate: 10,
|
||||
}
|
||||
)()
|
||||
|
|
Loading…
Reference in a new issue