Unverified Commit 6f98e9fc authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Isolate deploy e2e revalidation scope per suite (#100718)

`revalidatePath`/`revalidateTag` invalidate cache at Vercel **project**
scope, not per deployment. Deploy e2e suites share one project per
matrix dimension, so concurrent suites could purge each other's cache
entries: `app-static` and `actions` both used the tags
`thankyounext`/`justputit`, and several suites revalidated `/`. The
deploy manifest recorded the fallout as known-failed tests.

- Prefix cache tags with their suite slug: `actions:*`, `app-static:*`,
`revalidatetag-rsc:*`, `use-cache-after-uncached-io:*`,
`use-cache-custom-handler:*`
- Move `parallel-routes-revalidation` under `/prr` and
`actions-discarded-navigation-revert` under `/adr` so no deploy-active
fixture revalidates `/`; retarget navigation's popstate-revalidate
action to its own subtree and prefetch-inlining's default revalidate
path to its own route
- Give the cache-components deploy job (`build_and_test.yml`) its own
Vercel project (`vtest314-e2e-tests-cache-components`) via a new
`VERCEL_TEST_PROJECT` override in `next-deploy.ts`, so its suites can't
interfere with the plain deploy job's suites; the weekly project-reset
cron keeps the new project fresh
- Remove the healed known-failed entries from the deploy manifest and
add the `increment to trigger deploy tests` marker so the PR deploy jobs
exercise the affected suites
- `app-static`: assert cache persistence on a suite-unique route in
deploy mode (the `/` check can still observe foreign root-layout purges
from `vary-params-base-dynamic`, whose project-wide purge is its test
subject and can't be renamed), and fix the persistence loop never
recording `prevData`

## Verification

CI

<!-- NEXT_JS_LLM -->

---------
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent 55e64de0
......@@ -949,6 +949,9 @@ jobs:
export NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json,test/cache-components-tests-manifest.json"
export NEXT_E2E_TEST_TIMEOUT=240000
export IS_TURBOPACK_TEST=1
# revalidatePath/revalidateTag invalidate at project scope, so this
# job deploys into its own project, separate from the plain deploy job.
export VERCEL_TEST_PROJECT="vtest314-e2e-tests-cache-components"
node scripts/test-new-tests.mjs \
--mode deploy \
--group ${{ matrix.group }}
......
......@@ -238,6 +238,18 @@ tail -5 /tmp/test-output.log # Summary
})
```
- **Keep `revalidatePath`/`revalidateTag` arguments and fetch URLs
suite-unique.** In deploy mode the cache lives at Vercel project scope and
deploy e2e suites share one project per matrix dimension: revalidation
purges by tag/path across the whole project, and fetch cache entries are
keyed by URL across deployments. Prefix tags with the suite slug (e.g.
`cacheTag('app-static:thankyounext')`), never revalidate `/` from a
deploy-active fixture (every app has a `/` route — move the page to a
suite-unique route and revalidate that instead), and when a test depends on
a cached value, give the data-endpoint URL suite-unique query params (e.g.
`api/random?app-static-page`) so another fixture's fetches and
revalidations cannot share or purge the entry. See `test/AGENTS.md`.
## Linting and Types
```bash
......
......@@ -21,18 +21,24 @@ const TEST_TEAMS = [
teamId: TEST_TEAM_NAME,
tokenEnvVar: 'VERCEL_TEST_TOKEN',
token: TEST_TOKEN,
extraProjects: [],
},
{
teamEnvVar: 'VERCEL_ADAPTER_TEST_TEAM',
teamId: ADAPTER_TEST_TEAM_NAME,
tokenEnvVar: 'VERCEL_ADAPTER_TEST_TOKEN',
token: ADAPTER_TEST_TOKEN,
// The cache-components deploy job in build_and_test.yml deploys into its
// own project so its revalidations cannot interfere with the plain
// deploy job's suites.
extraProjects: ['vtest314-e2e-tests-cache-components'],
},
{
teamEnvVar: 'VERCEL_TURBOPACK_TEST_TEAM',
teamId: TURBOPACK_TEST_TEAM_NAME,
tokenEnvVar: 'VERCEL_TURBOPACK_TEST_TOKEN',
token: TURBOPACK_TEST_TOKEN,
extraProjects: [],
},
]
......@@ -42,22 +48,30 @@ async function main() {
// Keep going after a failure so that one misconfigured or unreachable team
// does not stop the others from being reset. `resetProject` rejects an absent
// teamId or token itself, so this only has to say which variables to check.
for (const { teamEnvVar, teamId, tokenEnvVar, token } of TEST_TEAMS) {
try {
await resetProject({
projectName: TEST_PROJECT_NAME,
teamId,
token,
disableDeploymentProtection: true,
})
} catch (err) {
console.error(
new Error(
`Failed to reset the ${TEST_PROJECT_NAME} project for ${teamEnvVar}. Verify that ${teamEnvVar} and ${tokenEnvVar} are set correctly.`,
{ cause: err }
for (const {
teamEnvVar,
teamId,
tokenEnvVar,
token,
extraProjects,
} of TEST_TEAMS) {
for (const projectName of [TEST_PROJECT_NAME, ...extraProjects]) {
try {
await resetProject({
projectName,
teamId,
token,
disableDeploymentProtection: true,
})
} catch (err) {
console.error(
new Error(
`Failed to reset the ${projectName} project for ${teamEnvVar}. Verify that ${teamEnvVar} and ${tokenEnvVar} are set correctly.`,
{ cause: err }
)
)
)
hadFailure = true
hadFailure = true
}
}
}
......
# Test review instructions
- During code review, flag any change that newly disables, skips, or omits deploy-mode tests or assertions, including `skipDeployment: true` and `isNextDeploy` conditionals. Only allow this when the assertion is inherently specific to self-hosted behavior; even then, prefer an explicit deploy-mode assertion that documents the different deployed semantics.
- During code review, flag any new hardcoded cache tag or any `revalidatePath('/')` (including `('/', 'layout')`) in a deploy-active fixture. Revalidation invalidates at Vercel project scope and every deploy suite shares one project per matrix dimension, so suites using the same tag or path purge each other's cache. Tags (`cacheTag`/`revalidateTag`/`updateTag`/`next.tags`) get a suite-slug prefix, e.g. `app-static:thankyounext`. Paths must name a real route, so a fixture that needs to revalidate `/` moves its page to a suite-unique route first (see `parallel-routes-revalidation`'s `/prr`). A revalidation route handler that takes the tag/path from a request parameter is fine as long as the values the tests pass are suite-unique.
- During code review, flag any fetch URL a fixture shares with another fixture when a test depends on the cached value. Fetch cache entries are keyed by URL across deployments, so two fixtures fetching the same URL share one entry, and either fixture's writes or revalidations change the value the other sees. Give the data endpoint suite-unique query params, e.g. `api/random?app-static-page` instead of `api/random?page`.
......@@ -69,8 +69,7 @@
},
"test/e2e/app-dir/app-static/app-static.test.ts": {
"failed": [
"app-dir static/dynamic handling new tags have been specified on subsequent fetch should not fetch from memory cache",
"app-dir static/dynamic handling new tags have been specified on subsequent fetch should not fetch from memory cache after revalidateTag is used"
"app-dir static/dynamic handling new tags have been specified on subsequent fetch should not fetch from memory cache"
]
},
"test/e2e/app-dir/metadata/metadata.test.ts": {
......
......@@ -16,7 +16,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
options?: { allowErrorStatusCodes: number[] }
) {
let page: Playwright.Page
const browser = await next.browser('/', {
const browser = await next.browser('/adr', {
beforePageLoad(p: Playwright.Page) {
page = p
},
......@@ -67,8 +67,8 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
// If B ran too early, it saw the pre-navigation page — but that is not
// necessarily visible yet. Running one more action makes it visible:
// with the bug, the URL flips back to "/" here instead of staying
// on /dest.
// with the bug, the URL flips back to "/adr" here instead of staying
// on /adr/dest.
await act(
async () => {
await browser.elementById('dispatch-c').click()
......@@ -77,7 +77,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
)
await browser.waitForElementByCss('#status-c[data-status="c-result"]')
expect(new URL(await browser.url()).pathname).toBe('/dest')
expect(new URL(await browser.url()).pathname).toBe('/adr/dest')
expect(await browser.elementById('dest').text()).toBe('Destination page')
return { browser, initialRender }
......@@ -113,7 +113,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
// entirely — the URL never even changed to the navigation target.)
it('runs an action dispatched during the navigation once it finishes', async () => {
let page: Playwright.Page
const browser = await next.browser('/', {
const browser = await next.browser('/adr', {
beforePageLoad(p: Playwright.Page) {
page = p
},
......@@ -149,7 +149,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
)
await browser.waitForElementByCss('#status-b[data-status="b-result"]')
expect(new URL(await browser.url()).pathname).toBe('/dest')
expect(new URL(await browser.url()).pathname).toBe('/adr/dest')
expect(await browser.elementById('dest').text()).toBe('Destination page')
})
......@@ -159,7 +159,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
// further interaction.
it('renders the state produced by an action that settles after the navigation', async () => {
let page: Playwright.Page
const browser = await next.browser('/', {
const browser = await next.browser('/adr', {
beforePageLoad(p: Playwright.Page) {
page = p
},
......@@ -202,7 +202,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
await browser.waitForElementByCss(
`#stamp:not([data-render="${initialRender}"])`
)
expect(new URL(await browser.url()).pathname).toBe('/dest')
expect(new URL(await browser.url()).pathname).toBe('/adr/dest')
expect(await browser.elementById('dest').text()).toBe('Destination page')
})
......@@ -214,7 +214,7 @@ describe('discarded action settling while a navigation is pending (#86151)', ()
await browser.waitForElementByCss(
`#stamp:not([data-render="${initialRender}"])`
)
expect(new URL(await browser.url()).pathname).toBe('/dest')
expect(new URL(await browser.url()).pathname).toBe('/adr/dest')
expect(await browser.elementById('dest').text()).toBe('Destination page')
})
})
......@@ -11,6 +11,6 @@ export async function reject() {
}
export async function revalidate() {
revalidatePath('/', 'layout')
revalidatePath('/adr', 'layout')
return 'revalidated'
}
......@@ -83,7 +83,7 @@ export function Controls() {
<button id="dispatch-b-revalidate" onClick={dispatchBRevalidate}>
dispatch revalidating queued action
</button>
<button id="go-dest" onClick={() => router.push('/dest')}>
<button id="go-dest" onClick={() => router.push('/adr/dest')}>
go to destination
</button>
<button id="dispatch-c" onClick={dispatchC}>
......
// increment to trigger deploy tests: v1
process.env.TEST_NODE_MIDDLEWARE = 'true'
require('./app-action.test')
......@@ -13,6 +13,7 @@ import { join } from 'node:path'
const GENERIC_RSC_ERROR =
'Error: Minified React error #441; visit https://react.dev/errors/441 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.'
// increment to trigger deploy tests: v1
describe('app-dir action handling', () => {
const { next, isNextDev, isNextStart, isNextDeploy, isTurbopack } =
nextTestSetup({
......
......@@ -5,9 +5,9 @@ import Link from 'next/link'
export default async function Page() {
const randomCookie = (await cookies()).get('random')
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?page',
'https://next-data-api-endpoint.vercel.app/api/random?actions-page',
{
next: { revalidate: 3600, tags: ['thankyounext'] },
next: { revalidate: 3600, tags: ['actions:thankyounext'] },
}
).then((res) => res.text())
......@@ -19,14 +19,15 @@ export default async function Page() {
</Link>
<p>
{' '}
revalidate (tags: thankyounext): <span id="thankyounext">{data}</span>
revalidate (tags: actions:thankyounext):{' '}
<span id="thankyounext">{data}</span>
</p>
<form>
<button
id="revalidate-tag"
formAction={async () => {
'use server'
updateTag('thankyounext')
updateTag('actions:thankyounext')
}}
>
revalidate thankyounext
......
......@@ -2,16 +2,16 @@ import { updateTag } from 'next/cache'
export default async function Page() {
const data1 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?a',
'https://next-data-api-endpoint.vercel.app/api/random?actions-a',
{
next: { tags: ['thankyounext'] },
next: { tags: ['actions:thankyounext'] },
}
).then((res) => res.text())
const data2 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?b',
'https://next-data-api-endpoint.vercel.app/api/random?actions-b',
{
next: { tags: ['justputit'] },
next: { tags: ['actions:justputit'] },
}
).then((res) => res.text())
......@@ -19,18 +19,20 @@ export default async function Page() {
<>
<h1 id="title">another route</h1>
<p>
revalidate (tags: thankyounext): <span id="thankyounext">{data1}</span>
revalidate (tags: actions:thankyounext):{' '}
<span id="thankyounext">{data1}</span>
</p>
<p>
revalidate (tags: justputit): <span id="justputit">{data2}</span>
revalidate (tags: actions:justputit):{' '}
<span id="justputit">{data2}</span>
</p>
<form>
<button
id="revalidate"
formAction={async () => {
'use server'
updateTag('thankyounext')
updateTag('justputit')
updateTag('actions:thankyounext')
updateTag('actions:justputit')
}}
>
revalidate thankyounext
......
......@@ -8,16 +8,19 @@ import RedirectClientComponent from './client'
export default async function Page() {
const cookie = (await cookies()).get('random')
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?page',
'https://next-data-api-endpoint.vercel.app/api/random?actions-page',
{
next: { revalidate: 3600, tags: ['thankyounext'] },
next: { revalidate: 3600, tags: ['actions:thankyounext'] },
}
).then((res) => res.text())
const data2 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?a=b',
'https://next-data-api-endpoint.vercel.app/api/random?actions-a=b',
{
next: { revalidate: 3600, tags: ['thankyounext', 'justputit'] },
next: {
revalidate: 3600,
tags: ['actions:thankyounext', 'actions:justputit'],
},
}
).then((res) => res.text())
......@@ -26,9 +29,8 @@ export default async function Page() {
<h1 id="title">revalidate</h1>
<p>
{' '}
revalidate (tags: thankyounext): <span id="thankyounext">
{data}
</span>{' '}
revalidate (tags: actions:thankyounext):{' '}
<span id="thankyounext">{data}</span>{' '}
<span>
<Link href="/revalidate-2" id="another">
/revalidate-2
......@@ -36,7 +38,7 @@ export default async function Page() {
</span>
</p>
<p>
revalidate (tags: thankyounext, justputit):{' '}
revalidate (tags: actions:thankyounext, actions:justputit):{' '}
<span id="justputit">{data2}</span>
</p>
<p>
......@@ -59,7 +61,7 @@ export default async function Page() {
id="revalidate-thankyounext"
formAction={async () => {
'use server'
updateTag('thankyounext')
updateTag('actions:thankyounext')
}}
>
revalidate thankyounext
......@@ -70,7 +72,7 @@ export default async function Page() {
id="revalidate-justputit"
formAction={async () => {
'use server'
updateTag('justputit')
updateTag('actions:justputit')
}}
>
revalidate justputit
......@@ -92,7 +94,7 @@ export default async function Page() {
id="revalidate-path-redirect"
formAction={async () => {
'use server'
updateTag('justputit')
updateTag('actions:justputit')
redirect('/revalidate')
}}
>
......@@ -115,7 +117,7 @@ export default async function Page() {
id="redirect-revalidate"
formAction={async () => {
'use server'
updateTag('justputit')
updateTag('actions:justputit')
redirect('/revalidate?foo=bar')
}}
>
......@@ -125,7 +127,7 @@ export default async function Page() {
<RedirectClientComponent
action={async () => {
'use server'
updateTag('justputit')
updateTag('actions:justputit')
}}
/>
</>
......
......@@ -15,6 +15,7 @@ import stripAnsi from 'strip-ansi'
const glob = promisify(globOrig)
// increment to trigger deploy tests: v1
describe('app-dir static/dynamic handling', () => {
const { next, isNextDev, isNextStart, isNextDeploy, isTurbopack } =
nextTestSetup({
......@@ -172,7 +173,7 @@ describe('app-dir static/dynamic handling', () => {
expect(res1.status).toBe(200)
const revalidateRes = await next.fetch(
'/api/revalidate-tag-node?tag=thankyounext'
'/api/revalidate-tag-node?tag=app-static:thankyounext'
)
expect((await revalidateRes.json()).revalidated).toBe(true)
......@@ -553,7 +554,7 @@ describe('app-dir static/dynamic handling', () => {
await check(async () => {
const revalidateRes = await next.fetch(
`${revalidateApi}?tag=thankyounext`
`${revalidateApi}?tag=app-static:thankyounext`
)
expect((await revalidateRes.json()).revalidated).toBe(true)
......@@ -610,8 +611,8 @@ describe('app-dir static/dynamic handling', () => {
if (prevData) {
expect(prevData).toBe(data)
prevData = data
}
prevData = data
await waitFor(500)
}
......@@ -622,6 +623,32 @@ describe('app-dir static/dynamic handling', () => {
}
})
if (isNextDeploy) {
// Deploy fixtures share one Vercel project, and revalidation is
// project-scoped: another suite revalidating `/` purges this
// deployment's `/` as well, so the test above can observe foreign
// purges. Assert persistence on a suite-unique route too, which no
// other suite's revalidation targets.
it('should not revalidate suite-unique routes when revalidate is not used', async () => {
let prevData
for (let i = 0; i < 5; i++) {
const res = await next.fetch('/variable-revalidate/revalidate-360')
const html = await res.text()
const $ = cheerio.load(html)
const data = $('#page-data').text()
expect(res.status).toBe(200)
if (prevData) {
expect(prevData).toBe(data)
}
prevData = data
await waitFor(500)
}
})
}
it.each([
{
type: 'edge route handler',
......@@ -2577,7 +2604,7 @@ describe('app-dir static/dynamic handling', () => {
"initialExpireSeconds": 31536000,
"initialHeaders": {
"content-type": "application/json",
"x-next-cache-tags": "_N_T_/layout,_N_T_/route-handler/layout,_N_T_/route-handler/revalidate-360-isr/layout,_N_T_/route-handler/revalidate-360-isr/route,_N_T_/route-handler/revalidate-360-isr,thankyounext",
"x-next-cache-tags": "_N_T_/layout,_N_T_/route-handler/layout,_N_T_/route-handler/revalidate-360-isr/layout,_N_T_/route-handler/revalidate-360-isr/route,_N_T_/route-handler/revalidate-360-isr,app-static:thankyounext",
},
"initialRevalidateSeconds": 10,
"response": "complete",
......@@ -3476,7 +3503,7 @@ describe('app-dir static/dynamic handling', () => {
expect(indexFetchMetrics).toHaveLength(1)
expect(indexFetchMetrics[0]).toMatchObject({
url: 'https://next-data-api-endpoint.vercel.app/api/random?page',
url: 'https://next-data-api-endpoint.vercel.app/api/random?app-static-page',
status: 200,
cacheStatus: expect.any(String),
start: expect.any(Number),
......@@ -5036,14 +5063,24 @@ describe('app-dir static/dynamic handling', () => {
describe('unstable_cache', () => {
it('should retrieve the same value on second request', async () => {
const res = await next.fetch('/unstable-cache/dynamic')
const html = await res.text()
const data = cheerio.load(html)('#cached-data').text()
const res2 = await next.fetch('/unstable-cache/dynamic')
const html2 = await res2.text()
const data2 = cheerio.load(html2)('#cached-data').text()
async function fetchCachedData() {
const res = await next.fetch('/unstable-cache/dynamic')
return cheerio
.load(await res.text())('#cached-data')
.text()
}
expect(data).toEqual(data2)
if (isNextDeploy) {
// The shared Data Cache is eventually consistent across lambda
// instances: a request can land before another instance's write is
// visible and recompute. Poll until two consecutive reads agree,
// which is the consistency the deployed cache provides.
await retry(async () => {
expect(await fetchCachedData()).toEqual(await fetchCachedData())
})
} else {
expect(await fetchCachedData()).toEqual(await fetchCachedData())
}
})
it('should bypass cache in draft mode', async () => {
......
......@@ -4,7 +4,7 @@ export default async function Page() {
console.log('rendering index')
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?page'
'https://next-data-api-endpoint.vercel.app/api/random?app-static-page'
).then((res) => res.text())
return (
......
......@@ -9,7 +9,7 @@ export async function GET() {
{
next: {
revalidate: 360,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
},
}
).then((res) => res.text())
......@@ -19,7 +19,7 @@ export async function GET() {
{
next: {
revalidate: 10,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
},
}
).then((res) => res.text())
......
......@@ -8,7 +8,7 @@ export async function GET() {
{
next: {
revalidate: 360,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
},
}
).then((res) => res.text())
......@@ -18,7 +18,7 @@ export async function GET() {
{
next: {
revalidate: 10,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
},
}
).then((res) => res.text())
......
......@@ -8,7 +8,7 @@ export async function GET() {
{
next: {
revalidate: 360,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
},
}
).then((res) => res.text())
......@@ -18,7 +18,7 @@ export async function GET() {
{
next: {
revalidate: 10,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
},
}
).then((res) => res.text())
......
......@@ -5,7 +5,7 @@ export default async function Page() {
'https://next-data-api-endpoint.vercel.app/api/random?sam=iam',
{
cache: 'force-cache',
next: { tags: ['thankyounext'] },
next: { tags: ['app-static:thankyounext'] },
}
).then((res) => res.text())
......
......@@ -5,7 +5,7 @@ export default async function Page() {
'https://next-data-api-endpoint.vercel.app/api/random?sam=iam',
{
cache: 'force-cache',
next: { tags: ['thankyounext', 'justputit'] },
next: { tags: ['app-static:thankyounext', 'app-static:justputit'] },
}
).then((res) => res.text())
......
......@@ -3,7 +3,7 @@ import { cache, use } from 'react'
export default function Layout({ children }) {
const getData = cache(() =>
fetch('https://next-data-api-endpoint.vercel.app/api/random?layout', {
next: { revalidate: 10, tags: ['thankyounext'] },
next: { revalidate: 10, tags: ['app-static:thankyounext'] },
}).then((res) => res.text())
)
const dataPromise = getData()
......
......@@ -2,16 +2,19 @@ import { unstable_cache } from 'next/cache'
export default async function Page() {
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?page',
'https://next-data-api-endpoint.vercel.app/api/random?app-static-page',
{
next: { revalidate: 360, tags: ['thankyounext'] },
next: { revalidate: 360, tags: ['app-static:thankyounext'] },
}
).then((res) => res.text())
const data2 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?a=b',
'https://next-data-api-endpoint.vercel.app/api/random?app-static-a=b',
{
next: { revalidate: 360, tags: ['thankyounext', 'justputit'] },
next: {
revalidate: 360,
tags: ['app-static:thankyounext', 'app-static:justputit'],
},
}
).then((res) => res.text())
......@@ -28,7 +31,7 @@ export default async function Page() {
},
['random'],
{
tags: ['thankyounext', 'unstable_cache_tag1'],
tags: ['app-static:thankyounext', 'unstable_cache_tag1'],
revalidate: 10,
}
)()
......@@ -36,12 +39,16 @@ export default async function Page() {
return (
<>
<p id="page">/variable-revalidate/revalidate-360</p>
<p id="page-data">revalidate 360 (tags: thankyounext): {data}</p>
<p id="page-data">
revalidate 360 (tags: app-static:thankyounext): {data}
</p>
<p id="page-data2">
revalidate 360 (tags: thankyounext, justputit): {data2}
revalidate 360 (tags: app-static:thankyounext, app-static:justputit):{' '}
{data2}
</p>
<p id="page-data3">
revalidate 10 (tags: thankyounext): {JSON.stringify(cachedData)}
revalidate 10 (tags: app-static:thankyounext):{' '}
{JSON.stringify(cachedData)}
</p>
<p id="now">{Date.now()}</p>
</>
......
......@@ -4,16 +4,19 @@ export const revalidate = 0
export default async function Page() {
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?page',
'https://next-data-api-endpoint.vercel.app/api/random?app-static-page',
{
next: { revalidate: 360, tags: ['thankyounext'] },
next: { revalidate: 360, tags: ['app-static:thankyounext'] },
}
).then((res) => res.text())
const data2 = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?a=b',
'https://next-data-api-endpoint.vercel.app/api/random?app-static-a=b',
{
next: { revalidate: 360, tags: ['thankyounext', 'justputit'] },
next: {
revalidate: 360,
tags: ['app-static:thankyounext', 'app-static:justputit'],
},
}
).then((res) => res.text())
......@@ -49,7 +52,7 @@ export default async function Page() {
},
['random'],
{
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
revalidate: 10,
}
)()
......@@ -60,7 +63,7 @@ export default async function Page() {
const data = await fetch(
'https://next-data-api-endpoint.vercel.app/api/random?something',
{
next: { revalidate: 15, tags: ['thankyounext'] },
next: { revalidate: 15, tags: ['app-static:thankyounext'] },
}
).then((res) => res.text())
return data
......@@ -77,19 +80,23 @@ export default async function Page() {
[],
{
revalidate: 1000,
tags: ['thankyounext'],
tags: ['app-static:thankyounext'],
}
)()
return (
<>
<p id="page">/variable-revalidate/revalidate-360</p>
<p id="page-data">revalidate 360 (tags: thankyounext): {data}</p>
<p id="page-data">
revalidate 360 (tags: app-static:thankyounext): {data}
</p>
<p id="page-data2">
revalidate 360 (tags: thankyounext, justputit): {data2}
revalidate 360 (tags: app-static:thankyounext, app-static:justputit):{' '}
{data2}
</p>
<p id="page-data3">
revalidate 10 (tags: thankyounext): {JSON.stringify(cachedData)}
revalidate 10 (tags: app-static:thankyounext):{' '}
{JSON.stringify(cachedData)}
</p>
<p id="now">{Date.now()}</p>
<p id="nested-cache">nested cache: {cacheOuter}</p>
......
......@@ -3,6 +3,6 @@
import { revalidatePath } from 'next/cache'
export async function action() {
revalidatePath('/', 'layout')
revalidatePath('/popstate-revalidate', 'layout')
return true
}
import React from 'react'
export default function Root({
children,
dialog,
interception,
}: {
children: React.ReactNode
dialog: React.ReactNode
interception: React.ReactNode
}) {
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<head>
<script src="https://cdn.tailwindcss.com?plugins=typography"></script>
</head>
<body>
{children}
{dialog}
{interception}
</body>
<body>{children}</body>
</html>
)
}
......@@ -15,7 +15,7 @@ export default function Page() {
<button onClick={() => router.refresh()} id="refresh-router">
Refresh Router
</button>
<Link href="/">Close</Link>
<Link href="/prr">Close</Link>
</dialog>
)
}
......@@ -9,7 +9,7 @@ export default function Page() {
await addData(new Date().toISOString())
revalidatePath('/', 'layout')
revalidatePath('/prr', 'layout')
}
return (
......@@ -24,7 +24,7 @@ export default function Page() {
</button>
</form>
<Link href="/">Close</Link>
<Link href="/prr">Close</Link>
</dialog>
)
}
......@@ -20,10 +20,10 @@ export async function redirectAction() {
'use server'
console.log('redirecting...')
await new Promise((res) => setTimeout(res, 1000))
redirect('/')
redirect('/prr')
}
export async function clearData() {
data = []
revalidatePath('/')
revalidatePath('/prr')
}
......@@ -3,7 +3,7 @@ import Link from 'next/link'
export default function Page() {
return (
<div>
<Link href="/catchall/foobar">Dynamic Catchall Interception</Link>
<Link href="/prr/catchall/foobar">Dynamic Catchall Interception</Link>
</div>
)
}
......@@ -13,7 +13,7 @@ export default function Layout({
<div>
<div>{children}</div>
<div>{modal}</div>
<Link href="/dynamic-refresh/foo/other">Go to Other Page</Link>
<Link href="/prr/dynamic-refresh/foo/other">Go to Other Page</Link>
</div>
)
}
......@@ -5,7 +5,7 @@ export default async function Home(props) {
const searchParams = await props.searchParams
return (
<main>
<Link href="/dynamic-refresh/foo/login">
<Link href="/prr/dynamic-refresh/foo/login">
<button>Login button</button>
</Link>
<div>
......
......@@ -3,7 +3,7 @@ import Link from 'next/link'
export default function Page() {
return (
<div>
<Link href="/dynamic/foobar">Dynamic Interception</Link>
<Link href="/prr/dynamic/foobar">Dynamic Interception</Link>
</div>
)
}
import React from 'react'
export default function PRRLayout({
children,
dialog,
interception,
}: {
children: React.ReactNode
dialog: React.ReactNode
interception: React.ReactNode
}) {
return (
<>
{children}
{dialog}
{interception}
</>
)
}
......@@ -34,7 +34,7 @@ export default function Page() {
<p className="mt-4">Drawer</p>
<div className="mt-4 flex flex-col gap-2">
<Link
href="/nested-revalidate/modal"
href="/prr/nested-revalidate/modal"
className="bg-sky-600 text-white p-2 rounded"
>
Open modal
......
......@@ -4,7 +4,7 @@ import { revalidatePath } from 'next/cache'
export async function revalidateAction() {
console.log('revalidate action')
revalidatePath('/')
revalidatePath('/prr/nested-revalidate')
return {
success: true,
}
......
......@@ -7,13 +7,13 @@ export default function Home() {
<p id="page-now">Date.now {Date.now()}</p>
<div className="flex flex-col gap-2">
<Link
href="/nested-revalidate/drawer"
href="/prr/nested-revalidate/drawer"
className="bg-sky-600 text-white p-2 rounded"
>
Open Drawer
</Link>
<Link
href="/nested-revalidate/modal"
href="/prr/nested-revalidate/modal"
className="bg-sky-600 text-white p-2 rounded"
>
Open Modal
......
......@@ -9,10 +9,10 @@ export default async function Home() {
return (
<div id="root-page">
<Link href="/revalidate-modal">Open Revalidate Modal</Link>
<Link href="/refresh-modal">Open Refresh Modal</Link>
<Link href="/redirect-modal">Open Redirect Modal</Link>
<Link href="/detail-page">Intercepted Detail Page</Link>
<Link href="/prr/revalidate-modal">Open Revalidate Modal</Link>
<Link href="/prr/refresh-modal">Open Refresh Modal</Link>
<Link href="/prr/redirect-modal">Open Redirect Modal</Link>
<Link href="/prr/detail-page">Intercepted Detail Page</Link>
<div id="random-number">{randomNumber}</div>
<form action={clearData}>
<button id="clear-entries">Clear Entries</button>
......
......@@ -5,7 +5,7 @@ export default function Page() {
<form
action={async () => {
'use server'
redirect('/')
redirect('/prr')
}}
>
<button type="submit" id="redirect-page">
......
......@@ -13,7 +13,7 @@ export default function Layout({
<div>
<div>{children}</div>
<div>{modal}</div>
<Link href="/refreshing/other">Go to Other Page</Link>
<Link href="/prr/refreshing/other">Go to Other Page</Link>
</div>
)
}
......@@ -5,7 +5,7 @@ export default async function Home(props) {
const searchParams = await props.searchParams
return (
<main>
<Link href="/refreshing/login">
<Link href="/prr/refreshing/login">
<button>Login button</button>
</Link>
<div>
......
......@@ -11,10 +11,10 @@ export default function Layout({
}) {
return (
<>
<Link prefetch={false} href="/retained-search/two?value=second">
<Link prefetch={false} href="/prr/retained-search/two?value=second">
Two
</Link>
<Link prefetch={false} href="/retained-search/three?value=third">
<Link prefetch={false} href="/prr/retained-search/three?value=third">
Three
</Link>
<RefreshButton />
......
......@@ -13,13 +13,13 @@ describe('parallel-routes-revalidation', () => {
// this could hit a separate lambda instance that won't share the same reference
if (!isNextDeploy) {
it('should submit the action and revalidate the page data', async () => {
const browser = await next.browser('/')
const browser = await next.browser('/prr')
await check(() => browser.hasElementByCssSelector('#create-entry'), false)
// there shouldn't be any data yet
expect((await browser.elementsByCss('#entries li')).length).toBe(0)
await browser.elementByCss("[href='/revalidate-modal']").click()
await browser.elementByCss("[href='/prr/revalidate-modal']").click()
await check(() => browser.hasElementByCssSelector('#create-entry'), true)
......@@ -37,7 +37,7 @@ describe('parallel-routes-revalidation', () => {
expect((await browser.elementsByCss('#entries li')).length).toBe(2)
})
await browser.elementByCss("[href='/']").click()
await browser.elementByCss("[href='/prr']").click()
// following a link back to `/` should close the modal
await check(() => browser.hasElementByCssSelector('#create-entry'), false)
......@@ -47,7 +47,7 @@ describe('parallel-routes-revalidation', () => {
it('refreshes a retained slot using its original URL after multiple navigations', async () => {
let act: ReturnType<typeof createRouterAct>
const browser = await next.browser('/retained-search/one?value=first', {
const browser = await next.browser('/prr/retained-search/one?value=first', {
beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p)
},
......@@ -61,7 +61,7 @@ describe('parallel-routes-revalidation', () => {
]) {
await act(async () => {
await browser
.elementByCss(`a[href="/retained-search/${page}?value=${value}"]`)
.elementByCss(`a[href="/prr/retained-search/${page}?value=${value}"]`)
.click()
})
expect(await browser.elementById('active-page').text()).toBe(page)
......@@ -83,12 +83,12 @@ describe('parallel-routes-revalidation', () => {
})
it('should handle router.refresh() when called in a slot', async () => {
const browser = await next.browser('/')
const browser = await next.browser('/prr')
await check(() => browser.hasElementByCssSelector('#refresh-router'), false)
const currentRandomNumber = (
await browser.elementById('random-number')
).text()
await browser.elementByCss("[href='/refresh-modal']").click()
await browser.elementByCss("[href='/prr/refresh-modal']").click()
await check(() => browser.hasElementByCssSelector('#refresh-router'), true)
await browser.elementById('refresh-router').click()
......@@ -97,7 +97,7 @@ describe('parallel-routes-revalidation', () => {
return randomNumber !== currentRandomNumber
}, true)
await browser.elementByCss("[href='/']").click()
await browser.elementByCss("[href='/prr']").click()
// following a link back to `/` should close the modal
await check(() => browser.hasElementByCssSelector('#create-entry'), false)
......@@ -105,9 +105,9 @@ describe('parallel-routes-revalidation', () => {
})
it('should handle a redirect action when called in a slot', async () => {
const browser = await next.browser('/')
const browser = await next.browser('/prr')
await check(() => browser.hasElementByCssSelector('#redirect'), false)
await browser.elementByCss("[href='/redirect-modal']").click()
await browser.elementByCss("[href='/prr/redirect-modal']").click()
await check(() => browser.hasElementByCssSelector('#redirect'), true)
await browser.elementById('redirect').click()
......@@ -116,9 +116,9 @@ describe('parallel-routes-revalidation', () => {
})
it.each([
{ path: '/detail-page' },
{ path: '/dynamic/foobar', param: 'foobar' },
{ path: '/catchall/foobar', param: 'foobar' },
{ path: '/prr/detail-page' },
{ path: '/prr/dynamic/foobar', param: 'foobar' },
{ path: '/prr/catchall/foobar', param: 'foobar' },
])(
'should not trigger interception when calling router.refresh() on an intercepted route ($path)',
async (route) => {
......@@ -160,7 +160,7 @@ describe('parallel-routes-revalidation', () => {
)
it('should not trigger full page when calling router.refresh() on an intercepted route', async () => {
const browser = await next.browser('/dynamic')
const browser = await next.browser('/prr/dynamic')
await browser.elementByCss('a').click()
// we soft-navigated to the route, so it should be intercepted
......@@ -192,10 +192,10 @@ describe('parallel-routes-revalidation', () => {
})
it('should not trigger the intercepted route when lazy-fetching missing data', async () => {
const browser = await next.browser('/')
const browser = await next.browser('/prr')
// trigger the interception page
await browser.elementByCss("[href='/detail-page']").click()
await browser.elementByCss("[href='/prr/detail-page']").click()
// we should see the intercepted page
expect(await browser.elementById('detail-title').text()).toBe(
......@@ -230,10 +230,10 @@ describe('parallel-routes-revalidation', () => {
// this could hit a separate lambda instance that won't share the same reference
if (!isNextDeploy) {
it('should refresh the correct page when a server action triggers a redirect', async () => {
const browser = await next.browser('/redirect')
const browser = await next.browser('/prr/redirect')
await browser.elementByCss('button').click()
await browser.elementByCss("[href='/revalidate-modal']").click()
await browser.elementByCss("[href='/prr/revalidate-modal']").click()
await check(() => browser.hasElementByCssSelector('#create-entry'), true)
......@@ -254,15 +254,15 @@ describe('parallel-routes-revalidation', () => {
}
describe.each([
{ basePath: '/refreshing', label: 'regular', withSearchParams: false },
{ basePath: '/refreshing', label: 'regular', withSearchParams: true },
{ basePath: '/prr/refreshing', label: 'regular', withSearchParams: false },
{ basePath: '/prr/refreshing', label: 'regular', withSearchParams: true },
{
basePath: '/dynamic-refresh/foo',
basePath: '/prr/dynamic-refresh/foo',
label: 'dynamic',
withSearchParams: false,
},
{
basePath: '/dynamic-refresh/foo',
basePath: '/prr/dynamic-refresh/foo',
label: 'dynamic',
withSearchParams: true,
},
......@@ -420,7 +420,7 @@ describe('parallel-routes-revalidation', () => {
describe('server action revalidation', () => {
it('handles refreshing when multiple parallel slots are active', async () => {
const browser = await next.browser('/nested-revalidate')
const browser = await next.browser('/prr/nested-revalidate')
const currentPageTime = await browser.elementById('page-now').text()
......@@ -428,11 +428,15 @@ describe('parallel-routes-revalidation', () => {
expect(await browser.hasElementByCssSelector('#drawer')).toBe(false)
// renders the drawer parallel slot
await browser.elementByCss("[href='/nested-revalidate/drawer']").click()
await browser
.elementByCss("[href='/prr/nested-revalidate/drawer']")
.click()
await browser.waitForElementByCss('#drawer')
// renders the modal slot
await browser.elementByCss("[href='/nested-revalidate/modal']").click()
await browser
.elementByCss("[href='/prr/nested-revalidate/modal']")
.click()
await browser.waitForElementByCss('#modal')
// Both should be visible, despite only one "matching"
......@@ -468,7 +472,7 @@ describe('parallel-routes-revalidation', () => {
it.skip('should not trigger a refresh for the page that is being redirected to', async () => {
const rscRequests = []
const prefetchRequests = []
const browser = await next.browser('/redirect', {
const browser = await next.browser('/prr/redirect', {
beforePageLoad(page) {
page.on('request', async (req) => {
const headers = await req.allHeaders()
......
......@@ -6,7 +6,7 @@ export default async function Page() {
'https://next-data-api-endpoint.vercel.app/api/random',
{
next: {
tags: ['data'],
tags: ['revalidatetag-rsc:data'],
revalidate: false,
},
}
......@@ -15,8 +15,11 @@ export default async function Page() {
return (
<div>
<span id="data">{data}</span>
<RevalidateViaForm tag="data" />
<Link href="/revalidate_via_page?tag=data" id="revalidate-via-page">
<RevalidateViaForm tag="revalidatetag-rsc:data" />
<Link
href="/revalidate_via_page?tag=revalidatetag-rsc:data"
id="revalidate-via-page"
>
Revalidate via page
</Link>
<Link href="/revalidate_via_cache" id="revalidate-via-cache">
......
......@@ -3,7 +3,7 @@ import { revalidateTag, unstable_cache } from 'next/cache'
export const dynamic = 'force-dynamic'
const revalidateInCache = unstable_cache(async () => {
revalidateTag('data', 'max')
revalidateTag('revalidatetag-rsc:data', 'max')
})
export default async function Page() {
......
......@@ -30,7 +30,7 @@ describe('revalidateTag-rsc', () => {
if (isNextDev) {
await waitForRedbox(browser)
await expect(getRedboxHeader(browser)).resolves.toContain(
'Route "/revalidate_via_page": `revalidateTag("data")` can\'t be called during render.'
'Route "/revalidate_via_page": `revalidateTag("revalidatetag-rsc:data")` can\'t be called during render.'
)
} else {
await retry(async () => {
......@@ -41,7 +41,7 @@ describe('revalidateTag-rsc', () => {
}
expect(next.cliOutput).toContain(
'Route "/revalidate_via_page": `revalidateTag("data")` can\'t be called during render. Call it from a Server Action or Route Handler instead.\nLearn more: https://nextjs.org/docs/messages/revalidate-in-use-cache'
'Route "/revalidate_via_page": `revalidateTag("revalidatetag-rsc:data")` can\'t be called during render. Call it from a Server Action or Route Handler instead.\nLearn more: https://nextjs.org/docs/messages/revalidate-in-use-cache'
)
})
......@@ -52,7 +52,7 @@ describe('revalidateTag-rsc', () => {
if (isNextDev) {
await waitForRedbox(browser)
await expect(getRedboxHeader(browser)).resolves.toContain(
'Route "/revalidate_via_cache": `revalidateTag("data")` can\'t be called inside a cached function.'
'Route "/revalidate_via_cache": `revalidateTag("revalidatetag-rsc:data")` can\'t be called inside a cached function.'
)
} else {
await retry(async () => {
......@@ -63,7 +63,7 @@ describe('revalidateTag-rsc', () => {
}
expect(next.cliOutput).toContain(
'Route "/revalidate_via_cache": `revalidateTag("data")` can\'t be called inside a cached function. Call it from a Server Action or Route Handler instead.\nLearn more: https://nextjs.org/docs/messages/revalidate-in-use-cache'
'Route "/revalidate_via_cache": `revalidateTag("revalidatetag-rsc:data")` can\'t be called inside a cached function. Call it from a Server Action or Route Handler instead.\nLearn more: https://nextjs.org/docs/messages/revalidate-in-use-cache'
)
})
}
......
......@@ -2,7 +2,8 @@ import { revalidatePath } from 'next/cache'
import { NextRequest, NextResponse } from 'next/server'
export async function GET(req: NextRequest) {
const path = req.nextUrl.searchParams.get('path') || '/'
const path =
req.nextUrl.searchParams.get('path') || '/test-on-demand-revalidate'
try {
revalidatePath(path)
......
......@@ -9,6 +9,13 @@ type RevalidateMode =
| 'path-team-layout'
| 'path-team-page'
// The `_N_T_/layout` and `('/', 'layout')` modes exercise root-layout
// revalidation, which is this suite's test subject. When this fixture is
// deployed to a shared Vercel project, these calls purge the root layout of
// every other deployment in the project (revalidation is project-scoped), so
// suites that assert cache persistence on `/` can observe interference from
// this suite. This is a known, accepted blast radius.
function isRevalidateMode(value: string): value is RevalidateMode {
return (
value === 'tag-layout-expireNow' ||
......
......@@ -2,7 +2,7 @@ import { revalidatePath, revalidateTag } from 'next/cache'
/** Evicts the entry so the prefetch's fill actually runs. */
export async function POST() {
revalidateTag('data', { expire: 0 })
revalidateTag('use-cache-after-uncached-io:data', { expire: 0 })
revalidatePath('/uses-cache')
return Response.json({ ok: true })
......
......@@ -28,7 +28,7 @@ async function Late() {
async function getCachedData(): Promise<string> {
'use cache'
cacheLife('hours')
cacheTag('data')
cacheTag('use-cache-after-uncached-io:data')
console.log('running getCachedData')
......
......@@ -14,7 +14,7 @@ async function getData() {
'use cache'
cacheLife({ revalidate: 6 })
cacheTag('modern')
cacheTag('use-cache-custom-handler:modern')
return new Date().toISOString()
}
......@@ -39,7 +39,7 @@ export default async function Home() {
formAction={async () => {
'use server'
updateTag('modern')
updateTag('use-cache-custom-handler:modern')
}}
>
Revalidate Tag
......@@ -59,7 +59,7 @@ export default async function Home() {
formAction={async () => {
'use server'
updateTag('modern')
updateTag('use-cache-custom-handler:modern')
redirect('/')
}}
>
......@@ -70,8 +70,8 @@ export default async function Home() {
formAction={async () => {
'use server'
updateTag('modern')
revalidateTag('other', { expire: 0 })
updateTag('use-cache-custom-handler:modern')
revalidateTag('use-cache-custom-handler:other', { expire: 0 })
}}
>
Revalidate Tags With Different Profiles
......
......@@ -102,7 +102,7 @@ describe('use-cache-custom-handler', () => {
await retry(async () => {
expect(next.cliOutput.slice(outputIndex)).toContain(
'ModernCustomCacheHandler::updateTags ["modern"]'
'ModernCustomCacheHandler::updateTags ["use-cache-custom-handler:modern"]'
)
const data = await browser.elementById('data').text()
......@@ -148,10 +148,10 @@ describe('use-cache-custom-handler', () => {
await retry(async () => {
const cliOutput = next.cliOutput.slice(outputIndex)
expect(cliOutput).toInclude(
'ModernCustomCacheHandler::updateTags ["modern"]'
'ModernCustomCacheHandler::updateTags ["use-cache-custom-handler:modern"]'
)
expect(cliOutput).toInclude(
'ModernCustomCacheHandler::updateTags ["other"]'
'ModernCustomCacheHandler::updateTags ["use-cache-custom-handler:other"]'
)
})
})
......
......@@ -569,6 +569,12 @@ export class NextDeployInstance extends NextInstance {
? projectEnv.TURBOPACK_TEST_TOKEN
: projectEnv.TEST_TOKEN
// revalidatePath/revalidateTag invalidate at project scope, so CI jobs
// that must not share a revalidation scope set VERCEL_TEST_PROJECT to a
// dedicated project. Unset keeps the shared default.
const TEST_PROJECT_NAME =
process.env.VERCEL_TEST_PROJECT?.trim() || projectEnv.TEST_PROJECT_NAME
// If the team name is available in the environment, use it as the scope.
if (TEST_TEAM_NAME) {
vercelFlags.push('--scope', TEST_TEAM_NAME)
......@@ -611,7 +617,7 @@ export class NextDeployInstance extends NextInstance {
// link the project
const linkRes = await execa(
'vercel',
['link', '-p', projectEnv.TEST_PROJECT_NAME, '--yes', ...vercelFlags],
['link', '-p', TEST_PROJECT_NAME, '--yes', ...vercelFlags],
{
cwd: this.testDir,
env: vercelEnv,
......
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