Hooks run Local API calls with req; cross-locale sync restores req.locale
buildCrossLocaleFieldSync read other locales outside the save's transaction and its update(req) left req.locale on the last target locale. buildPreventDeleteSystemPage now reads Site Settings with req. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1beb0edb7f
commit
67e9655376
@@ -103,6 +103,11 @@ export function buildCrossLocaleFieldSync(
|
||||
if (otherLocales.length === 0) {return doc} // single-locale site: nothing to sync
|
||||
|
||||
const payload = req.payload
|
||||
// Passing `req` keeps the reads and writes in the save's transaction, but
|
||||
// the Local API sets req.locale / req.fallbackLocale to the call's locale —
|
||||
// restored in `finally`, or the rest of the save (afterRead, the response)
|
||||
// would run in the last target locale.
|
||||
const { fallbackLocale, locale: requestLocale } = req
|
||||
|
||||
reqAny[guardFlag] = true
|
||||
try {
|
||||
@@ -114,6 +119,7 @@ export function buildCrossLocaleFieldSync(
|
||||
collection: collection as never,
|
||||
depth: 0,
|
||||
locale: locale as never,
|
||||
req,
|
||||
})) as Record<string, unknown>
|
||||
} catch {
|
||||
continue // locale not yet created for this doc — nothing to sync into
|
||||
@@ -167,6 +173,8 @@ export function buildCrossLocaleFieldSync(
|
||||
payload.logger?.error?.({ err, msg: `[ipal] cross-locale ${arrayField} sync failed` })
|
||||
} finally {
|
||||
reqAny[guardFlag] = false
|
||||
req.locale = requestLocale
|
||||
req.fallbackLocale = fallbackLocale
|
||||
}
|
||||
|
||||
return doc
|
||||
|
||||
@@ -25,7 +25,7 @@ export function buildPreventDeleteSystemPage(
|
||||
|
||||
return async ({ id, req }) => {
|
||||
const settings = (await req.payload
|
||||
.findGlobal({ slug: settingsSlug as never, depth: 0 })
|
||||
.findGlobal({ slug: settingsSlug as never, depth: 0, req })
|
||||
.catch(() => null)) as null | Record<string, unknown>
|
||||
if (!settings) {return}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user