-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
RichText onChange is erroneously called (and puts editor in dirty state) when wrapped in withFilters HOC #6134
Comments
I can confirm the issue with unnecessary |
I can confirm that the proposed change fixes this issue. I don't see any reason why |
I haven't tested but this issue I see is that we don't "save" the editor when it's not dirty anymore (when we call |
Also not a fan of adding Also not sure if the |
I agree with this statement, but I'd test carefully the different usecases, of splitting/merging/switching etc... :) fast typing + splitting |
Issue Overview
I'm extending blocks to conditionally add a notice, using
wp.hooks.addFilter( 'blocks.BlockEdit'… )
, for example:In doing this, I've found that when a block uses the
RichText
component that the overall editor state will become initially dirty after first loading the page, if the component doesn't in fact error due to TinyMCE not being instantiated. When using a production build, normally theeditor
prop is not initialized yet here and an error is raised:gutenberg/blocks/rich-text/index.js
Line 400 in 004cb8b
Even when the
editor
is initialized, however, the result of callingonChange
is that the editor is put into a dirty state, even when no changes have been made by the user. With the abovewp.hooks.addFilter( 'blocks.BlockEdit'… )
call in place, if the editor is loaded with a paragraph block, then if you then try to reload the page after making no edits then you'll get prompted with theonbeforeunload
“Are you sure?” prompt, as well as the Update button is initially enabled.In digging through the stack trace it seems the reason is due to the
withFilters
HOC call toforceUpdate
after applying filters:gutenberg/components/higher-order/with-filters/index.js
Line 36 in 004cb8b
Down the stack trace this then results in the
RichEdit
component getting unmounted andcomponentWillUnmount
is called which in turn unconditionally callsonChange
even when there are no edits:gutenberg/blocks/rich-text/index.js
Lines 702 to 704 in 004cb8b
Steps to Reproduce
addFilter
code to a plugin.Possible Solution
Check if
this.editor
is defined and in a dirty state itself before callingonChange
during unmounting?The text was updated successfully, but these errors were encountered: