Commit 82cd994
authored
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.1 parent 6df3f23 commit 82cd994
2 files changed
Lines changed: 37 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
96 | 119 | | |
97 | 120 | | |
98 | 121 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
| 96 | + | |
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
| |||
0 commit comments