From 7229b785785af812c4953437ed45e888e3d091c0 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sun, 14 Jul 2024 20:11:37 +0200 Subject: [PATCH] Disable caching on partials only if used as partials --- src/pages/[locale]/api/pages/partial.astro | 5 ++++- src/pages/[locale]/api/timeline/partial.astro | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/[locale]/api/pages/partial.astro b/src/pages/[locale]/api/pages/partial.astro index bf95243..45b33b5 100644 --- a/src/pages/[locale]/api/pages/partial.astro +++ b/src/pages/[locale]/api/pages/partial.astro @@ -13,7 +13,6 @@ import PageCredits from "./_components/PageCredits.astro"; import type { EndpointPage } from "src/shared/payload/endpoint-types"; export const partial = true; -Astro.locals.pageCaching = false; interface Props { lang?: string; @@ -21,6 +20,10 @@ interface Props { page?: EndpointPage; } +if (!Astro.props.page) { + Astro.locals.pageCaching = false; +} + const reqUrl = new URL(Astro.request.url); const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!; const slug = Astro.props.slug ?? reqUrl.searchParams.get("slug")!; diff --git a/src/pages/[locale]/api/timeline/partial.astro b/src/pages/[locale]/api/timeline/partial.astro index bb347ff..bacfc14 100644 --- a/src/pages/[locale]/api/timeline/partial.astro +++ b/src/pages/[locale]/api/timeline/partial.astro @@ -10,7 +10,6 @@ import type { EndpointChronologyEvent } from "src/shared/payload/endpoint-types" import { payload } from "src/services"; export const partial = true; -Astro.locals.pageCaching = false; interface Props { lang?: string; @@ -19,6 +18,10 @@ interface Props { index?: number; } +if (!Astro.props.event) { + Astro.locals.pageCaching = false; +} + const reqUrl = new URL(Astro.request.url); const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!; const id = Astro.props.id ?? reqUrl.searchParams.get("id")!;