Classic block: Fix content syncing effect for React StrictMode#62051
Classic block: Fix content syncing effect for React StrictMode#62051
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I also noticed that the Maybe we should defer rendering while the state is resolving? gutenberg/packages/block-library/src/freeform/edit.js Lines 45 to 69 in 513f9ea |
|
Size Change: +7 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
|
|
||
| const currentContent = editor.getContent(); | ||
| if ( currentContent !== content ) { | ||
| editor.setContent( content || '' ); |
There was a problem hiding this comment.
Definitely didn't make sense to do this if editor was not to be found in the first place 👍
| onReadyStateChange | ||
| ); | ||
| wp.oldEditor.remove( `editor-${ clientId }` ); | ||
| didMount.current = false; |
There was a problem hiding this comment.
We don't do this in a lot of places. Is this necessary in practice?
There was a problem hiding this comment.
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
|
|
||
| const currentContent = editor.getContent(); | ||
| if ( currentContent !== content ) { | ||
| editor.setContent( content || '' ); |
There was a problem hiding this comment.
Any possible concerns that this won't run once window.tinymce.get( editor-${ clientId } ) is populated?
I'm not sure. Though that change isn't really required for the StrictMode fix, I'm happy to remove it from this PR. |
…ress#62051) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
…ress#62051) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
What?
PR fixes a React StrictMode bug for the Classic block. The content syncing effect triggered an error in development mode.
The bug was discovered via #61943.
Why?
The TinyMCE initialization effect was resetting the
didMountref during the cleanup.How?
didMountref when TinyMCE editor is removed.Testing Instructions
wp-env.npm run test:e2e -- editor/blocks/classic.spec.jsPatch for enabling modes
Testing Instructions for Keyboard
Same.