next.js
f1240993 - Make `instant()` resilient to a leaked navigation-testing cookie

Commit
16 days ago
Make `instant()` resilient to a leaked navigation-testing cookie The Instant Navigation Testing helper threw "An instant() scope is already active" whenever it found the next-instant-navigation-testing cookie set at acquire time. Because Playwright reuses one browser context across every test in a file, a cookie left behind by an earlier scope poisoned the shared jar and made every following instant() call fail fast, cascading through the suite. The cookie can outlive its scope: under the lock, each MPA page load asynchronously re-writes it via cookieStore, and that write can land right after the scope's release deletes it but before the client observes the deletion, resurrecting a captured-state entry that the change handler then ignores. Nesting is now tracked in-process, keyed on the browser context, rather than inferred from cookie presence. The context is the right granularity because the instant cookie is context-scoped: concurrent scopes on the same context share one cookie and conflict, while scopes on separate contexts or browsers are independent and must both run. On acquire we clear any stale cookie instead of throwing, and the release re-reads and re-deletes until the cookie stays gone, defeating the resurrection race. New tests cover recovery from a leaked cookie and concurrent scopes across separate contexts.
Author
Committer
Parents
Loading