diff --git a/packages/richtext-lexical/src/field/Field.tsx b/packages/richtext-lexical/src/field/Field.tsx index 4088dbf326..571e1d6f56 100644 --- a/packages/richtext-lexical/src/field/Field.tsx +++ b/packages/richtext-lexical/src/field/Field.tsx @@ -79,10 +79,6 @@ const RichTextComponent: React.FC< const disabled = readOnlyFromProps || formProcessing || formInitializing const [isSmallWidthViewport, setIsSmallWidthViewport] = useState(false) - const [rerenderProviderKey, setRerenderProviderKey] = useState() - - const prevInitialValueRef = React.useRef(initialValue) - const prevValueRef = React.useRef(value) useEffect(() => { const updateViewPortWidth = () => { @@ -117,24 +113,13 @@ const RichTextComponent: React.FC< const handleChange = useCallback( (editorState: EditorState) => { - const newState = editorState.toJSON() - prevValueRef.current = newState - setValue(newState) + setValue(editorState.toJSON()) }, [setValue], ) const styles = useMemo(() => mergeFieldStyles(field), [field]) - useEffect(() => { - if (JSON.stringify(initialValue) !== JSON.stringify(prevInitialValueRef.current)) { - prevInitialValueRef.current = initialValue - if (JSON.stringify(prevValueRef.current) !== JSON.stringify(value)) { - setRerenderProviderKey(new Date()) - } - } - }, [initialValue, value]) - return (
{ - const { dispatchFields, fields } = useForm() - - const clearState = React.useCallback(() => { - dispatchFields({ - type: 'REPLACE_STATE', - state: { - ...fields, - [fieldName]: { - ...fields[fieldName], - initialValue: null, - value: null, - }, - }, - }) - }, [dispatchFields, fields, fieldName]) - - return ( - - ) -} diff --git a/test/fields/collections/Lexical/e2e/main/e2e.spec.ts b/test/fields/collections/Lexical/e2e/main/e2e.spec.ts index 4597fa2948..3352788f11 100644 --- a/test/fields/collections/Lexical/e2e/main/e2e.spec.ts +++ b/test/fields/collections/Lexical/e2e/main/e2e.spec.ts @@ -264,19 +264,6 @@ describe('lexicalMain', () => { }) }) - test('should be able to externally mutate editor state', async () => { - await navigateToLexicalFields() - const richTextField = page.locator('.rich-text-lexical').nth(1).locator('.editor-scroller') // first - await expect(richTextField).toBeVisible() - await richTextField.click() // Use click, because focus does not work - await page.keyboard.type('some text') - const spanInEditor = richTextField.locator('span').first() - await expect(spanInEditor).toHaveText('some text') - await saveDocAndAssert(page) - await page.locator('#clear-lexical-lexicalSimple').click() - await expect(spanInEditor).not.toBeAttached() - }) - test('should be able to bold text using floating select toolbar', async () => { await navigateToLexicalFields() const richTextField = page.locator('.rich-text-lexical').nth(2) // second diff --git a/test/fields/collections/Lexical/index.ts b/test/fields/collections/Lexical/index.ts index 5630a7e3ea..bff47de359 100644 --- a/test/fields/collections/Lexical/index.ts +++ b/test/fields/collections/Lexical/index.ts @@ -317,20 +317,6 @@ export const LexicalFields: CollectionConfig = { ], }), }, - { - type: 'ui', - name: 'clearLexicalState', - admin: { - components: { - Field: { - path: '/collections/Lexical/components/ClearState.js#ClearState', - clientProps: { - fieldName: 'lexicalSimple', - }, - }, - }, - }, - }, { name: 'lexicalWithBlocks', type: 'richText',