Admin link-preview hook never throws without a Payload instance

syncAdminMeta returned to payload.logger in its catch even when payload was
undefined, so the Site settings afterChange hook threw with req: {} (an
unhandled rejection that made vitest, and npm publish for 1.14.5, exit 1).
Return early without payload, log through payload?.logger, skip the call in the
hook without req.payload; the fillEmptyLocales hooks get the same guard. Tests:
sync without payload, and every plugin global afterChange hook with req: {}.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 12:21:21 +01:00
co-authored by Claude Opus 5.5
parent 838a2f70b2
commit 71f7108cb8
4 changed files with 24 additions and 5 deletions
+3 -1
View File
@@ -171,6 +171,8 @@ export async function syncAdminMeta(
resolved: ResolvedAdminMeta,
{ nameField = 'siteName', settingsSlug = 'site-settings' }: { nameField?: string; settingsSlug?: string } = {},
): Promise<void> {
// A hook called without a Payload instance (tests, scripts) has nothing to read or write.
if (!payload) {return}
try {
const locale = payload.config.localization ? payload.config.localization.defaultLocale : undefined
const settings = (await payload.findGlobal({ slug: settingsSlug as never, depth: 0, ...(locale ? { locale: locale as never } : {}) })) as Record<string, unknown>
@@ -185,6 +187,6 @@ export async function syncAdminMeta(
if (!resolved.own.description && resolved.options.description !== false && description) {meta.description = description}
if (!resolved.own.titleSuffix && resolved.options.titleSuffix !== false && titleSuffix) {meta.titleSuffix = titleSuffix}
} catch (error) {
payload.logger.warn({ err: error, msg: '[ipal] admin meta: could not read Site settings; Payload defaults stay.' })
payload?.logger?.warn({ err: error, msg: '[ipal] admin meta: could not read Site settings; Payload defaults stay.' })
}
}