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 {
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,
* navigations render the prefetched UI immediately and wait for the
......@@ -58,11 +64,14 @@ export async function instant<T>(
// navigation-testing-lock.ts, which acquires the in-memory navigation lock.
const { hostname } = new URL(resolveURL(page, options))
await step('Acquire Instant Lock', () =>
page
.context()
.addCookies([
{ name: INSTANT_COOKIE, value: '1', domain: hostname, path: '/' },
])
page.context().addCookies([
{
name: INSTANT_COOKIE,
value: String(++cookieCounter),
domain: hostname,
path: '/',
},
])
)
try {
return await fn()
......
......@@ -58,12 +58,12 @@ export function InstantNavsPanel() {
}, [state.page, status, dispatch])
function handleReload() {
document.cookie = 'next-instant-navigation-testing=1; path=/'
document.cookie = `next-instant-navigation-testing=${Date.now()}; path=/`
window.location.reload()
}
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
initialPageRef.current = state.page
dispatch({
......
......@@ -98,11 +98,16 @@ describe('instant-nav-panel', () => {
await clearInstantModeCookie(browser)
await browser.waitForElementByCss('[data-testid="home-title"]')
// Wait for initial compilation to settle
await retry(async () => {
const status = await getBadgeStatus(browser)
expect(status).toBe('none')
})
// Wait for initial compilation to settle (tsconfig creation triggers
// Fast Refresh so the badge may stay in a transient state for a while)
await retry(
async () => {
const status = await getBadgeStatus(browser)
expect(status).toBe('none')
},
10_000,
500
)
await openInstantNavPanel(browser)
......@@ -127,10 +132,14 @@ describe('instant-nav-panel', () => {
await browser.waitForElementByCss('[data-testid="home-title"]')
// Wait for initial compilation to settle (tsconfig creation triggers Fast Refresh)
await retry(async () => {
const status = await getBadgeStatus(browser)
expect(status).toBe('none')
})
await retry(
async () => {
const status = await getBadgeStatus(browser)
expect(status).toBe('none')
},
10_000,
500
)
await openInstantNavPanel(browser)
......@@ -145,7 +154,7 @@ describe('instant-nav-panel', () => {
// Cookie should now be set
await retry(async () => {
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
......
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