Commit e1cce1b3 authored by Cursor Agent's avatar Cursor Agent

fix: use unique cookie values for instant navigation testing lock

Newer Chromium versions (>=136, shipped with Playwright >=1.58) skip
CookieStore change events when a cookie is set to the same value it
already has. This broke nesting detection in the instant navigation
testing API because both the outer and inner instant() calls set the
cookie to '1'.

- Use a counter-based value in @next/playwright so each addCookies
  call triggers a CookieStore change event
- Use Date.now() in the dev overlay panel for the same reason
- Increase retry timeouts in devtools test to accommodate slightly
  slower badge status transitions in newer Chromium
- Update cookie value assertion to match dynamic values
parent 2a411664
...@@ -26,6 +26,12 @@ interface PlaywrightPage { ...@@ -26,6 +26,12 @@ interface PlaywrightPage {
const INSTANT_COOKIE = 'next-instant-navigation-testing' const INSTANT_COOKIE = 'next-instant-navigation-testing'
// Counter ensures each addCookies call uses a distinct value so the
// browser's CookieStore always fires a "change" event — even when the
// cookie already exists. Newer Chromium versions (≥136, shipped with
// Playwright ≥1.58) skip the event when the value is unchanged.
let cookieCounter = 0
/** /**
* Runs a function with instant navigation enabled. Within this scope, * Runs a function with instant navigation enabled. Within this scope,
* navigations render the prefetched UI immediately and wait for the * navigations render the prefetched UI immediately and wait for the
...@@ -58,11 +64,14 @@ export async function instant<T>( ...@@ -58,11 +64,14 @@ export async function instant<T>(
// navigation-testing-lock.ts, which acquires the in-memory navigation lock. // navigation-testing-lock.ts, which acquires the in-memory navigation lock.
const { hostname } = new URL(resolveURL(page, options)) const { hostname } = new URL(resolveURL(page, options))
await step('Acquire Instant Lock', () => await step('Acquire Instant Lock', () =>
page page.context().addCookies([
.context() {
.addCookies([ name: INSTANT_COOKIE,
{ name: INSTANT_COOKIE, value: '1', domain: hostname, path: '/' }, value: String(++cookieCounter),
]) domain: hostname,
path: '/',
},
])
) )
try { try {
return await fn() return await fn()
......
...@@ -58,12 +58,12 @@ export function InstantNavsPanel() { ...@@ -58,12 +58,12 @@ export function InstantNavsPanel() {
}, [state.page, status, dispatch]) }, [state.page, status, dispatch])
function handleReload() { function handleReload() {
document.cookie = 'next-instant-navigation-testing=1; path=/' document.cookie = `next-instant-navigation-testing=${Date.now()}; path=/`
window.location.reload() window.location.reload()
} }
function handleStartClientNav() { function handleStartClientNav() {
document.cookie = 'next-instant-navigation-testing=1; path=/' document.cookie = `next-instant-navigation-testing=${Date.now()}; path=/`
fromUrlRef.current = window.location.pathname + window.location.search fromUrlRef.current = window.location.pathname + window.location.search
initialPageRef.current = state.page initialPageRef.current = state.page
dispatch({ dispatch({
......
...@@ -98,11 +98,16 @@ describe('instant-nav-panel', () => { ...@@ -98,11 +98,16 @@ describe('instant-nav-panel', () => {
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await browser.waitForElementByCss('[data-testid="home-title"]') await browser.waitForElementByCss('[data-testid="home-title"]')
// Wait for initial compilation to settle // Wait for initial compilation to settle (tsconfig creation triggers
await retry(async () => { // Fast Refresh so the badge may stay in a transient state for a while)
const status = await getBadgeStatus(browser) await retry(
expect(status).toBe('none') async () => {
}) const status = await getBadgeStatus(browser)
expect(status).toBe('none')
},
10_000,
500
)
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
...@@ -127,10 +132,14 @@ describe('instant-nav-panel', () => { ...@@ -127,10 +132,14 @@ describe('instant-nav-panel', () => {
await browser.waitForElementByCss('[data-testid="home-title"]') await browser.waitForElementByCss('[data-testid="home-title"]')
// Wait for initial compilation to settle (tsconfig creation triggers Fast Refresh) // Wait for initial compilation to settle (tsconfig creation triggers Fast Refresh)
await retry(async () => { await retry(
const status = await getBadgeStatus(browser) async () => {
expect(status).toBe('none') const status = await getBadgeStatus(browser)
}) expect(status).toBe('none')
},
10_000,
500
)
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
...@@ -145,7 +154,7 @@ describe('instant-nav-panel', () => { ...@@ -145,7 +154,7 @@ describe('instant-nav-panel', () => {
// Cookie should now be set // Cookie should now be set
await retry(async () => { await retry(async () => {
const cookie = await browser.eval(() => document.cookie) const cookie = await browser.eval(() => document.cookie)
expect(cookie).toContain('next-instant-navigation-testing=1') expect(cookie).toMatch(/next-instant-navigation-testing=\d+/)
}) })
// Panel should show client-nav-waiting state // Panel should show client-nav-waiting state
......
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