Skip to content

Commit feb6fdd

Browse files
committed
chore: update sanitizeFallbackLocale func
1 parent ddce75e commit feb6fdd

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/payload/src/fields/hooks/afterRead/promise.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,9 @@ export const promise = async ({
160160
if (fallbackLocale && fallbackLocale !== locale) {
161161
let fallbackValue
162162
const isNullOrUndefined = typeof value === 'undefined' || value === null
163-
const fallbackIsArray =
164-
Array.isArray(fallbackLocale) ||
165-
(fallbackLocale.startsWith('[') && fallbackLocale.endsWith(']'))
166-
167-
if (fallbackIsArray) {
168-
const formattedFallback = Array.isArray(fallbackLocale)
169-
? fallbackLocale
170-
: fallbackLocale
171-
.slice(1, -1)
172-
.split(',')
173-
.map((l) => l.trim())
174-
175-
for (const locale of formattedFallback) {
163+
164+
if (Array.isArray(fallbackLocale)) {
165+
for (const locale of fallbackLocale) {
176166
const val = siblingDoc[field.name!]?.[locale]
177167

178168
if (val !== undefined && val !== null && val !== '') {

packages/payload/src/utilities/sanitizeFallbackLocale.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SanitizedLocalizationConfig } from '../config/types.js'
22
import type { TypedLocale } from '../index.js'
33

44
interface Args {
5-
fallbackLocale: false | TypedLocale
5+
fallbackLocale: false | TypedLocale | TypedLocale[]
66
locale: string
77
localization: SanitizedLocalizationConfig
88
}
@@ -26,7 +26,10 @@ export const sanitizeFallbackLocale = ({
2626
hasFallbackLocale = Boolean(localization && localization.fallback)
2727
}
2828

29-
if (fallbackLocale && !['false', 'none', 'null'].includes(fallbackLocale)) {
29+
if (
30+
fallbackLocale &&
31+
!['false', 'none', 'null'].includes(!Array.isArray(fallbackLocale) ? fallbackLocale : '')
32+
) {
3033
hasFallbackLocale = true
3134
}
3235

@@ -52,5 +55,16 @@ export const sanitizeFallbackLocale = ({
5255
fallbackLocale = null
5356
}
5457

58+
if (
59+
typeof fallbackLocale === 'string' &&
60+
fallbackLocale.startsWith('[') &&
61+
fallbackLocale.endsWith(']')
62+
) {
63+
fallbackLocale = fallbackLocale
64+
.slice(1, -1)
65+
.split(',')
66+
.map((l) => l.trim())
67+
}
68+
5569
return fallbackLocale as null | string
5670
}

0 commit comments

Comments
 (0)