-
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
Blocks: Avoid setAttributes on end-of-paragraph split #7482
Conversation
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.
LGTM 👍
I've a few things I'm looking into before merging this:
|
core-blocks/paragraph/index.js
Outdated
} = this.props; | ||
|
||
if ( after ) { | ||
// After content should be appended to the set of spread blocks as |
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.
This comment was a bit hard to understand.
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.
This comment was a bit hard to understand.
Updated in 2ea9199.
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 good to me. Thanks for adding comments!
For locked blocks. See also: #6587
Accommodates case where childNodes exist, but none which would qualify after filtering. Also preserves existing logic for detecting / handling paste context.
785bea9
to
7a8ec43
Compare
Updates:
|
I think we are stilling making a non required setAttributes call. I added this paragraph as the content of the post:
I opened redux dev tools in core/editor store. It is possible to check that we are doing a non required UPDATE_BLOCK_ATTRIBUTES also by inserting many paragraphs without any content. To undo each paragraph creation we need to use undo two times. |
@jorgefilipecosta Nice catch. I can reproduce this. However, I think it's a totally separate issue. Namely, we're causing |
This pull request is part of a performance audit of the paragraph block. It seeks to resolve an issue where we needlessly call
setAttributes
on a paragraph block when splitting into a new paragraph, and avoids potentially heavy processing withinRichText
to determinebefore
andafter
fragments when it can be inferred by the position of the selection at the end/beginning of theRichText
field whether the existing value can be used verbatim; thus also giving opportunity for the paragraph block to do a strict comparison against its owncontent
attribute to determine whethersetAttributes
needs to be called.This is one of two
setAttributes
calls which are currently invoked on the original paragraph when pressing enter at the end of its text. The other is explained at #4956 (comment) .Testing instructions:
Verify there are no regressions in the behavior of paragraph splitting.
Optional: Validate that
UPDATE_BLOCK_ATTRIBUTES
is dispatched only once (erroneously, vs. twice on master) when pressing enter at the end of a paragraph block using Redux DevTools Extension.