-
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
Text Block: Fix updating the content of an empty text block #512
Conversation
Yeah, twice Part of the problem might be that we're creating a new paragraph element each time https://github.com/WordPress/gutenberg/blob/f58fea4/blocks/library/text/index.js#L48 There might be a way to move this out of the Since I'm seeing Edit: Ah, I guess it's not a totally unnecessary render, because we're passing the |
A few more issues that are potentially related:
|
#507 seems to resolve the infinite loop I'm seeing when first adding the new text block. |
Should we merge this as is (it fixes a bug avoiding the usage of empty text blocks) and address performance issues later. Maybe related to #523 |
52dc81e
to
f95ffcf
Compare
The main problem is simply that we're creating a different reference for I toyed with this in a separate branch with acbcc90 and aca7a04, adding a Alternatively, I'm starting to question whether we need Aside: I rebased and force pushed the branch to account for changes merged in #507. |
This is needed when splitting/merging blocks because the update won't come from the block itself. It's also needed in undo/redo. I'm Ok with the |
We could do a combination of the two where we prefer to do a strict equality test, and only in the case that they differ, do a deeper check to verify that the content has indeed changed, either with So condition becomes: value !== prevProps.value &&
! deepEquals( value, prevProps.value ) |
f95ffcf
to
2b67550
Compare
2b67550
to
e3438e3
Compare
@aduth Tried and seems to work properly |
Just worried about some of the internal properties that React assigns, like Do you still think there's value in the changes explored in my |
@aduth I think the |
Brain-dump of my considerations.
attributes: ( rawContent ) => {
return {
content: parse( rawContent, children() ) || <p />
};
}
const DEFAULT_CONTENT = <p />;
// ...
edit( { attributes } ) {
const { content = DEFAULT_CONTENT } = attributes;
// ...
} Not sure if either of these sound more appealing to you. |
Also, there's alignment with React's |
I have a preference for I like the flexibility of the |
Pushed default attributes behavior. This LGTM now if you agree to these changes 👍 |
Treating
Editable
's value as a React Element introduced a regression when updating the content of an empty text block. The content of the text block was constantly being reset to "empty" because theupdateContent
was called too many times.This fix may cause a performance loss (not noticeable right now for me).