fix: blank page

This commit is contained in:
2026-05-12 13:42:02 -04:00
parent 7cb5c30b71
commit cb5e688e55
3 changed files with 55 additions and 7 deletions

View File

@@ -44,10 +44,40 @@ declare global {
}
}
// WP's PHP serializer omits empty ACF fields, so sections coming from the CMS can
// be missing title/body/etc. Treat those missing-or-empty values as "fall back to
// the local content" instead of letting them blow up the React render.
function isEmptyValue(v: unknown): boolean {
if (v === null || v === undefined) return true;
if (typeof v === "string") return v === "";
if (Array.isArray(v)) return v.length === 0;
if (typeof v === "object") {
const obj = v as Record<string, unknown>;
if ("fr" in obj && "en" in obj) return !obj.fr && !obj.en;
}
return false;
}
function mergeSection(local: SectionBlock | undefined, wp: SectionBlock): SectionBlock {
if (!local || local.type !== wp.type) return wp;
const merged: Record<string, unknown> = { ...local };
for (const [key, val] of Object.entries(wp)) {
if (!isEmptyValue(val)) merged[key] = val;
}
return merged as unknown as SectionBlock;
}
export function PageRenderer({ page }: { page: PageContent }) {
const { t, locale } = useLocale();
const wpPage = window.__CASCA_PAGE__;
const renderedPage = wpPage?.sections?.length ? ({ ...page, ...wpPage } as PageContent) : page;
const wpSections = wpPage?.sections;
const renderedPage = wpSections?.length
? ({
...page,
...wpPage,
sections: wpSections.map((wpSec, i) => mergeSection(page.sections[i], wpSec)),
} as PageContent)
: page;
// Per-page SEO (title + description). React 19 will hoist these to <head>.
useEffect(() => {