From 6d58249dca4881bbc77ef52ad51e0da7b7dc6594 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 29 May 2024 12:39:49 +0400 Subject: [PATCH] Classic block: Fix content syncing effect for React StrictMode (#62051) Co-authored-by: Mamaduka Co-authored-by: tyxla Co-authored-by: ellatrix --- packages/block-library/src/freeform/edit.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/freeform/edit.js b/packages/block-library/src/freeform/edit.js index c41a78ca5c0422..9e432992a30054 100644 --- a/packages/block-library/src/freeform/edit.js +++ b/packages/block-library/src/freeform/edit.js @@ -83,12 +83,15 @@ function ClassicEdit( { } const editor = window.tinymce.get( `editor-${ clientId }` ); - const currentContent = editor?.getContent(); + if ( ! editor ) { + return; + } + const currentContent = editor.getContent(); if ( currentContent !== content ) { editor.setContent( content || '' ); } - }, [ content ] ); + }, [ clientId, content ] ); useEffect( () => { const { baseURL, suffix } = window.wpEditorL10n.tinymce; @@ -227,6 +230,7 @@ function ClassicEdit( { onReadyStateChange ); wp.oldEditor.remove( `editor-${ clientId }` ); + didMount.current = false; }; }, [] );