From ce283688db0e8e0a1858caa43606f31283b86c64 Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Mon, 14 Oct 2024 16:42:58 +1100 Subject: [PATCH 1/4] fix: add cache revalidation for root pages --- packages/sanity-cms/api/revalidate.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/sanity-cms/api/revalidate.ts b/packages/sanity-cms/api/revalidate.ts index 509c889d..28115186 100644 --- a/packages/sanity-cms/api/revalidate.ts +++ b/packages/sanity-cms/api/revalidate.ts @@ -146,6 +146,8 @@ export const createRevalidateHandler = ({ revalidatePath(`${schemaUrl}`); } else { revalidatePath(`${schemaUrl}${slug}`); + // Also revalidate the root schema url (if it's not the landing page) Eg: /blog + revalidatePath(schemaUrl.replaceAll('/', '')); } } } From e19745eeb571421d65848b461e735b7f973d8f71 Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Mon, 14 Oct 2024 16:46:02 +1100 Subject: [PATCH 2/4] fix: remove landing if check --- packages/sanity-cms/api/revalidate.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/sanity-cms/api/revalidate.ts b/packages/sanity-cms/api/revalidate.ts index 28115186..54674f1c 100644 --- a/packages/sanity-cms/api/revalidate.ts +++ b/packages/sanity-cms/api/revalidate.ts @@ -5,7 +5,6 @@ import logger from '../lib/logger'; import { safeTry } from '@session/util-js/try'; import type { PageSchemaType } from '../schemas/page'; import type { PostSchemaType } from '../schemas/post'; -import { getSiteSettings } from '../queries/getSiteSettings'; import type { SessionSanityClient } from '../lib/client'; type RssGeneratorConfig = { @@ -141,14 +140,8 @@ export const createRevalidateHandler = ({ if (!schemaUrl.endsWith('/')) { schemaUrl = `${schemaUrl}/`; } - const settings = await getSiteSettings({ client }); - if (slug === settings?.landingPage?.slug?.current) { - revalidatePath(`${schemaUrl}`); - } else { - revalidatePath(`${schemaUrl}${slug}`); - // Also revalidate the root schema url (if it's not the landing page) Eg: /blog - revalidatePath(schemaUrl.replaceAll('/', '')); - } + revalidatePath(`${schemaUrl}`); + revalidatePath(`${schemaUrl}${slug}`); } } } From 9481329506ea686cf96c822a32b9e81b4db68f9f Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Mon, 14 Oct 2024 16:49:24 +1100 Subject: [PATCH 3/4] chore: remove need for sanity client in revalidate --- packages/sanity-cms/api/revalidate.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/sanity-cms/api/revalidate.ts b/packages/sanity-cms/api/revalidate.ts index 54674f1c..7f5737cb 100644 --- a/packages/sanity-cms/api/revalidate.ts +++ b/packages/sanity-cms/api/revalidate.ts @@ -5,7 +5,6 @@ import logger from '../lib/logger'; import { safeTry } from '@session/util-js/try'; import type { PageSchemaType } from '../schemas/page'; import type { PostSchemaType } from '../schemas/post'; -import type { SessionSanityClient } from '../lib/client'; type RssGeneratorConfig = { /** The CMS content type that the generator should be run for.*/ @@ -20,7 +19,6 @@ type RssGeneratorConfig = { type CreateRevalidateHandlerOptions = { /** The secret used to verify the webhook request. */ revalidateSecret: string; - client: SessionSanityClient; schemaUrls: Record; /** An array of RSS generator configurations. {@link RssGeneratorConfig} */ rssGenerators?: Array; @@ -55,7 +53,6 @@ type CreateRevalidateHandlerOptions = { */ export const createRevalidateHandler = ({ revalidateSecret, - client, schemaUrls, rssGenerators, }: CreateRevalidateHandlerOptions) => { From 356d2d1d9c91b312a2898ed556e2be06e2945a61 Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Mon, 14 Oct 2024 16:53:03 +1100 Subject: [PATCH 4/4] chore: remove client --- apps/foundation/app/api/revalidate/route.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/foundation/app/api/revalidate/route.ts b/apps/foundation/app/api/revalidate/route.ts index 465a50e3..7042d0ff 100644 --- a/apps/foundation/app/api/revalidate/route.ts +++ b/apps/foundation/app/api/revalidate/route.ts @@ -1,5 +1,4 @@ import { createRevalidateHandler } from '@session/sanity-cms/api/revalidate'; -import { client } from '@/lib/sanity/sanity.client'; import { SANITY_SCHEMA_URL } from '@/lib/constants'; const SANITY_REVALIDATE_SECRET = process.env.SANITY_REVALIDATE_SECRET!; @@ -9,7 +8,6 @@ if (!SANITY_REVALIDATE_SECRET) { export const { POST } = createRevalidateHandler({ revalidateSecret: SANITY_REVALIDATE_SECRET, - client: client, schemaUrls: { page: SANITY_SCHEMA_URL.PAGE, post: SANITY_SCHEMA_URL.POST,