-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Memoize createRecord #11602
Conversation
I'm moving this out of 4.3, we still need to check whether it creates bugs or not. |
Sounds good.
…On Fri, 9 Nov 2018 at 10:02, Riad Benguella ***@***.***> wrote:
I'm moving this out of 4.3, we still need to check whether it creates bugs
or not.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11602 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEfg6w0119bqnzrd6pRqTpUYCPdFydn4ks5utTaIgaJpZM4YTL_m>
.
|
@youknowriad Do you mean something like this? With this button, the range still stays the same. wp.richText.registerFormatType( 'plugin/test', {
title: 'test',
tagName: 'test',
className: 'test',
edit: function( props ) {
return wp.element.createElement( wp.element.Fragment, null,
wp.element.createElement( wp.editor.RichTextToolbarButton, {
icon: 'editor-textcolor',
title: 'test',
onClick: function() {
props.onChange( {
...props.value,
text: props.value.text.toUpperCase(),
} );
}
} )
);
},
} ); |
yes |
Cool. So all seems fine to me then. |
@@ -229,7 +229,11 @@ export class RichText extends Component { | |||
createRecord() { | |||
const range = getSelection().getRangeAt( 0 ); | |||
|
|||
return create( { | |||
if ( range === this.createRecord.lastRange ) { |
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.
Should we add a brief comment about the intention of this for posterity?
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.
Left a comment about adding a comment.
The e2e test failures seems legit. |
@youknowriad Previous ones were passing, and the last commit is just a comment. May only need a rebase. |
9c31692
to
5ae8f47
Compare
No idea why e2e are failing suddenly. Needs investigation. |
5ae8f47
to
763c6ef
Compare
763c6ef
to
afcdbd9
Compare
afcdbd9
to
2f38940
Compare
I'm going to close this for now as #12547 addresses the source of the issue: the selection change event emitting too many times with the same selection. The browser might still emit the event in other cases with the same selection, so maybe this fix should still be included, but it would be good to see where it could happen. |
Description
It very often occurs that on selection change, the range stays the same and no selection calculation needs to be made. E.g. on entering a character
onSelectionChange
will be called twice, while the selection actually stays the same. We can memoize createRecord, as range object will be strict equal throughgetSelection().getRangeAt( 0 )
calls.How has this been tested?
Screenshots
Types of changes
Checklist: