-
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
Fix reusable block crash when converting a just created reusable block to blocks. #29292
Conversation
Size Change: +2.21 kB (0%) Total Size: 1.38 MB
ℹ️ View Unchanged
|
It seems this has been a problem since #25859 switched from using |
I discovered this is actually really easy to reproduce by editing a created reusable block and trying to convert it back to regular blocks before saving. That made the test case much easier to write. I think this problem will have been made more common by recent changes to reusable blocks. Back when they had a more distinct editing/saved state it would be difficult to do this. The bug reports indicate it probably happened only with particular blocks, but now it could quite easily happen with any block. |
@@ -297,4 +297,29 @@ describe( 'Reusable blocks', () => { | |||
expect( content ).toEqual( 'Awesome Paragraph modified' ); | |||
} ); | |||
} ); | |||
|
|||
// Check for regressions of https://github.com/WordPress/gutenberg/issues/26421. | |||
it( 'allows conversion back to blocks when the reusable block has unsaved edits', async () => { |
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.
Thanks for the test.
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.
Thanks for the fix.
I think ideally these "function as edit" behavior should be something only internal to core-data but a change like that would require a lot more thinking and impact so this is a good fix for now.
…k to blocks. (#29292) * Fix reusable block crash when content is a function * Fix incorrect arg to content function * Add an e2e test
…k to blocks. (#29292) * Fix reusable block crash when content is a function * Fix incorrect arg to content function * Add an e2e test
Proper fix already released in WordPress/gutenberg#29292
Description
Fixes #26421
Reusable blocks crash on conversion when they have unsaved edits.
This happens because the entity
content
prop is passed to the blocksparse
function. Usually that's ok, because it'll be a string. But when a reusable block has unsaved edits,content
is a function thatparse
doesn't know how to handle.The content function is created here:
gutenberg/packages/core-data/src/entity-provider.js
Lines 183 to 187 in 60314e8
It looks like this function is called on
saveEntityRecord
, but is otherwise stored internally as a function:gutenberg/packages/core-data/src/actions.js
Lines 386 to 394 in 5d3681a
This became an issue in #25859, where reusable blocks were switched over to using the entity system. Before that they did a plain
apiFetch
and as far as I can tell always dealt with stringcontent
.How has this been tested?
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: