@prismicio/next 1.1.0-alpha.2 → 1.1.0

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.
@@ -12,7 +12,12 @@ const enableAutoPreviews = (config) => {
12
12
  } else {
13
13
  config.client.queryContentFromRef(() => {
14
14
  var _a;
15
- const cookie$1 = (_a = headers.cookies().get(cookie.preview)) == null ? void 0 : _a.value;
15
+ let cookie$1;
16
+ try {
17
+ cookie$1 = (_a = headers.cookies().get(cookie.preview)) == null ? void 0 : _a.value;
18
+ } catch {
19
+ return;
20
+ }
16
21
  if (cookie$1 && /\.prismic\.io/.test(cookie$1)) {
17
22
  return cookie$1;
18
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { PreviewData } from \"next\";\nimport { cookies } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or `getServerSideProps()` (`pages` directory).\n\n\t\tif (\n\t\t\ttypeof config.previewData === \"object\" &&\n\t\t\t\"ref\" in config.previewData &&\n\t\t\ttypeof config.previewData.ref === \"string\"\n\t\t) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tconst cookie = cookies().get(prismic.cookie.preview)?.value;\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["cookie","cookies","prismic.cookie.preview"],"mappings":";;;;AAkDa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAIjD,QAAA,OAAO,OAAO,gBAAgB,YAC9B,SAAS,OAAO,eAChB,OAAO,OAAO,YAAY,QAAQ,UACjC;AACD,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAKC,WAAA,OAAO,oBAAoB,MAAK;;AACtC,YAAMA,YAASC,aAAAA,QAAO,EAAG,IAAIC,OAAsB,OAAA,MAApCD,mBAAuC;AAgBtD,UAAID,YAAU,gBAAgB,KAAKA,QAAM,GAAG;AACpC,eAAAA;AAAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
1
+ {"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { PreviewData } from \"next\";\nimport { cookies } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (\n\t\t\ttypeof config.previewData === \"object\" &&\n\t\t\t\"ref\" in config.previewData &&\n\t\t\ttypeof config.previewData.ref === \"string\"\n\t\t) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// noop - We are probably in\n\t\t\t\t// `getStaticProps()` or `getServerSideProps()`\n\t\t\t\t// with inactive Preview Mode where `cookies()`\n\t\t\t\t// does not work. We don't need to do any\n\t\t\t\t// preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We are probably in App Router (`app` directory).\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["cookie","cookies","prismic.cookie.preview"],"mappings":";;;;AAkDa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAMjD,QAAA,OAAO,OAAO,gBAAgB,YAC9B,SAAS,OAAO,eAChB,OAAO,OAAO,YAAY,QAAQ,UACjC;AACD,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,MAAK;;AAClC,UAAAA;AACA,UAAA;AACHA,oBAASC,aAAAA,QAAU,EAAA,IAAIC,OAAsB,OAAA,MAApCD,mBAAuC;AAAA,MAAA,QAC/C;AAOD;AAAA,MACA;AAkBD,UAAID,YAAU,gBAAgB,KAAKA,QAAM,GAAG;AACpC,eAAAA;AAAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
@@ -10,7 +10,12 @@ const enableAutoPreviews = (config) => {
10
10
  } else {
11
11
  config.client.queryContentFromRef(() => {
12
12
  var _a;
13
- const cookie = (_a = cookies().get(preview)) == null ? void 0 : _a.value;
13
+ let cookie;
14
+ try {
15
+ cookie = (_a = cookies().get(preview)) == null ? void 0 : _a.value;
16
+ } catch {
17
+ return;
18
+ }
14
19
  if (cookie && /\.prismic\.io/.test(cookie)) {
15
20
  return cookie;
16
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { PreviewData } from \"next\";\nimport { cookies } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or `getServerSideProps()` (`pages` directory).\n\n\t\tif (\n\t\t\ttypeof config.previewData === \"object\" &&\n\t\t\t\"ref\" in config.previewData &&\n\t\t\ttypeof config.previewData.ref === \"string\"\n\t\t) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tconst cookie = cookies().get(prismic.cookie.preview)?.value;\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["prismic.cookie.preview"],"mappings":";;AAkDa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAIjD,QAAA,OAAO,OAAO,gBAAgB,YAC9B,SAAS,OAAO,eAChB,OAAO,OAAO,YAAY,QAAQ,UACjC;AACD,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAKC,WAAA,OAAO,oBAAoB,MAAK;;AACtC,YAAM,UAAS,aAAO,EAAG,IAAIA,OAAsB,MAApC,mBAAuC;AAgBtD,UAAI,UAAU,gBAAgB,KAAK,MAAM,GAAG;AACpC,eAAA;AAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
1
+ {"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { PreviewData } from \"next\";\nimport { cookies } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (\n\t\t\ttypeof config.previewData === \"object\" &&\n\t\t\t\"ref\" in config.previewData &&\n\t\t\ttypeof config.previewData.ref === \"string\"\n\t\t) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// noop - We are probably in\n\t\t\t\t// `getStaticProps()` or `getServerSideProps()`\n\t\t\t\t// with inactive Preview Mode where `cookies()`\n\t\t\t\t// does not work. We don't need to do any\n\t\t\t\t// preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We are probably in App Router (`app` directory).\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["prismic.cookie.preview"],"mappings":";;AAkDa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAMjD,QAAA,OAAO,OAAO,gBAAgB,YAC9B,SAAS,OAAO,eAChB,OAAO,OAAO,YAAY,QAAQ,UACjC;AACD,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,MAAK;;AAClC,UAAA;AACA,UAAA;AACH,kBAAS,aAAU,EAAA,IAAIA,OAAsB,MAApC,mBAAuC;AAAA,MAAA,QAC/C;AAOD;AAAA,MACA;AAkBD,UAAI,UAAU,gBAAgB,KAAK,MAAM,GAAG;AACpC,eAAA;AAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const version = "1.1.0-alpha.2";
3
+ const version = "1.1.0";
4
4
  exports.version = version;
5
5
  //# sourceMappingURL=package.json.cjs.map
@@ -1,4 +1,4 @@
1
- const version = "1.1.0-alpha.2";
1
+ const version = "1.1.0";
2
2
  export {
3
3
  version
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "1.1.0-alpha.2",
3
+ "version": "1.1.0",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "typescript",
@@ -65,6 +65,7 @@
65
65
  "eslint-plugin-tsdoc": "^0.2.17",
66
66
  "happy-dom": "^9.9.2",
67
67
  "next": "^13.4.0",
68
+ "node-fetch": "^3.3.1",
68
69
  "prettier": "^2.8.8",
69
70
  "prettier-plugin-jsdoc": "^0.4.2",
70
71
  "react": "^18.1.0",
@@ -52,7 +52,9 @@ export const enableAutoPreviews = <TPreviewData extends PreviewData>(
52
52
  config: EnableAutoPreviewsConfig<TPreviewData>,
53
53
  ): void => {
54
54
  if ("previewData" in config && config.previewData) {
55
- // Assume we are in `getStaticProps()` or `getServerSideProps()` (`pages` directory).
55
+ // Assume we are in `getStaticProps()` or
56
+ // `getServerSideProps()` with active Preview Mode (`pages`
57
+ // directory).
56
58
 
57
59
  if (
58
60
  typeof config.previewData === "object" &&
@@ -66,12 +68,27 @@ export const enableAutoPreviews = <TPreviewData extends PreviewData>(
66
68
 
67
69
  config.client.enableAutoPreviewsFromReq(config.req);
68
70
  } else {
69
- // Assume we are in App Router (`app` directory).
71
+ // Assume we are in App Router (`app` directory) OR
72
+ // `getStaticProps()`/`getServerSideProps()` with an inactive
73
+ // Preview Mode (`pages` directory).
70
74
 
71
75
  // We use a function value so the cookie is checked on every
72
76
  // request. We don't have a static value to read from.
73
77
  config.client.queryContentFromRef(() => {
74
- const cookie = cookies().get(prismic.cookie.preview)?.value;
78
+ let cookie: string | undefined;
79
+ try {
80
+ cookie = cookies().get(prismic.cookie.preview)?.value;
81
+ } catch {
82
+ // noop - We are probably in
83
+ // `getStaticProps()` or `getServerSideProps()`
84
+ // with inactive Preview Mode where `cookies()`
85
+ // does not work. We don't need to do any
86
+ // preview handling.
87
+
88
+ return;
89
+ }
90
+
91
+ // We are probably in App Router (`app` directory).
75
92
 
76
93
  // We only return the cookie if a Prismic Preview session is active.
77
94
  //