Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure non-implicit unstable_cache tags are propagated #52058

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/next/src/server/web/spec-extension/unstable-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/app-dir/app-static/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default async function Page() {
},
['random'],
{
tags: ['thankyounext'],
tags: ['thankyounext', 'unstable_cache_tag1'],
revalidate: 10,
}
)()
Expand Down