Unverified Commit 60c984bf authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure only one tags manifest is leveraged across handlers (#71522)

This ensures even if there are multiple module instances of the
tags-manifest module we have one global tags manifest in memory that is
used as the source of truth to prevent drift from revalidateTag and
various cache handlers.
parent 4b364ca9
......@@ -4,7 +4,10 @@
*/
import { LRUCache } from '../lru-cache'
import type { CacheEntry, CacheHandler } from './types'
import { isTagStale, tagsManifest } from '../incremental-cache/tags-manifest'
import {
isTagStale,
tagsManifest,
} from '../incremental-cache/tags-manifest.external'
type PrivateCacheEntry = {
entry: CacheEntry
......
......@@ -18,7 +18,7 @@ import {
RSC_SEGMENTS_DIR_SUFFIX,
RSC_SUFFIX,
} from '../../../lib/constants'
import { tagsManifest } from './tags-manifest'
import { tagsManifest } from './tags-manifest.external'
type FileSystemCacheContext = Omit<
CacheHandlerContext,
......
'use server'
import { revalidateTag } from 'next/cache'
export async function revalidateWithTag(tag) {
revalidateTag(tag)
return 'done'
}
'use client'
import { useRouter } from 'next/navigation'
import React from 'react'
import { revalidateWithTag } from './actions'
export function RevalidateButtons() {
const router = useRouter()
return (
<>
<button
id="revalidate-a"
onClick={() => {
revalidateWithTag('a').then(() => router.refresh())
}}
>
revalidate a
</button>
<button
id="revalidate-b"
onClick={() => {
revalidateWithTag('b').then(() => router.refresh())
}}
>
revalidate b
</button>
<button
id="revalidate-c"
onClick={() => {
revalidateWithTag('c').then(() => router.refresh())
}}
>
revalidate c
</button>
</>
)
}
import React from 'react'
import { unstable_cacheTag as cacheTag } from 'next/cache'
import { RevalidateButtons } from './button'
async function getCachedWithTag(tag) {
'use cache'
......@@ -11,8 +13,11 @@ export default async function Page() {
const y = await getCachedWithTag('b')
return (
<p>
{x}
{y}
<p id="x">{x}</p>
<br />
<p id="y">{y}</p>
<br />
<RevalidateButtons />
</p>
)
}
......@@ -153,6 +153,33 @@ describe('use-cache', () => {
})
})
it('should update after revalidateTag correctly', async () => {
const browser = await next.browser('/cache-tag')
const initialX = await browser.elementByCss('#x').text()
const initialY = await browser.elementByCss('#y').text()
let updatedX
let updatedY
await browser.elementByCss('#revalidate-a').click()
await retry(async () => {
updatedX = await browser.elementByCss('#x').text()
expect(updatedX).not.toBe(initialX)
})
await browser.elementByCss('#revalidate-b').click()
await retry(async () => {
updatedY = await browser.elementByCss('#y').text()
expect(updatedY).not.toBe(initialY)
})
await browser.elementByCss('#revalidate-c').click()
await retry(async () => {
expect(await browser.elementByCss('#x').text()).not.toBe(updatedX)
expect(await browser.elementByCss('#y').text()).not.toBe(updatedY)
})
})
if (isNextStart) {
it('should match the expected revalidate config on the prerender manifest', async () => {
const prerenderManifest = JSON.parse(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment