From fb48a394a38b7db304d7e25973d038f42ba142bf Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Wed, 30 Oct 2024 11:30:23 -1000 Subject: [PATCH 1/7] fix(adapter-next): async access to `params` and `searchParams` in Next.js 15 (#1471) --- .../src/hooks/documentation-read.ts | 16 ++++++++----- .../adapter-next/src/hooks/project-init.ts | 10 ++++---- packages/adapter-next/src/simulator/types.ts | 4 ++-- .../plugin-documentation-read.test.ts.snap | 24 ++++++++----------- .../test/plugin-project-init.test.ts | 15 +++++++----- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/packages/adapter-next/src/hooks/documentation-read.ts b/packages/adapter-next/src/hooks/documentation-read.ts index 9bf98b9da5..7ebe382747 100644 --- a/packages/adapter-next/src/hooks/documentation-read.ts +++ b/packages/adapter-next/src/hooks/documentation-read.ts @@ -41,10 +41,11 @@ export const documentationRead: DocumentationReadHook = async ( type Params = { uid: string }; - export default async function Page({ params }: { params: Params }) { + export default async function Page({ params }: { params: Promise }) { + const { uid } = await params const client = createClient(); const page = await client - .getByUID("${model.id}", params.uid) + .getByUID("${model.id}", uid) .catch(() => notFound()); return ; @@ -53,11 +54,12 @@ export const documentationRead: DocumentationReadHook = async ( export async function generateMetadata({ params, }: { - params: Params; + params: Promise; }): Promise { + const { uid } = await params const client = createClient(); const page = await client - .getByUID("${model.id}", params.uid) + .getByUID("${model.id}", uid) .catch(() => notFound()); return { @@ -205,18 +207,20 @@ export const documentationRead: DocumentationReadHook = async ( export default async function Page({ params }) { + const { uid } = await params const client = createClient(); const page = await client - .getByUID("${model.id}", params.uid) + .getByUID("${model.id}", uid) .catch(() => notFound()); return ; } export async function generateMetadata({ params }) { + const { uid } = await params const client = createClient(); const page = await client - .getByUID("${model.id}", params.uid) + .getByUID("${model.id}", uid) .catch(() => notFound()); return { diff --git a/packages/adapter-next/src/hooks/project-init.ts b/packages/adapter-next/src/hooks/project-init.ts index c95cc7ad0e..40b51a4c0f 100644 --- a/packages/adapter-next/src/hooks/project-init.ts +++ b/packages/adapter-next/src/hooks/project-init.ts @@ -284,10 +284,11 @@ const createSliceSimulatorPage = async ({ import { components } from "../../slices"; - export default function SliceSimulatorPage({ + export default async function SliceSimulatorPage({ searchParams, }: SliceSimulatorParams) { - const slices = getSlices(searchParams.state); + const { state } = await searchParams + const slices = getSlices(state); return ( @@ -306,8 +307,9 @@ const createSliceSimulatorPage = async ({ import { components } from "../../slices"; - export default function SliceSimulatorPage({ searchParams }) { - const slices = getSlices(searchParams.state); + export default async function SliceSimulatorPage({ searchParams }) { + const { state } = await searchParams + const slices = getSlices(state); return ( diff --git a/packages/adapter-next/src/simulator/types.ts b/packages/adapter-next/src/simulator/types.ts index 0628749dff..2347324fec 100644 --- a/packages/adapter-next/src/simulator/types.ts +++ b/packages/adapter-next/src/simulator/types.ts @@ -5,7 +5,7 @@ * Server Component. */ export type SliceSimulatorParams = { - searchParams: { + searchParams: Promise<{ state?: string; - }; + }>; }; diff --git a/packages/adapter-next/test/__snapshots__/plugin-documentation-read.test.ts.snap b/packages/adapter-next/test/__snapshots__/plugin-documentation-read.test.ts.snap index 7f3e429e3f..a5e2f9fe46 100644 --- a/packages/adapter-next/test/__snapshots__/plugin-documentation-read.test.ts.snap +++ b/packages/adapter-next/test/__snapshots__/plugin-documentation-read.test.ts.snap @@ -16,19 +16,17 @@ import { createClient } from \\"@/prismicio\\"; import { components } from \\"@/slices\\"; export default async function Page({ params }) { + const { uid } = await params; const client = createClient(); - const page = await client - .getByUID(\\"foo_bar\\", params.uid) - .catch(() => notFound()); + const page = await client.getByUID(\\"foo_bar\\", uid).catch(() => notFound()); return ; } export async function generateMetadata({ params }) { + const { uid } = await params; const client = createClient(); - const page = await client - .getByUID(\\"foo_bar\\", params.uid) - .catch(() => notFound()); + const page = await client.getByUID(\\"foo_bar\\", uid).catch(() => notFound()); return { title: page.data.meta_title, @@ -69,11 +67,10 @@ import { components } from \\"@/slices\\"; type Params = { uid: string }; -export default async function Page({ params }: { params: Params }) { +export default async function Page({ params }: { params: Promise }) { + const { uid } = await params; const client = createClient(); - const page = await client - .getByUID(\\"foo_bar\\", params.uid) - .catch(() => notFound()); + const page = await client.getByUID(\\"foo_bar\\", uid).catch(() => notFound()); return ; } @@ -81,12 +78,11 @@ export default async function Page({ params }: { params: Params }) { export async function generateMetadata({ params, }: { - params: Params; + params: Promise; }): Promise { + const { uid } = await params; const client = createClient(); - const page = await client - .getByUID(\\"foo_bar\\", params.uid) - .catch(() => notFound()); + const page = await client.getByUID(\\"foo_bar\\", uid).catch(() => notFound()); return { title: page.data.meta_title, diff --git a/packages/adapter-next/test/plugin-project-init.test.ts b/packages/adapter-next/test/plugin-project-init.test.ts index ad7697a614..74533b8338 100644 --- a/packages/adapter-next/test/plugin-project-init.test.ts +++ b/packages/adapter-next/test/plugin-project-init.test.ts @@ -850,8 +850,9 @@ describe("Slice Simulator route", () => { import { components } from \\"../../slices\\"; - export default function SliceSimulatorPage({ searchParams }) { - const slices = getSlices(searchParams.state); + export default async function SliceSimulatorPage({ searchParams }) { + const { state } = await searchParams; + const slices = getSlices(state); return ( @@ -915,8 +916,9 @@ describe("Slice Simulator route", () => { import { components } from \\"../../slices\\"; - export default function SliceSimulatorPage({ searchParams }) { - const slices = getSlices(searchParams.state); + export default async function SliceSimulatorPage({ searchParams }) { + const { state } = await searchParams; + const slices = getSlices(state); return ( @@ -1012,10 +1014,11 @@ describe("Slice Simulator route", () => { import { components } from \\"../../slices\\"; - export default function SliceSimulatorPage({ + export default async function SliceSimulatorPage({ searchParams, }: SliceSimulatorParams) { - const slices = getSlices(searchParams.state); + const { state } = await searchParams; + const slices = getSlices(state); return ( From a80b6d64bfad34dc582744c31f170c8aa558d97d Mon Sep 17 00:00:00 2001 From: angeloashmore <8601064+angeloashmore@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:09:17 +0000 Subject: [PATCH 2/7] release: 9 new packages --- packages/adapter-next/package.json | 2 +- packages/adapter-nuxt/package.json | 2 +- packages/adapter-nuxt2/package.json | 2 +- packages/adapter-sveltekit/package.json | 2 +- packages/init/package.json | 2 +- packages/manager/package.json | 2 +- packages/plugin-kit/package.json | 2 +- packages/slice-machine/package.json | 2 +- packages/start-slicemachine/package.json | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/adapter-next/package.json b/packages/adapter-next/package.json index 64b2f53c89..18f0b55008 100644 --- a/packages/adapter-next/package.json +++ b/packages/adapter-next/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-next", - "version": "0.3.54", + "version": "0.3.55", "description": "Slice Machine adapter for Next.js.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt/package.json b/packages/adapter-nuxt/package.json index add4869419..e0c3d63ef9 100644 --- a/packages/adapter-nuxt/package.json +++ b/packages/adapter-nuxt/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt", - "version": "0.3.54", + "version": "0.3.55", "description": "Slice Machine adapter for Nuxt 3.", "keywords": [ "typescript", diff --git a/packages/adapter-nuxt2/package.json b/packages/adapter-nuxt2/package.json index 0efd79533e..3422e34375 100644 --- a/packages/adapter-nuxt2/package.json +++ b/packages/adapter-nuxt2/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-nuxt2", - "version": "0.3.54", + "version": "0.3.55", "description": "Slice Machine adapter for Nuxt 2.", "keywords": [ "typescript", diff --git a/packages/adapter-sveltekit/package.json b/packages/adapter-sveltekit/package.json index 3f717a8224..d856be76ff 100644 --- a/packages/adapter-sveltekit/package.json +++ b/packages/adapter-sveltekit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/adapter-sveltekit", - "version": "0.3.54", + "version": "0.3.55", "description": "Slice Machine adapter for SvelteKit.", "keywords": [ "typescript", diff --git a/packages/init/package.json b/packages/init/package.json index fee75cc74e..dfa077ce5a 100644 --- a/packages/init/package.json +++ b/packages/init/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/init", - "version": "2.10.11", + "version": "2.10.12", "description": "Init Prismic Slice Machine in your project", "keywords": [ "typescript", diff --git a/packages/manager/package.json b/packages/manager/package.json index 5afd1ef5b0..44dc6161cd 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/manager", - "version": "0.22.0", + "version": "0.22.1", "description": "Manage all aspects of a Slice Machine project.", "repository": { "type": "git", diff --git a/packages/plugin-kit/package.json b/packages/plugin-kit/package.json index 8594fe54e5..27a0e3c099 100644 --- a/packages/plugin-kit/package.json +++ b/packages/plugin-kit/package.json @@ -1,6 +1,6 @@ { "name": "@slicemachine/plugin-kit", - "version": "0.4.54", + "version": "0.4.55", "description": "A set of helpers to develop and run Slice Machine plugins", "keywords": [ "typescript", diff --git a/packages/slice-machine/package.json b/packages/slice-machine/package.json index 8de7af7ece..8e5190e2f8 100644 --- a/packages/slice-machine/package.json +++ b/packages/slice-machine/package.json @@ -1,6 +1,6 @@ { "name": "slice-machine-ui", - "version": "2.10.0", + "version": "2.10.1", "license": "MIT", "description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.", "repository": { diff --git a/packages/start-slicemachine/package.json b/packages/start-slicemachine/package.json index c449fcaf4f..7ed822d01c 100644 --- a/packages/start-slicemachine/package.json +++ b/packages/start-slicemachine/package.json @@ -1,6 +1,6 @@ { "name": "start-slicemachine", - "version": "0.12.34", + "version": "0.12.35", "description": "Start Slice Machine from within a project.", "repository": { "type": "git", From d9dff547cd694b202f6b94a29668c5c05b854760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marti=CC=81n?= Date: Mon, 4 Nov 2024 22:37:56 +0100 Subject: [PATCH 3/7] Refetch field snippet when config changes --- .../common/Zone/Card/components/Hints/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx index e5fe1ede29..73c0890d8f 100644 --- a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +++ b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx @@ -20,9 +20,15 @@ const Hint: React.FC = ({ }) => { const fieldPathString = renderHintBase({ item }); - // TODO: Call `swr`'s global `mutate` function when something changes to clear the cache. + const snippetCacheKey = [fieldPathString]; + if (item.value.type === "Link") { + if (item.value.config?.allowText ?? false) + snippetCacheKey.push("allowText"); + if (item.value.config?.repeat ?? false) snippetCacheKey.push("repeat"); + } + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const { data, error } = useSWR(fieldPathString, async () => { + const { data, error } = useSWR(snippetCacheKey.join("$"), async () => { return await managerClient.snippets.readSnippets({ fieldPath: fieldPathString.split("."), model: item.value, From 150f394134800496a3a021a423d16f9b9bcaf0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Mon, 4 Nov 2024 22:50:43 +0100 Subject: [PATCH 4/7] Update packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx --- .../lib/builders/common/Zone/Card/components/Hints/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx index 73c0890d8f..bb694ee368 100644 --- a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +++ b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx @@ -24,7 +24,6 @@ const Hint: React.FC = ({ if (item.value.type === "Link") { if (item.value.config?.allowText ?? false) snippetCacheKey.push("allowText"); - if (item.value.config?.repeat ?? false) snippetCacheKey.push("repeat"); } // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment From c945784fd879507146a9f44d512a71d9fb3b9a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Mon, 4 Nov 2024 23:16:24 +0100 Subject: [PATCH 5/7] Update packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx --- .../lib/builders/common/Zone/Card/components/Hints/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx index bb694ee368..d045f9a57c 100644 --- a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +++ b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx @@ -20,7 +20,7 @@ const Hint: React.FC = ({ }) => { const fieldPathString = renderHintBase({ item }); - const snippetCacheKey = [fieldPathString]; + const snippetCacheKey = [item.value.type]; if (item.value.type === "Link") { if (item.value.config?.allowText ?? false) snippetCacheKey.push("allowText"); From df78ab0ecfad11077e04e4172b859f52180c762c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Mon, 4 Nov 2024 23:43:47 +0100 Subject: [PATCH 6/7] Update packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx --- .../lib/builders/common/Zone/Card/components/Hints/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx index d045f9a57c..408f57363d 100644 --- a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +++ b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx @@ -20,7 +20,7 @@ const Hint: React.FC = ({ }) => { const fieldPathString = renderHintBase({ item }); - const snippetCacheKey = [item.value.type]; + const snippetCacheKey: string[] = [item.value.type]; if (item.value.type === "Link") { if (item.value.config?.allowText ?? false) snippetCacheKey.push("allowText"); From 3c6fc43955aef85bb6afbb604936eb91d1b450e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Tue, 5 Nov 2024 00:15:47 +0100 Subject: [PATCH 7/7] Update packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx --- .../lib/builders/common/Zone/Card/components/Hints/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx index 408f57363d..bb694ee368 100644 --- a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +++ b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx @@ -20,7 +20,7 @@ const Hint: React.FC = ({ }) => { const fieldPathString = renderHintBase({ item }); - const snippetCacheKey: string[] = [item.value.type]; + const snippetCacheKey = [fieldPathString]; if (item.value.type === "Link") { if (item.value.config?.allowText ?? false) snippetCacheKey.push("allowText");