-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix edited Classic block's content deletion when switching to Code editor #23927
Fix edited Classic block's content deletion when switching to Code editor #23927
Conversation
Size Change: -1.02 MB (88%) 🏆 Total Size: 1.15 MB
ℹ️ View Unchanged
|
Can you run a performance comparison between the base branch and this one, per Testing Overview § Performance Testing? Thanks! |
a334fba
to
69d7604
Compare
69d7604
to
10a6bec
Compare
@mcsf The performance test actually runs on each PR now, unfortunately, the job doesn't post the result as a comment or something, so you'd have to dig in the github action to see the results. |
The performance test don't rely on classic blocks though 🤷 |
D'oh, I'm silly. Unconsciously I probably thought "RichText" instead of "Classic". |
405ae38
to
1f8ef41
Compare
// We need this check because when we remove the editor (onUnmount) | ||
// due to the usage of `debounce`, this callback is executed in | ||
// another tick. This results in setting the content to empty. | ||
if ( editor._isRemoved ) return; |
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.
I personally like this style, but I'm surprised the linter didn't complain about this if
statement with no curly braces:
if ( A ) {
return;
}
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.
It might have allowSingleLine
set. I'll check the rules.
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.
It seems that allows the omission of curly braces when a block contains only one statement by default, if not explicitly set. I'm not sure yet though.
There are other similar cases in the codebase as well. So if this is a problem, we should check and fix the linter config/rules.
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.
Yeah, apparently it's not enforced in code, but for reference here are the guidelines:
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.
Looks great now :)
…itor (#23927) * remove lodash debounce * handle unmount with debounce for performance reasons * add debounce time * utilize lodash debounce cancel method
Description
Fixes: #23924
If you edit the content of a
Classic
block and then switch toCode editor
, the content disappears.This was happening because with the switch ( and possibly other actions as well? ) the
Classic
block unmounts and calls thewp.oldEditor
( tinymce ) functionremove
. This function in a series of internal actions withsave
ended up calling our debounced function. Since it was set to execute to anothertick
, the editor had already cleared its content (caused by the aboveremove
call) resulting in the disappearance of the content.There might be some performance issues on "edge" cases, as previously discussed here: #23408 (comment), in the PR that introduced this side effect.
Checklist: