-
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
Blocks: simplify/optimise isUnmodifiedBlock #56919
Conversation
Size Change: -32 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 4e48a90. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7179834066
|
cf61631
to
a1a7015
Compare
Initial testing seems good at the Gutenberg previewer. |
function isEqual( a, b ) { | ||
return ( a?.valueOf() ?? a ) === ( b?.valueOf() ?? b ); | ||
} | ||
return Object.entries( getBlockType( block.name )?.attributes ?? {} ).every( |
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.
we're checking the attributes on the block type here, but would it be important to compare also the attributes on this particular block instance that may not be on the block type?
for instance, if I setAttribute('formerlyNotPresentAttribute', true)
then I would imagine I have a modified block, but the block type won't have formerlyNotPresentAttribute
so it won't show different here
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.
We didn't before. And I guess if it's not officially declared, why check?
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.
I missed that in the before code. makes me wonder anyway if it's been a latent bug. no need to make it part of this change.
a1a7015
to
4e48a90
Compare
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.
The logic of the change is good for me. It makes me wonder why we're calling this function so often?
Yes, the only suspects are block popover and the inserter/appender. But block popover doesn't show when typing, though we might be calling those selectors. We might also be calling appender selectors. Might have a look at some point. |
What?
This is one of the functions I see pop up a lot in the performance graph for the
input
event, due to the rich text value to store PR (#43204). Because we're now comparing.valueOf()
, these attributes are now serialised to check strict equality.This PR changes to function to look at the defaults in the attribute definition. If the attributes don't match the defaults, or are not empty, it means the block was modified.
Why?
This function runs on typing so it's important to change. It's also simpler.
How?
Described above
Testing Instructions
No tests should fail.
Testing Instructions for Keyboard
Screenshots or screencast