Disable caching on partials only if used as partials

This commit is contained in:
DrMint 2024-07-14 20:11:37 +02:00
parent c311c0921d
commit 7229b78578
2 changed files with 8 additions and 2 deletions

View File

@ -13,7 +13,6 @@ import PageCredits from "./_components/PageCredits.astro";
import type { EndpointPage } from "src/shared/payload/endpoint-types"; import type { EndpointPage } from "src/shared/payload/endpoint-types";
export const partial = true; export const partial = true;
Astro.locals.pageCaching = false;
interface Props { interface Props {
lang?: string; lang?: string;
@ -21,6 +20,10 @@ interface Props {
page?: EndpointPage; page?: EndpointPage;
} }
if (!Astro.props.page) {
Astro.locals.pageCaching = false;
}
const reqUrl = new URL(Astro.request.url); const reqUrl = new URL(Astro.request.url);
const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!; const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!;
const slug = Astro.props.slug ?? reqUrl.searchParams.get("slug")!; const slug = Astro.props.slug ?? reqUrl.searchParams.get("slug")!;

View File

@ -10,7 +10,6 @@ import type { EndpointChronologyEvent } from "src/shared/payload/endpoint-types"
import { payload } from "src/services"; import { payload } from "src/services";
export const partial = true; export const partial = true;
Astro.locals.pageCaching = false;
interface Props { interface Props {
lang?: string; lang?: string;
@ -19,6 +18,10 @@ interface Props {
index?: number; index?: number;
} }
if (!Astro.props.event) {
Astro.locals.pageCaching = false;
}
const reqUrl = new URL(Astro.request.url); const reqUrl = new URL(Astro.request.url);
const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!; const lang = Astro.props.lang ?? reqUrl.searchParams.get("lang")!;
const id = Astro.props.id ?? reqUrl.searchParams.get("id")!; const id = Astro.props.id ?? reqUrl.searchParams.get("id")!;