fix: localized fields within block references were not handled properly if any parent is localized (#11207)
The `localized` properly was not stripped out of referenced block fields, if any parent was localized. For normal fields, this is done in sanitizeConfig. As the same referenced block config can be used in both a localized and non-localized config, we are not able to strip it out inside sanitizeConfig by modifying the block config. Instead, this PR had to bring back tedious logic to handle it everywhere the `field.localized` property is accessed. For backwards-compatibility, we need to keep the existing sanitizeConfig logic. In 4.0, we should remove it to benefit from better test coverage of runtime field.localized handling - for now, this is done for our test suite using the `PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY` flag.
This commit is contained in:
@@ -276,7 +276,7 @@ describe('Localization', () => {
|
||||
expect(localized.title.es).toEqual(spanishTitle)
|
||||
})
|
||||
|
||||
it('REST all locales with all', async () => {
|
||||
it('rest all locales with all', async () => {
|
||||
const response = await restClient.GET(`/${collection}/${localizedPost.id}`, {
|
||||
query: {
|
||||
locale: 'all',
|
||||
@@ -290,7 +290,7 @@ describe('Localization', () => {
|
||||
expect(localized.title.es).toEqual(spanishTitle)
|
||||
})
|
||||
|
||||
it('REST all locales with asterisk', async () => {
|
||||
it('rest all locales with asterisk', async () => {
|
||||
const response = await restClient.GET(`/${collection}/${localizedPost.id}`, {
|
||||
query: {
|
||||
locale: '*',
|
||||
@@ -1869,14 +1869,16 @@ describe('Localization', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// Nested localized fields do no longer have their localized property stripped in
|
||||
// this monorepo, as this is handled at runtime.
|
||||
describe('nested localized field sanitization', () => {
|
||||
it('should sanitize nested localized fields', () => {
|
||||
it('ensure nested localized fields keep localized property in monorepo', () => {
|
||||
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()
|
||||
expect(collection.fields[0].tabs[0].fields[0].localized).toBeDefined()
|
||||
expect(collection.fields[1].fields[0].localized).toBeDefined()
|
||||
expect(collection.fields[2].blocks[0].fields[0].localized).toBeDefined()
|
||||
expect(collection.fields[3].fields[0].localized).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user