feat!: auto-removes localized property from localized fields within other localized fields (#7933)
## Description Payload localization works on a field-by-field basis. As you can nest fields within other fields, you could potentially nest a localized field within a localized field—but this would be redundant and unnecessary. There would be no reason to define a localized field within a localized parent field, given that the entire data structure from the parent field onward would be localized. Up until this point, Payload would _allow_ you to nest a localized field within another localized field, and this might have worked in MongoDB but it will throw errors in Postgres. Now, Payload will automatically remove the `localized: true` property from sub-fields within `sanitizeFields` if a parent field is localized. This could potentially be a breaking change if you have a configuration with MongoDB that nests localized fields within localized fields. ## Migrating You probably only need to migrate if you are using MongoDB, as there, you may not have noticed any problems. But in Postgres or SQLite, this would have caused issues so it's unlikely that you've made it too far without experiencing issues due to a nested localized fields config. In the event you would like to keep existing data in this fashion, we have added a `compatibility.allowLocalizedWithinLocalized` flag to the Payload config, which you can set to `true`, and Payload will then disable this new sanitization step. Set this compatibility flag to `true` only if you have an existing Payload MongoDB database from pre-3.0, and you have nested localized fields that you would like to maintain without migrating.
This commit is contained in:
@@ -6,7 +6,6 @@ import { fileURLToPath } from 'url'
|
||||
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import type { LocalizedPost, WithLocalizedRelationship } from './payload-types.js'
|
||||
|
||||
import { englishLocale } from '../globals/config.js'
|
||||
import { idToString } from '../helpers/idToString.js'
|
||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||
import { arrayCollectionSlug } from './collections/Array/index.js'
|
||||
@@ -15,6 +14,7 @@ import { nestedToArrayAndBlockCollectionSlug } from './collections/NestedToArray
|
||||
import { tabSlug } from './collections/Tab/index.js'
|
||||
import {
|
||||
defaultLocale,
|
||||
defaultLocale as englishLocale,
|
||||
englishTitle,
|
||||
hungarianLocale,
|
||||
localizedPostsSlug,
|
||||
@@ -1396,6 +1396,17 @@ describe('Localization', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('nested localized field sanitization', () => {
|
||||
it('should sanitize nested localized fields', () => {
|
||||
const collection = payload.collections['localized-within-localized'].config
|
||||
|
||||
expect(collection.fields[0].tabs[0].fields[0].localized).toBeUndefined()
|
||||
expect(collection.fields[1].fields[0].localized).toBeUndefined()
|
||||
expect(collection.fields[2].blocks[0].fields[0].localized).toBeUndefined()
|
||||
expect(collection.fields[3].fields[0].localized).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('nested blocks', () => {
|
||||
let id
|
||||
it('should allow creating nested blocks per locale', async () => {
|
||||
|
||||
Reference in New Issue
Block a user