From 68763ee1fdf6c8e557c4502083733e0cb5044367 Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Tue, 3 Jun 2025 14:48:24 +0000 Subject: [PATCH] Merged in fix/sitemap-fixes (pull request #2280) fix:sitemap - added null check and correct content-type * fix:sitemap - added null check and correct content-type * Revert test code Approved-by: Erik Tiekstra --- apps/scandic-web/app/api/web/sitemap/utils.ts | 20 +++++++++++++++---- .../app/sitemap/[sitemapId]/route.ts | 2 +- apps/scandic-web/app/sitemap/route.ts | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/scandic-web/app/api/web/sitemap/utils.ts b/apps/scandic-web/app/api/web/sitemap/utils.ts index eeeb59884..af7711f8a 100644 --- a/apps/scandic-web/app/api/web/sitemap/utils.ts +++ b/apps/scandic-web/app/api/web/sitemap/utils.ts @@ -20,10 +20,22 @@ export function mergeEntries( const entries = [...currentEntries] newEntries.forEach((entry) => { - const index = entries.findIndex( - ({ data }) => - data.uid === entry.data.uid && data.locale === entry.data.locale - ) + if (!entry?.data?.uid || !entry?.data?.locale) { + metricsEntriesMerge.dataError( + `Invalid entry data, missing uid or locale`, + { entry } + ) + return + } + + const index = entries.findIndex(({ data }) => { + if (!data) { + metricsEntriesMerge.dataError(`Data is null or undefined,`) + return false + } + + return data.uid === entry.data.uid && data.locale === entry.data.locale + }) if (index > -1) { entries[index] = entry } else { diff --git a/apps/scandic-web/app/sitemap/[sitemapId]/route.ts b/apps/scandic-web/app/sitemap/[sitemapId]/route.ts index cf6ffb511..b42182aaf 100644 --- a/apps/scandic-web/app/sitemap/[sitemapId]/route.ts +++ b/apps/scandic-web/app/sitemap/[sitemapId]/route.ts @@ -49,6 +49,6 @@ export async function GET( const sitemapXML = `\n${entries.join("")}\n` return new Response(sitemapXML, { - headers: { "Content-Type": "text/xml" }, + headers: { "Content-Type": "application/xml" }, }) } diff --git a/apps/scandic-web/app/sitemap/route.ts b/apps/scandic-web/app/sitemap/route.ts index 802eb6e41..76042dbc2 100644 --- a/apps/scandic-web/app/sitemap/route.ts +++ b/apps/scandic-web/app/sitemap/route.ts @@ -33,6 +33,6 @@ export async function GET() { const sitemapIndexXML = `\n${urls.join("")}\n` return new Response(sitemapIndexXML, { - headers: { "Content-Type": "text/xml" }, + headers: { "Content-Type": "application/xml" }, }) }