diff --git a/src/admin/components/forms/field-types/RichText/RichText.tsx b/src/admin/components/forms/field-types/RichText/RichText.tsx index 9504cd653b..dd5d6c8720 100644 --- a/src/admin/components/forms/field-types/RichText/RichText.tsx +++ b/src/admin/components/forms/field-types/RichText/RichText.tsx @@ -247,7 +247,7 @@ const RichText: React.FC = (props) => { const parsedJSON = JSON.parse(valueToRender); valueToRender = parsedJSON; } catch (err) { - // do nothing + valueToRender = null; } } diff --git a/test/fields/collections/RichText/index.ts b/test/fields/collections/RichText/index.ts index c178426387..a39b92f89d 100644 --- a/test/fields/collections/RichText/index.ts +++ b/test/fields/collections/RichText/index.ts @@ -188,6 +188,30 @@ const RichTextFields: CollectionConfig = { }, }, }, + { + name: 'blocks', + type: 'blocks', + blocks: [ + { + slug: 'textBlock', + fields: [ + { + name: 'text', + type: 'text', + }, + ], + }, + { + slug: 'richTextBlock', + fields: [ + { + name: 'text', + type: 'richText', + }, + ], + }, + ], + }, ], }; @@ -440,12 +464,32 @@ export const richTextBulletsDoc = { ], }; +export const richTextBlocks = [ + { + blockType: 'textBlock', + text: 'Regular text', + }, + { + blockType: 'richTextBlock', + text: [ + { + children: [ + { + text: 'Rich text', + }, + ], + type: 'h1', + }, + ], + }, +]; export const richTextDoc = { title: 'Rich Text', selectHasMany: ['one', 'five'], richText: generateRichText(), richTextReadOnly: generateRichText(), richTextCustomFields: generateRichText(), + blocks: richTextBlocks, }; export default RichTextFields; diff --git a/test/fields/e2e.spec.ts b/test/fields/e2e.spec.ts index 7ff02ff47d..f3cc7f98ae 100644 --- a/test/fields/e2e.spec.ts +++ b/test/fields/e2e.spec.ts @@ -736,6 +736,25 @@ describe('fields', () => { const textField = await editLinkModal.locator('#field-text'); await expect(textField).toHaveValue('Hello, I\'m a rich text field.'); }); + test('should not take value from previous block', async () => { + await navigateToRichTextFields(); + + // check first block value + const textField = await page.locator('#field-blocks__0__text'); + await expect(textField).toHaveValue('Regular text'); + + // remove the first block + const editBlock = await page.locator('#blocks-row-0 .popup-button'); + await editBlock.click(); + const removeButton = await page.locator('#blocks-row-0').getByRole('button', { name: 'Remove' }); + await expect(removeButton).toBeVisible(); + await removeButton.click(); + + // check new first block value + const richTextField = await page.locator('#field-blocks__0__text'); + const richTextValue = await richTextField.innerText(); + await expect(richTextValue).toContain('Rich text'); + }); }); });