@next/playwright 16.2.0-canary.94 → 16.2.0-canary.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -12,8 +12,14 @@ interface PlaywrightBrowserContext {
12
12
  domain?: string;
13
13
  path?: string;
14
14
  }>): Promise<void>;
15
+ cookies(): Promise<Array<{
16
+ name: string;
17
+ value: string;
18
+ }>>;
15
19
  clearCookies(options?: {
16
20
  name?: string;
21
+ domain?: string;
22
+ path?: string;
17
23
  }): Promise<void>;
18
24
  }
19
25
  interface PlaywrightPage {
package/dist/index.js CHANGED
@@ -25,6 +25,14 @@ const INSTANT_COOKIE = 'next-instant-navigation-testing';
25
25
  * as labeled steps in the Playwright UI.
26
26
  */
27
27
  async function instant(page, fn, options) {
28
+ // Check for nested instant() calls. The cookie is scoped to the browser
29
+ // context, so we can detect nesting by checking if it's already set.
30
+ const existingCookies = await page.context().cookies();
31
+ if (existingCookies.some((c) => c.name === INSTANT_COOKIE)) {
32
+ throw new Error('An instant() scope is already active. Nesting instant() ' +
33
+ 'calls is not supported. Did you forget to await the ' +
34
+ 'previous instant() call?');
35
+ }
28
36
  // Acquire the lock by setting the cookie via the browser context. This
29
37
  // ensures the cookie is present even on the very first navigation.
30
38
  // The cookie triggers the CookieStore change event in
@@ -33,16 +41,16 @@ async function instant(page, fn, options) {
33
41
  await (0, step_1.step)('Acquire Instant Lock', () => page
34
42
  .context()
35
43
  .addCookies([
36
- { name: INSTANT_COOKIE, value: '1', domain: hostname, path: '/' },
44
+ { name: INSTANT_COOKIE, value: '[0]', domain: hostname, path: '/' },
37
45
  ]));
38
46
  try {
39
47
  return await fn();
40
48
  }
41
49
  finally {
42
- // Release the lock by clearing the cookie. For SPA navigations, this
43
- // triggers the CookieStore change event which resolves the in-memory
44
- // lock. For MPA navigations (reload, plain anchor), the listener in
45
- // app-bootstrap.ts triggers a page reload to fetch dynamic data.
50
+ // Release the lock by clearing the cookie. Next.js may have updated the
51
+ // cookie value (e.g. from [0] to [1,null]) during the lock scope. We
52
+ // clear by name to remove the cookie regardless of its current value or
53
+ // which domain variant it was stored under.
46
54
  await (0, step_1.step)('Release Instant Lock', () => page.context().clearCookies({ name: INSTANT_COOKIE }));
47
55
  }
48
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/playwright",
3
- "version": "16.2.0-canary.94",
3
+ "version": "16.2.0-canary.95",
4
4
  "repository": {
5
5
  "url": "vercel/next.js",
6
6
  "directory": "packages/next-playwright"