@prismicio/next 2.3.1-pr.147.2aebcfe → 2.3.1-pr.147.3320c5b

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.
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -16,10 +16,8 @@ const require_expiredPreviewCookies = require("./lib/expiredPreviewCookies.cjs")
16
16
  * ```
17
17
  */
18
18
  async function exitPreview() {
19
- const { draftMode } = await import("next/headers.js");
20
- (await draftMode()).disable();
21
19
  const headers = new Headers({ "Cache-Control": "no-store" });
22
- for (const setCookie of require_expiredPreviewCookies.expiredPreviewCookieHeaders()) headers.append("Set-Cookie", setCookie);
20
+ for (const setCookie of [...require_expiredPreviewCookies.expiredPreviewCookieHeaders(), ...require_expiredPreviewCookies.expiredDraftModeCookieHeaders()]) headers.append("Set-Cookie", setCookie);
23
21
  return new Response(JSON.stringify({ success: true }), { headers });
24
22
  }
25
23
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieHeaders"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"./lib/expiredPreviewCookies\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may\n\t// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.\n\t// Expire both on the Response. Do not use `cookies().set` / `delete()`:\n\t// ResponseCookies is name-keyed, so a second `io.prismic.preview` overwrites\n\t// the first and the Lax leftover survives.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of expiredPreviewCookieHeaders()) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,cAAc,MAAM,OAAO;AAElC,EAAC,MAAM,WAAW,EAAE,SAAS;CAO9B,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAaA,8BAAAA,6BAA6B,CACpD,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
1
+ {"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieHeaders","expiredDraftModeCookieHeaders"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import {\n\texpiredDraftModeCookieHeaders,\n\texpiredPreviewCookieHeaders,\n} from \"./lib/expiredPreviewCookies\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Do not call `cookies()` or `draftMode().disable()`. ResponseCookies is\n\t// name-keyed: `appendMutableCookies` rebuilds Set-Cookie by name and drops\n\t// the extra Lax expire. Emit every expire on the Response instead:\n\t// toolbar Lax + iframe None; Secure for `io.prismic.preview`, and both\n\t// shapes of `__prerender_bypass` that `disable()` would have cleared.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,eAAsB,cAAiC;CAMtD,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,CAAC,GAAGA,8BAAAA,6BAA6B,EAAE,GAAGC,8BAAAA,+BAA+B,CAAC,CAC7F,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1,4 +1,4 @@
1
- import { expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
1
+ import { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
2
2
  //#region src/exitPreview.ts
3
3
  /**
4
4
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -16,10 +16,8 @@ import { expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
16
16
  * ```
17
17
  */
18
18
  async function exitPreview() {
19
- const { draftMode } = await import("next/headers.js");
20
- (await draftMode()).disable();
21
19
  const headers = new Headers({ "Cache-Control": "no-store" });
22
- for (const setCookie of expiredPreviewCookieHeaders()) headers.append("Set-Cookie", setCookie);
20
+ for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) headers.append("Set-Cookie", setCookie);
23
21
  return new Response(JSON.stringify({ success: true }), { headers });
24
22
  }
