-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Classic block: Fix content syncing effect for React StrictMode #62051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 || '' ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any possible concerns that this won't run once |
||
| } | ||
| }, [ 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good find!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }; | ||
| }, [] ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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
editorwas not to be found in the first place 👍