fix(SW-976): handle unlocalized entries revalidation

This commit is contained in:
Christel Westerberg
2024-11-21 15:20:31 +01:00
parent f5990998db
commit d3d72f74c9

View File

@@ -29,6 +29,7 @@ const validateJsonBody = z.object({
})
.optional(),
locale: z.nativeEnum(Lang),
publish_details: z.object({ locale: z.nativeEnum(Lang) }).optional(),
uid: z.string(),
url: z.string().optional(),
page_settings: z
@@ -67,15 +68,19 @@ export async function POST(request: NextRequest) {
data: { content_type, entry },
},
} = validatedData
const refsTag = generateRefsResponseTag(entry.locale, entry.uid)
const refTag = generateRefTag(entry.locale, content_type.uid, entry.uid)
const tag = generateTag(entry.locale, entry.uid)
// The publish_details.locale is the locale that the entry is published in, regardless if it is "localized" or not
const entryLocale = entry.publish_details?.locale ?? entry.locale
const refsTag = generateRefsResponseTag(entryLocale, entry.uid)
const refTag = generateRefTag(entryLocale, content_type.uid, entry.uid)
const tag = generateTag(entryLocale, entry.uid)
const languageSwitcherTag = generateTag(
entry.locale,
entryLocale,
entry.uid,
languageSwitcherAffix
)
const metadataTag = generateTag(entry.locale, entry.uid, metadataAffix)
const metadataTag = generateTag(entryLocale, entry.uid, metadataAffix)
console.info(`Revalidating refsTag: ${refsTag}`)
revalidateTag(refsTag)
@@ -94,12 +99,12 @@ export async function POST(request: NextRequest) {
if (entry.breadcrumbs) {
const breadcrumbsRefsTag = generateRefsResponseTag(
entry.locale,
entryLocale,
entry.uid,
breadcrumbsAffix
)
const breadcrumbsTag = generateTag(
entry.locale,
entryLocale,
entry.uid,
breadcrumbsAffix
)
@@ -113,7 +118,7 @@ export async function POST(request: NextRequest) {
if (entry.page_settings?.hide_booking_widget) {
const bookingwidgetTag = generateTag(
entry.locale,
entryLocale,
entry.uid,
bookingwidgetAffix
)