next.js
82cd9945 - Release the instant navs lock without clearing the whole cookie jar (#94947)

Commit
162 days ago
Release the instant navs lock without clearing the whole cookie jar (#94947) The `instant()` helper in `@next/playwright` released the navigation lock by calling `page.context().clearCookies({ name: INSTANT_COOKIE })`. Playwright implements a filtered `clearCookies` non-atomically: it clears the entire cookie jar and then re-adds the cookies that don't match the filter, briefly removing the application's own cookies too. Because Next.js reacts to the instant cookie's deletion by immediately re-rendering (a soft refresh or a full reload), a render whose request raced that empty window observed none of the test's cookies, so a page reading `cookies()` rendered as if nothing was set, for example `testCookie: not set`. Resource contention widened the clear-then-re-add window, which is why the instant navigation suite failed intermittently in CI. <img width="225" height="225" alt="empty cookie jar" src="https://github.com/user-attachments/assets/770b8817-e4c4-4b4b-8251-30353d892816" /> We now release the lock by reading the instant cookie's stored entries (Next.js may have updated the value, e.g. from `[0]` to `[1, null]`, but preserves the domain and path) and re-adding each with a past expiry, which deletes only those entries and leaves every other cookie untouched. This removes the transient empty-jar window while still firing the CookieStore deletion event that releases the lock. To exercise the fix under the conditions that surfaced it, we want CI's flake-detection job to replay the instant navigation suite, which only happens when the suite's test file changes. We trigger that by un-skipping the `renders runtime-prefetched content instantly during navigation` test. That test had been skipped as flaky because of a real bug in the dev runtime-prefetch decode, which #94866 has since fixed, so it passes reliably now and no longer needs to be skipped.
Author
Parents
Loading