Skip to content

Commit 712fcf9

Browse files
committed
Delete object field when i18n and default present
Fix #629
1 parent a50c781 commit 712fcf9

2 files changed

Lines changed: 104 additions & 1 deletion

File tree

src/lib/services/contents/draft/update/locale.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const copyDefaultLocaleValues = (content) => {
2323

2424
const { defaultLocale } = (collectionFile ?? collection)._i18n;
2525
/** @type {FlattenedEntryContent} */
26-
const newContent = { ...toRaw(content), ...toRaw(currentValues[defaultLocale]) };
26+
const defaultLocaleContent = toRaw(currentValues[defaultLocale]);
27+
const newContent = { ...toRaw(content), ...defaultLocaleContent };
2728
const getFieldArgs = { collectionName, fileName, valueMap: newContent, isIndexFile };
2829
/** @type {string[]} */
2930
const noI18nFieldKeys = [];
@@ -48,6 +49,16 @@ export const copyDefaultLocaleValues = (content) => {
4849
newContent[keyPath] = content[keyPath] ?? '';
4950
}
5051

52+
// Remove `null` values for object fields if i18n is enabled and the field is enabled in the
53+
// default locale, otherwise the subfields will not be saved in the current locale
54+
if (
55+
fieldType === 'object' &&
56+
[true, 'translate', 'duplicate'].includes(i18n) &&
57+
defaultLocaleContent[keyPath] !== null
58+
) {
59+
delete newContent[keyPath];
60+
}
61+
5162
// Remove the field if i18n is disabled
5263
if (
5364
[false, 'none'].includes(i18n) ||

src/lib/services/contents/draft/update/locale.test.js

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)