25
23
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"./lib/expiredPreviewCookies\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may\n\t// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.\n\t// Expire both on the Response. Do not use `cookies().set` / `delete()`:\n\t// ResponseCookies is name-keyed, so a second `io.prismic.preview` overwrites\n\t// the first and the Lax leftover survives.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of expiredPreviewCookieHeaders()) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,cAAc,MAAM,OAAO;AAElC,EAAC,MAAM,WAAW,EAAE,SAAS;CAO9B,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,6BAA6B,CACpD,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
1
+ {"version":3,"file":"exitPreview.js","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["import {\n\texpiredDraftModeCookieHeaders,\n\texpiredPreviewCookieHeaders,\n} from \"./lib/expiredPreviewCookies\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Do not call `cookies()` or `draftMode().disable()`. ResponseCookies is\n\t// name-keyed: `appendMutableCookies` rebuilds Set-Cookie by name and drops\n\t// the extra Lax expire. Emit every expire on the Response instead:\n\t// toolbar Lax + iframe None; Secure for `io.prismic.preview`, and both\n\t// shapes of `__prerender_bypass` that `disable()` would have cleared.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,eAAsB,cAAiC;CAMtD,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,CAAC,GAAG,6BAA6B,EAAE,GAAG,+BAA+B,CAAC,CAC7F,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
@@ -29,8 +29,23 @@ async function getPreviewRef() {
29
29
  if (!isDraftModeEnabled) return;
30
30
  const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
31
31
  if (!cookie) return;
32
- if (!cookie.includes("websitePreviewId=")) return;
33
- return cookie;
32
+ return previewRefFromCookie(cookie);
33
+ }
34
+ /**
35
+ * Unwraps `io.prismic.preview` to a Content API ref.
36
+ *
37
+ * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is
38
+ * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`
39
+ * / Cache Components send a non-ref (ParsingError / 404).
40
+ */
41
+ function previewRefFromCookie(cookie) {
42
+ try {
43
+ const parsed = JSON.parse(cookie);
44
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
45
+ for (const value of Object.values(parsed)) if (value !== null && typeof value === "object" && !Array.isArray(value) && "preview" in value && typeof value.preview === "string") return value.preview;
46
+ } catch {
47
+ return cookie;
48
+ }
34
49
  }
35
50
  //#endregion
36
51
  exports.getPreviewRef = getPreviewRef;
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.cjs","names":["prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAAC,OACJ;AAID,KAAI,CADmB,OAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAO"}
1
+ {"version":3,"file":"getPreviewRef.cjs","names":["prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\t// Draft Mode gates preview reads. The cookie may be a raw token or the\n\t// toolbar jar (`{ \"<repo>.prismic.io\": { preview } }`). Only `preview` is a\n\t// Content API ref; the jar string is not.\n\treturn previewRefFromCookie(cookie)\n}\n\n/**\n * Unwraps `io.prismic.preview` to a Content API ref.\n *\n * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is\n * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`\n * / Cache Components send a non-ref (ParsingError / 404).\n */\nfunction previewRefFromCookie(cookie: string): string | undefined {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(cookie)\n\t\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const value of Object.values(parsed)) {\n\t\t\tif (\n\t\t\t\tvalue !== null &&\n\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\"preview\" in value &&\n\t\t\t\ttypeof value.preview === \"string\"\n\t\t\t) {\n\t\t\t\treturn value.preview\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn cookie\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAAC,OACJ;AAMD,QAAO,qBAAqB,OAAO;;;;;;;;;AAUpC,SAAS,qBAAqB,QAAoC;AACjE,KAAI;EACH,MAAM,SAAkB,KAAK,MAAM,OAAO;AAC1C,MAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,CACzE;AAGD,OAAK,MAAM,SAAS,OAAO,OAAO,OAAO,CACxC,KACC,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,MAAM,IACrB,aAAa,SACb,OAAO,MAAM,YAAY,SAEzB,QAAO,MAAM;SAGR;AACP,SAAO"}
@@ -28,8 +28,23 @@ async function getPreviewRef() {
28
28
  if (!isDraftModeEnabled) return;
29
29
  const cookie$1 = (await cookies()).get(cookie.preview)?.value;
30
30
  if (!cookie$1) return;
31
- if (!cookie$1.includes("websitePreviewId=")) return;
32
- return cookie$1;
31
+ return previewRefFromCookie(cookie$1);
32
+ }
33
+ /**
34
+ * Unwraps `io.prismic.preview` to a Content API ref.
35
+ *
36
+ * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is
37
+ * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`
38
+ * / Cache Components send a non-ref (ParsingError / 404).
39
+ */
40
+ function previewRefFromCookie(cookie) {
41
+ try {
42
+ const parsed = JSON.parse(cookie);
43
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
44
+ for (const value of Object.values(parsed)) if (value !== null && typeof value === "object" && !Array.isArray(value) && "preview" in value && typeof value.preview === "string") return value.preview;
45
+ } catch {
46
+ return cookie;
47
+ }
33
48
  }
34
49
  //#endregion
35
50
  export { getPreviewRef };
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewRef.js","names":["cookie","prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAACD,SACJ;AAID,KAAI,CADmBA,SAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAOA"}
1
+ {"version":3,"file":"getPreviewRef.js","names":["cookie","prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\t// Draft Mode gates preview reads. The cookie may be a raw token or the\n\t// toolbar jar (`{ \"<repo>.prismic.io\": { preview } }`). Only `preview` is a\n\t// Content API ref; the jar string is not.\n\treturn previewRefFromCookie(cookie)\n}\n\n/**\n * Unwraps `io.prismic.preview` to a Content API ref.\n *\n * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is\n * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`\n * / Cache Components send a non-ref (ParsingError / 404).\n */\nfunction previewRefFromCookie(cookie: string): string | undefined {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(cookie)\n\t\tif (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const value of Object.values(parsed)) {\n\t\t\tif (\n\t\t\t\tvalue !== null &&\n\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\"preview\" in value &&\n\t\t\t\ttypeof value.preview === \"string\"\n\t\t\t) {\n\t\t\t\treturn value.preview\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn cookie\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAACD,SACJ;AAMD,QAAO,qBAAqBA,SAAO;;;;;;;;;AAUpC,SAAS,qBAAqB,QAAoC;AACjE,KAAI;EACH,MAAM,SAAkB,KAAK,MAAM,OAAO;AAC1C,MAAI,WAAW,QAAQ,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,CACzE;AAGD,OAAK,MAAM,SAAS,OAAO,OAAO,OAAO,CACxC,KACC,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,MAAM,IACrB,aAAa,SACb,OAAO,MAAM,YAAY,SAEzB,QAAO,MAAM;SAGR;AACP,SAAO"}
@@ -2,12 +2,26 @@ require("../_virtual/_rolldown/runtime.cjs");
2
2
  let _prismicio_client = require("@prismicio/client");
3
3
  //#region src/lib/expiredPreviewCookies.ts
4
4
  const epoch = /* @__PURE__ */ new Date(0);
5
+ function expiresAttr() {
6
+ return `Expires=${epoch.toUTCString()}`;
7
+ }
5
8
  /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
6
9
  function expiredPreviewCookieHeaders(name = _prismicio_client.cookie.preview) {
7
- const expires = `Expires=${epoch.toUTCString()}`;
10
+ const expires = expiresAttr();
8
11
  return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
9
12
  }
13
+ /**
14
+ * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`
15
+ * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;
16
+ * Secure in production.
17
+ */
18
+ function expiredDraftModeCookieHeaders() {
19
+ const expires = expiresAttr();
20
+ const name = "__prerender_bypass";
21
+ return [`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`, `${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`];
22
+ }
10
23
  //#endregion
24
+ exports.expiredDraftModeCookieHeaders = expiredDraftModeCookieHeaders;
11
25
  exports.expiredPreviewCookieHeaders = expiredPreviewCookieHeaders;
12
26
 
13
27
  //# sourceMappingURL=expiredPreviewCookies.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"expiredPreviewCookies.cjs","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = `Expires=${epoch.toUTCString()}`\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n"],"mappings":";;;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;;AAGzB,SAAgB,4BAA4B,OAAOA,kBAAAA,OAAc,SAAmB;CACnF,MAAM,UAAU,WAAW,MAAM,aAAa;AAE9C,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B"}
1
+ {"version":3,"file":"expiredPreviewCookies.cjs","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\nfunction expiresAttr(): string {\n\treturn `Expires=${epoch.toUTCString()}`\n}\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = expiresAttr()\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n\n/**\n * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`\n * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;\n * Secure in production.\n */\nexport function expiredDraftModeCookieHeaders(): string[] {\n\tconst expires = expiresAttr()\n\tconst name = \"__prerender_bypass\"\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`,\n\t]\n}\n"],"mappings":";;;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;AAEzB,SAAS,cAAsB;AAC9B,QAAO,WAAW,MAAM,aAAa;;;AAItC,SAAgB,4BAA4B,OAAOA,kBAAAA,OAAc,SAAmB;CACnF,MAAM,UAAU,aAAa;AAE7B,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B;;;;;;;AAQF,SAAgB,gCAA0C;CACzD,MAAM,UAAU,aAAa;CAC7B,MAAM,OAAO;AAEb,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,2BAC7B,GAAG,KAAK,aAAa,QAAQ,mCAC7B"}
@@ -1,12 +1,25 @@
1
1
  import { cookie } from "@prismicio/client";
2
2
  //#region src/lib/expiredPreviewCookies.ts
3
3
  const epoch = /* @__PURE__ */ new Date(0);
4
+ function expiresAttr() {
5
+ return `Expires=${epoch.toUTCString()}`;
6
+ }
4
7
  /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
5
8
  function expiredPreviewCookieHeaders(name = cookie.preview) {
6
- const expires = `Expires=${epoch.toUTCString()}`;
9
+ const expires = expiresAttr();
7
10
  return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
8
11
  }
12
+ /**
13
+ * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`
14
+ * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;
15
+ * Secure in production.
16
+ */
17
+ function expiredDraftModeCookieHeaders() {
18
+ const expires = expiresAttr();
19
+ const name = "__prerender_bypass";
20
+ return [`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`, `${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`];
21
+ }
9
22
  //#endregion
10
- export { expiredPreviewCookieHeaders };
23
+ export { expiredDraftModeCookieHeaders, expiredPreviewCookieHeaders };
11
24
 
12
25
  //# sourceMappingURL=expiredPreviewCookies.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"expiredPreviewCookies.js","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = `Expires=${epoch.toUTCString()}`\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n"],"mappings":";;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;;AAGzB,SAAgB,4BAA4B,OAAOA,OAAc,SAAmB;CACnF,MAAM,UAAU,WAAW,MAAM,aAAa;AAE9C,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B"}
1
+ {"version":3,"file":"expiredPreviewCookies.js","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\nfunction expiresAttr(): string {\n\treturn `Expires=${epoch.toUTCString()}`\n}\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = expiresAttr()\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n\n/**\n * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`\n * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;\n * Secure in production.\n */\nexport function expiredDraftModeCookieHeaders(): string[] {\n\tconst expires = expiresAttr()\n\tconst name = \"__prerender_bypass\"\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`,\n\t]\n}\n"],"mappings":";;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;AAEzB,SAAS,cAAsB;AAC9B,QAAO,WAAW,MAAM,aAAa;;;AAItC,SAAgB,4BAA4B,OAAOA,OAAc,SAAmB;CACnF,MAAM,UAAU,aAAa;AAE7B,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B;;;;;;;AAQF,SAAgB,gCAA0C;CACzD,MAAM,UAAU,aAAa;CAC7B,MAAM,OAAO;AAEb,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,2BAC7B,GAAG,KAAK,aAAa,QAAQ,mCAC7B"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.147.2aebcfe";
2
+ var version = "2.3.1-pr.147.3320c5b";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.147.2aebcfe";
2
+ var version = "2.3.1-pr.147.3320c5b";
3
3
  //#endregion
4
4
  export { version };
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.3.1-pr.147.2aebcfe",
3
+ "version": "2.3.1-pr.147.3320c5b",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -1,4 +1,7 @@
1
- import { expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies"
1
+ import {
2
+ expiredDraftModeCookieHeaders,
3
+ expiredPreviewCookieHeaders,
4
+ } from "./lib/expiredPreviewCookies"
2
5
 
3
6
  /**
4
7
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
@@ -16,22 +19,15 @@ import { expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies"
16
19
  * ```
17
20
  */
18
21
  export async function exitPreview(): Promise<Response> {
19
- // Need this to avoid the following Next.js build-time error:
20
- // You're importing a component that needs next/headers. That only works
21
- // in a Server Component which is not supported in the pages/ directory.
22
- const { draftMode } = await import("next/headers")
23
-
24
- ;(await draftMode()).disable()
25
-
26
- // `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may
27
- // leave SameSite=Lax (not Secure). Those are different cookies to Chrome.
28
- // Expire both on the Response. Do not use `cookies().set` / `delete()`:
29
- // ResponseCookies is name-keyed, so a second `io.prismic.preview` overwrites
30
- // the first and the Lax leftover survives.
22
+ // Do not call `cookies()` or `draftMode().disable()`. ResponseCookies is
23
+ // name-keyed: `appendMutableCookies` rebuilds Set-Cookie by name and drops
24
+ // the extra Lax expire. Emit every expire on the Response instead:
25
+ // toolbar Lax + iframe None; Secure for `io.prismic.preview`, and both
26
+ // shapes of `__prerender_bypass` that `disable()` would have cleared.
31
27
  const headers = new Headers({
32
28
  "Cache-Control": "no-store",
33
29
  })
34
- for (const setCookie of expiredPreviewCookieHeaders()) {
30
+ for (const setCookie of [...expiredPreviewCookieHeaders(), ...expiredDraftModeCookieHeaders()]) {
35
31
  headers.append("Set-Cookie", setCookie)
36
32
  }
37
33
 
@@ -42,10 +42,38 @@ export async function getPreviewRef(): Promise<string | undefined> {
42
42
  return
43
43
  }
44
44
 
45
- const isActiveCookie = cookie.includes("websitePreviewId=")
46
- if (!isActiveCookie) {
47
- return
48
- }
45
+ // Draft Mode gates preview reads. The cookie may be a raw token or the
46
+ // toolbar jar (`{ "<repo>.prismic.io": { preview } }`). Only `preview` is a
47
+ // Content API ref; the jar string is not.
48
+ return previewRefFromCookie(cookie)
49
+ }
50
+
51
+ /**
52
+ * Unwraps `io.prismic.preview` to a Content API ref.
53
+ *
54
+ * After toolbar `PreviewCookie.sync` / `upsertPreviewForDomain`, the cookie is
55
+ * `{ [domain]: { preview: string } }`. Returning that jar makes `enableAutoPreviews`
56
+ * / Cache Components send a non-ref (ParsingError / 404).
57
+ */
58
+ function previewRefFromCookie(cookie: string): string | undefined {
59
+ try {
60
+ const parsed: unknown = JSON.parse(cookie)
61
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
62
+ return
63
+ }
49
64
 
50
- return cookie
65
+ for (const value of Object.values(parsed)) {
66
+ if (
67
+ value !== null &&
68
+ typeof value === "object" &&
69
+ !Array.isArray(value) &&
70
+ "preview" in value &&
71
+ typeof value.preview === "string"
72
+ ) {
73
+ return value.preview
74
+ }
75
+ }
76
+ } catch {
77
+ return cookie
78
+ }
51
79
  }
@@ -2,12 +2,31 @@ import { cookie as prismicCookie } from "@prismicio/client"
2
2
 
3
3
  const epoch = new Date(0)
4
4
 
5
+ function expiresAttr(): string {
6
+ return `Expires=${epoch.toUTCString()}`
7
+ }
8
+
5
9
  /** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
6
10
  export function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {
7
- const expires = `Expires=${epoch.toUTCString()}`
11
+ const expires = expiresAttr()
8
12
 
9
13
  return [
10
14
  `${name}=; Path=/; ${expires}; SameSite=Lax`,
11
15
  `${name}=; Path=/; ${expires}; SameSite=None; Secure`,
12
16
  ]
13
17
  }
18
+
19
+ /**
20
+ * Expired `Set-Cookie` values for the App Router draft-mode cookie that `draftMode().disable()`
21
+ * would clear. Next sets `__prerender_bypass` as Lax (not Secure) in development and SameSite=None;
22
+ * Secure in production.
23
+ */
24
+ export function expiredDraftModeCookieHeaders(): string[] {
25
+ const expires = expiresAttr()
26
+ const name = "__prerender_bypass"
27
+
28
+ return [
29
+ `${name}=; Path=/; ${expires}; SameSite=Lax; HttpOnly`,
30
+ `${name}=; Path=/; ${expires}; SameSite=None; Secure; HttpOnly`,
31
+ ]
32
+ }