Skip to content

RichText: comment isEqual checks to avoid regressing in the future#5252

Merged
youknowriad merged 1 commit intomasterfrom
update/comment-isequal-checks
Feb 26, 2018
Merged

RichText: comment isEqual checks to avoid regressing in the future#5252
youknowriad merged 1 commit intomasterfrom
update/comment-isequal-checks

Conversation

@youknowriad
Copy link
Copy Markdown
Contributor

Related #5100 (comment)

These checks have been added and removed several times, this comment ensures we don't remove them anymore unless we check the correct regression they introduce.

@youknowriad youknowriad added the [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable label Feb 26, 2018
@youknowriad youknowriad self-assigned this Feb 26, 2018
@youknowriad youknowriad requested a review from ellatrix February 26, 2018 08:02
Comment thread blocks/rich-text/index.js Outdated
this.props.value !== prevProps.value &&
this.props.value !== this.savedContent &&

// Comparing using isEqual is neccessary especially to avoid unnecessary updateContent calls
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: neccessary => necessary. :)

@youknowriad youknowriad force-pushed the update/comment-isequal-checks branch from 284b353 to 2240b4a Compare February 26, 2018 10:12
Comment thread blocks/rich-text/index.js
@@ -696,6 +696,10 @@ export class RichText extends Component {
this.props.tagName === prevProps.tagName &&
this.props.value !== prevProps.value &&
this.props.value !== this.savedContent &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering: are these values ever strict equal? this.savedContent seems to change all the time, so it will never be strictly equal to the value prop? I'm also having a hard time understanding why we need to check three different values here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is that before calling this.props.onChange we save the value in this.savedContent that way when the component is rerendered with the newly provided value prop. this check will fail this.props.value !== this.savedContent and we avoid calling updateContent (happens when you type continuously on a rich text element)

@ellatrix
Copy link
Copy Markdown
Member

Thank you! :)

@youknowriad youknowriad merged commit bb56c0e into master Feb 26, 2018
@youknowriad youknowriad deleted the update/comment-isequal-checks branch February 26, 2018 10:21
@ellatrix
Copy link
Copy Markdown
Member

Sorry for going on about this... but I want to understand the problem a bit better. Is this only a problem for multi line rich text areas? If so, why? Wy doesn't the stick equality work here? Are there other solutions to this? If not, we check for multi line instances here before we deep compare?

@ellatrix
Copy link
Copy Markdown
Member

This especially worries me since we're comparing React objects here, which, even if the content is the same might not be deep equal...

@youknowriad
Copy link
Copy Markdown
Contributor Author

@iseulde We do the comparison only if the previous checks pass, which doesn't happen so often. I don't know exactly why it's happening for multi-richtext blocks when moving the focus, I assumed it's happening because when you focusOut a new instance is generated somehow but can't tell exacly why, we'll have to look deeper.

@ellatrix
Copy link
Copy Markdown
Member

I know that it won't fire often, but it's just the principle and that it might change later on... I'd rather have we don't have to do this at all. I'll look into it a bit

@ellatrix
Copy link
Copy Markdown
Member

Fix coming :)

@ellatrix ellatrix mentioned this pull request Feb 26, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants