@prismicio/next 2.3.3 → 2.3.4-canary.620be70
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/PrismicNextImage.cjs +6 -5
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.cts +7 -7
- package/dist/PrismicNextImage.d.cts.map +1 -1
- package/dist/PrismicNextImage.d.ts +7 -7
- package/dist/PrismicNextImage.d.ts.map +1 -1
- package/dist/PrismicNextImage.js +5 -4
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicNextLink.cjs +3 -2
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.cts +9 -13
- package/dist/PrismicNextLink.d.cts.map +1 -1
- package/dist/PrismicNextLink.d.ts +8 -12
- package/dist/PrismicNextLink.d.ts.map +1 -1
- package/dist/PrismicNextLink.js +2 -1
- package/dist/PrismicNextLink.js.map +1 -1
- package/dist/PrismicPreview.cjs +2 -2
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts +4 -5
- package/dist/PrismicPreview.d.cts.map +1 -1
- package/dist/PrismicPreview.d.ts +4 -5
- package/dist/PrismicPreview.d.ts.map +1 -1
- package/dist/PrismicPreview.js +1 -1
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +0 -1
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/SliceSimulator.cjs +10 -3
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.cts +3 -4
- package/dist/SliceSimulator.d.cts.map +1 -1
- package/dist/SliceSimulator.d.ts +3 -4
- package/dist/SliceSimulator.d.ts.map +1 -1
- package/dist/SliceSimulator.js +9 -2
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/SliceSimulatorWrapper.cjs +0 -1
- package/dist/SliceSimulatorWrapper.cjs.map +1 -1
- package/dist/SliceSimulatorWrapper.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/cacheTagPrismicPages.cjs +1 -1
- package/dist/cacheTagPrismicPages.cjs.map +1 -1
- package/dist/cacheTagPrismicPages.d.cts +1 -3
- package/dist/cacheTagPrismicPages.d.cts.map +1 -1
- package/dist/cacheTagPrismicPages.d.ts +1 -3
- package/dist/cacheTagPrismicPages.d.ts.map +1 -1
- package/dist/cacheTagPrismicPages.js.map +1 -1
- package/dist/createLocaleRedirect.cjs.map +1 -1
- package/dist/createLocaleRedirect.d.cts +2 -3
- package/dist/createLocaleRedirect.d.cts.map +1 -1
- package/dist/createLocaleRedirect.d.ts +2 -3
- package/dist/createLocaleRedirect.d.ts.map +1 -1
- package/dist/createLocaleRedirect.js.map +1 -1
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts +4 -5
- package/dist/enableAutoPreviews.d.cts.map +1 -1
- package/dist/enableAutoPreviews.d.ts +4 -5
- package/dist/enableAutoPreviews.d.ts.map +1 -1
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +0 -1
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts +1 -2
- package/dist/exitPreview.d.cts.map +1 -1
- package/dist/exitPreview.d.ts +1 -2
- package/dist/exitPreview.d.ts.map +1 -1
- package/dist/exitPreview.js.map +1 -1
- package/dist/getPreviewRef.cjs +0 -1
- package/dist/getPreviewRef.cjs.map +1 -1
- package/dist/getPreviewRef.d.cts +1 -2
- package/dist/getPreviewRef.d.cts.map +1 -1
- package/dist/getPreviewRef.d.ts +1 -2
- package/dist/getPreviewRef.d.ts.map +1 -1
- package/dist/getPreviewRef.js.map +1 -1
- package/dist/getPrismicCacheTags.cjs +4 -2
- package/dist/getPrismicCacheTags.cjs.map +1 -1
- package/dist/getPrismicCacheTags.d.cts +1 -3
- package/dist/getPrismicCacheTags.d.cts.map +1 -1
- package/dist/getPrismicCacheTags.d.ts +1 -3
- package/dist/getPrismicCacheTags.d.ts.map +1 -1
- package/dist/getPrismicCacheTags.js +4 -2
- package/dist/getPrismicCacheTags.js.map +1 -1
- package/dist/getSlices.cjs +1 -1
- package/dist/getSlices.cjs.map +1 -1
- package/dist/getSlices.d.cts +1 -3
- package/dist/getSlices.d.cts.map +1 -1
- package/dist/getSlices.d.ts +1 -3
- package/dist/getSlices.d.ts.map +1 -1
- package/dist/getSlices.js.map +1 -1
- package/dist/imgixLoader.cjs +0 -1
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/imgixLoader.d.cts +1 -3
- package/dist/imgixLoader.d.cts.map +1 -1
- package/dist/imgixLoader.d.ts +1 -3
- package/dist/imgixLoader.d.ts.map +1 -1
- package/dist/imgixLoader.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +1 -1
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts +4 -5
- package/dist/pages/PrismicPreview.d.cts.map +1 -1
- package/dist/pages/PrismicPreview.d.ts +4 -5
- package/dist/pages/PrismicPreview.d.ts.map +1 -1
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/SliceSimulator.cjs +0 -1
- package/dist/pages/SliceSimulator.cjs.map +1 -1
- package/dist/pages/SliceSimulator.d.cts +3 -4
- package/dist/pages/SliceSimulator.d.cts.map +1 -1
- package/dist/pages/SliceSimulator.d.ts +3 -4
- package/dist/pages/SliceSimulator.d.ts.map +1 -1
- package/dist/pages/SliceSimulator.js.map +1 -1
- package/dist/pages/enableAutoPreviews.cjs.map +1 -1
- package/dist/pages/enableAutoPreviews.d.cts +4 -5
- package/dist/pages/enableAutoPreviews.d.cts.map +1 -1
- package/dist/pages/enableAutoPreviews.d.ts +4 -5
- package/dist/pages/enableAutoPreviews.d.ts.map +1 -1
- package/dist/pages/enableAutoPreviews.js.map +1 -1
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts +2 -4
- package/dist/pages/exitPreview.d.cts.map +1 -1
- package/dist/pages/exitPreview.d.ts +2 -4
- package/dist/pages/exitPreview.d.ts.map +1 -1
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +4 -5
- package/dist/pages/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.ts +4 -5
- package/dist/pages/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/pages/setPreviewData.cjs +0 -1
- package/dist/pages/setPreviewData.cjs.map +1 -1
- package/dist/pages/setPreviewData.d.cts +2 -7
- package/dist/pages/setPreviewData.d.cts.map +1 -1
- package/dist/pages/setPreviewData.d.ts +2 -7
- package/dist/pages/setPreviewData.d.ts.map +1 -1
- package/dist/pages/setPreviewData.js.map +1 -1
- package/dist/pages/types.d.cts +3 -5
- package/dist/pages/types.d.cts.map +1 -1
- package/dist/pages/types.d.ts +3 -5
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.cjs +0 -1
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +4 -5
- package/dist/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +4 -5
- package/dist/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/revalidatePrismicPages.cjs +4 -2
- package/dist/revalidatePrismicPages.cjs.map +1 -1
- package/dist/revalidatePrismicPages.d.cts +1 -2
- package/dist/revalidatePrismicPages.d.cts.map +1 -1
- package/dist/revalidatePrismicPages.d.ts +1 -2
- package/dist/revalidatePrismicPages.d.ts.map +1 -1
- package/dist/revalidatePrismicPages.js +4 -1
- package/dist/revalidatePrismicPages.js.map +1 -1
- package/dist/types.d.cts +2 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +2 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/PrismicNextImage.tsx +5 -5
- package/src/PrismicNextLink.tsx +2 -2
- package/src/PrismicPreview.tsx +2 -2
- package/src/SliceSimulator.tsx +18 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revalidatePrismicPages.js","names":[],"sources":["../src/revalidatePrismicPages.ts"],"sourcesContent":["import { revalidateTag } from \"next/cache\"\n\nimport { buildPrismicCacheTag } from \"./getPrismicCacheTags\"\n\n/**\n * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs\n * typically comes from a Prismic webhook triggered when publishing content.\n *\n * @param ids - A list of Prismic page IDs to revalidate.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}\n */\nexport function revalidatePrismicPages(ids: string[]): void {\n\tfor (const id of ids) {\n\t\tconst tag = buildPrismicCacheTag(id)\n\t\trevalidateTag(tag, { expire: 0 })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,uBAAuB,KAAqB;
|
|
1
|
+
{"version":3,"file":"revalidatePrismicPages.js","names":[],"sources":["../src/revalidatePrismicPages.ts"],"sourcesContent":["import { revalidateTag } from \"next/cache\"\n\nimport { buildPrismicCacheTag } from \"./getPrismicCacheTags\"\n\n/**\n * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs\n * typically comes from a Prismic webhook triggered when publishing content.\n *\n * @param ids - A list of Prismic page IDs to revalidate.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}\n */\nexport function revalidatePrismicPages(ids: string[]): void {\n\tfor (const id of ids) {\n\t\tconst tag = buildPrismicCacheTag(id)\n\t\trevalidateTag(tag, { expire: 0 })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,uBAAuB,KAAqB;CAC3D,KAAK,MAAM,MAAM,KAAK;EACrB,MAAM,MAAM,qBAAqB,EAAE;EACnC,cAAc,KAAK,EAAE,QAAQ,EAAE,CAAC;CACjC;AACD"}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ClientConfig } from "@prismicio/client";
|
|
2
|
-
|
|
3
2
|
//#region src/types.d.ts
|
|
4
3
|
declare module "@prismicio/client" {
|
|
5
4
|
interface RequestInitLike {
|
|
@@ -7,13 +6,13 @@ declare module "@prismicio/client" {
|
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
/** @deprecated Use `@prismicio/client`'s `ClientConfig`. */
|
|
10
|
-
type CreateClientConfig = ClientConfig;
|
|
9
|
+
export type CreateClientConfig = ClientConfig;
|
|
11
10
|
/**
|
|
12
11
|
* The minimal set of properties needed from `next`'s `NextRequest` type.
|
|
13
12
|
*
|
|
14
13
|
* This request type is only compatible with Route Handlers defined in the `app` directory.
|
|
15
14
|
*/
|
|
16
|
-
type NextRequestLike = {
|
|
15
|
+
export type NextRequestLike = {
|
|
17
16
|
headers: {
|
|
18
17
|
get(name: string): string | null;
|
|
19
18
|
};
|
|
@@ -26,5 +25,4 @@ type NextRequestLike = {
|
|
|
26
25
|
};
|
|
27
26
|
};
|
|
28
27
|
//#endregion
|
|
29
|
-
export { CreateClientConfig, NextRequestLike };
|
|
30
28
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;YAIW;IACT,OAAO;;;;YAKG,qBAAqB;;;;;;YAOrB;EACX;IACC,IAAI;;EAEL;EACA;IACC;IACA;MACC,IAAI"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ClientConfig } from "@prismicio/client";
|
|
2
|
-
|
|
3
2
|
//#region src/types.d.ts
|
|
4
3
|
declare module "@prismicio/client" {
|
|
5
4
|
interface RequestInitLike {
|
|
@@ -7,13 +6,13 @@ declare module "@prismicio/client" {
|
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
/** @deprecated Use `@prismicio/client`'s `ClientConfig`. */
|
|
10
|
-
type CreateClientConfig = ClientConfig;
|
|
9
|
+
export type CreateClientConfig = ClientConfig;
|
|
11
10
|
/**
|
|
12
11
|
* The minimal set of properties needed from `next`'s `NextRequest` type.
|
|
13
12
|
*
|
|
14
13
|
* This request type is only compatible with Route Handlers defined in the `app` directory.
|
|
15
14
|
*/
|
|
16
|
-
type NextRequestLike = {
|
|
15
|
+
export type NextRequestLike = {
|
|
17
16
|
headers: {
|
|
18
17
|
get(name: string): string | null;
|
|
19
18
|
};
|
|
@@ -26,5 +25,4 @@ type NextRequestLike = {
|
|
|
26
25
|
};
|
|
27
26
|
};
|
|
28
27
|
//#endregion
|
|
29
|
-
export { CreateClientConfig, NextRequestLike };
|
|
30
28
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;YAIW;IACT,OAAO;;;;YAKG,qBAAqB;;;;;;YAOrB;EACX;IACC,IAAI;;EAEL;EACA;IACC;IACA;MACC,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4-canary.620be70",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"next",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"workspaces": [
|
|
19
19
|
".",
|
|
20
20
|
"e2e-projects/*",
|
|
21
|
+
"!e2e-projects/next-14",
|
|
21
22
|
"!e2e-projects/next-15"
|
|
22
23
|
],
|
|
23
24
|
"files": [
|
|
@@ -54,23 +55,23 @@
|
|
|
54
55
|
"types": "tsc --noEmit"
|
|
55
56
|
},
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"@prismicio/simulator": "^0.2.
|
|
58
|
+
"@prismicio/simulator": "^0.2.4",
|
|
58
59
|
"imgix-url-builder": "^0.0.6",
|
|
59
60
|
"lz-string": "^1.5.0"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"@playwright/test": "^1.
|
|
63
|
-
"@prismicio/client": "^7.
|
|
64
|
-
"@types/node": "^
|
|
65
|
-
"@types/react": "^19.
|
|
66
|
-
"next": "16.2
|
|
67
|
-
"oxfmt": "^0.
|
|
68
|
-
"oxlint": "^1.
|
|
69
|
-
"playwright": "^1.
|
|
70
|
-
"react": "^19.
|
|
71
|
-
"react-dom": "^19.
|
|
72
|
-
"tsdown": "^0.
|
|
73
|
-
"typescript": "^
|
|
63
|
+
"@playwright/test": "^1.64.1",
|
|
64
|
+
"@prismicio/client": "^7.22.3",
|
|
65
|
+
"@types/node": "^26.6.5",
|
|
66
|
+
"@types/react": "^19.3.0",
|
|
67
|
+
"next": "16.4.2",
|
|
68
|
+
"oxfmt": "^0.73.0",
|
|
69
|
+
"oxlint": "^1.88.0",
|
|
70
|
+
"playwright": "^1.64.1",
|
|
71
|
+
"react": "^19.3.1",
|
|
72
|
+
"react-dom": "^19.3.1",
|
|
73
|
+
"tsdown": "^0.23.1",
|
|
74
|
+
"typescript": "^7.0.2"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
77
|
"@prismicio/client": "^7",
|
|
@@ -78,6 +79,6 @@
|
|
|
78
79
|
"react": "^18 || ^19"
|
|
79
80
|
},
|
|
80
81
|
"engines": {
|
|
81
|
-
"node": ">=
|
|
82
|
+
"node": ">=22"
|
|
82
83
|
}
|
|
83
84
|
}
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -13,6 +13,8 @@ import { imgixLoader } from "./imgixLoader"
|
|
|
13
13
|
import { devMsg } from "./lib/devMsg"
|
|
14
14
|
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
15
15
|
|
|
16
|
+
const ResolvedImage = resolveDefaultExport(Image)
|
|
17
|
+
|
|
16
18
|
const castInt = (input: string | number | undefined): number | undefined => {
|
|
17
19
|
if (typeof input === "number" || typeof input === "undefined") {
|
|
18
20
|
return input
|
|
@@ -113,14 +115,14 @@ export const PrismicNextImage: ForwardRefExoticComponent<
|
|
|
113
115
|
return <>{fallback}</>
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
const resolvedImgixParams = imgixParams
|
|
117
|
-
for (const x in
|
|
118
|
+
const resolvedImgixParams = { ...imgixParams }
|
|
119
|
+
for (const x in resolvedImgixParams) {
|
|
118
120
|
if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
|
|
119
121
|
resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
const src = buildURL(field.url,
|
|
125
|
+
const src = buildURL(field.url, resolvedImgixParams as ImgixURLParams)
|
|
124
126
|
|
|
125
127
|
const ar = field.dimensions.width / field.dimensions.height
|
|
126
128
|
|
|
@@ -147,8 +149,6 @@ export const PrismicNextImage: ForwardRefExoticComponent<
|
|
|
147
149
|
)
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
const ResolvedImage = resolveDefaultExport(Image)
|
|
151
|
-
|
|
152
152
|
return (
|
|
153
153
|
<ResolvedImage
|
|
154
154
|
ref={ref}
|
package/src/PrismicNextLink.tsx
CHANGED
|
@@ -11,6 +11,8 @@ import { forwardRef } from "react"
|
|
|
11
11
|
|
|
12
12
|
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
13
13
|
|
|
14
|
+
const ResolvedLink = resolveDefaultExport(Link)
|
|
15
|
+
|
|
14
16
|
export type PrismicNextLinkProps = Omit<
|
|
15
17
|
ComponentProps<typeof Link>,
|
|
16
18
|
"field" | "document" | "href" | "rel"
|
|
@@ -54,8 +56,6 @@ export const PrismicNextLink = forwardRef<HTMLAnchorElement, PrismicNextLinkProp
|
|
|
54
56
|
rel = restProps.rel
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
const ResolvedLink = resolveDefaultExport(Link)
|
|
58
|
-
|
|
59
59
|
return (
|
|
60
60
|
<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
61
61
|
{"children" in props ? children : field?.text}
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -5,6 +5,8 @@ import type { FC, ReactNode } from "react"
|
|
|
5
5
|
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
6
6
|
import { PrismicPreviewClient } from "./PrismicPreviewClient"
|
|
7
7
|
|
|
8
|
+
const ResolvedScript = resolveDefaultExport(Script)
|
|
9
|
+
|
|
8
10
|
/** Props for `<PrismicPreview>`. */
|
|
9
11
|
export type PrismicPreviewProps = {
|
|
10
12
|
/**
|
|
@@ -48,8 +50,6 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
|
48
50
|
const toolbarSrc = getToolbarSrc(repositoryName)
|
|
49
51
|
const isDraftMode = (await draftMode()).isEnabled
|
|
50
52
|
|
|
51
|
-
const ResolvedScript = resolveDefaultExport(Script)
|
|
52
|
-
|
|
53
53
|
return (
|
|
54
54
|
<>
|
|
55
55
|
{children}
|
package/src/SliceSimulator.tsx
CHANGED
|
@@ -37,25 +37,38 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
|
37
37
|
className,
|
|
38
38
|
}) => {
|
|
39
39
|
const [message, setMessage] = useState(() => getDefaultMessage())
|
|
40
|
+
const [trustedState, setTrustedState] = useState<string | null>(null)
|
|
40
41
|
const router = useRouter()
|
|
41
42
|
|
|
42
43
|
const state =
|
|
43
44
|
typeof window !== "undefined"
|
|
44
45
|
? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY)
|
|
45
46
|
: undefined
|
|
46
|
-
|
|
47
|
+
// Only render state this page received from Slice Machine or the Page
|
|
48
|
+
// Builder. The `state` URL parameter on its own can be set by anyone.
|
|
49
|
+
const hasSlices = state != null && state === trustedState && getSlices(state).length > 0
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
// `@prismicio/simulator` accepts messages from any origin in development,
|
|
53
|
+
// so the URL is as trustworthy as a message there. Trusting it keeps
|
|
54
|
+
// slices visible when the dev server fully reloads the page. It is set
|
|
55
|
+
// after hydration so the first render matches the server.
|
|
56
|
+
if (process.env.NODE_ENV === "development") {
|
|
57
|
+
// oxlint-disable-next-line react/set-state-in-effect
|
|
58
|
+
setTrustedState(new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY))
|
|
59
|
+
}
|
|
60
|
+
}, [])
|
|
47
61
|
|
|
48
62
|
useEffect(() => {
|
|
49
63
|
simulatorManager.state.on(
|
|
50
64
|
StateEventType.Slices,
|
|
51
65
|
(newSlices) => {
|
|
66
|
+
const nextState = lzString.compressToEncodedURIComponent(JSON.stringify(newSlices))
|
|
52
67
|
const url = new URL(window.location.href)
|
|
53
|
-
url.searchParams.set(
|
|
54
|
-
STATE_PARAMS_KEY,
|
|
55
|
-
lzString.compressToEncodedURIComponent(JSON.stringify(newSlices)),
|
|
56
|
-
)
|
|
68
|
+
url.searchParams.set(STATE_PARAMS_KEY, nextState)
|
|
57
69
|
|
|
58
70
|
window.history.replaceState(null, "", url)
|
|
71
|
+
setTrustedState(nextState)
|
|
59
72
|
// Wait until the next tick to prevent URL state race conditions.
|
|
60
73
|
setTimeout(() => router.refresh(), 0)
|
|
61
74
|
},
|