Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/block-library/src/freeform/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely didn't make sense to do this if editor was not to be found in the first place 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any possible concerns that this won't run once window.tinymce.get( editor-${ clientId } ) is populated?

}
}, [ content ] );
}, [ clientId, content ] );

useEffect( () => {
const { baseURL, suffix } = window.wpEditorL10n.tinymce;
Expand Down Expand Up @@ -227,6 +230,7 @@ function ClassicEdit( {
onReadyStateChange
);
wp.oldEditor.remove( `editor-${ clientId }` );
didMount.current = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do this in a lot of places. Is this necessary in practice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends. A cleanup could be necessary when you have two connected effects like this and want to ensure that one only does its job after the initial mount.

Here's an example: https://codesandbox.io/p/sandbox/heuristic-rhodes-stw52g?file=%2Fsrc%2FApp.js

};
}, [] );

Expand Down