-
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
Error when deprecating the default value of a block attribute #11705
Comments
What you're seeing is expected behavior.
That's not possible. Every block is validated against the registered block type. When you try to edit an existing block after changing the block type's data, there's obviously a mismatch. The correct way to change default values like you describe is to use the block deprecation feature. Please have a look at https://wordpress.org/gutenberg/handbook/block-api/deprecated-blocks/ for how deprecations work. |
Hi @swissspidy. Yes I'm deprecating blocks right now. I'll explain my scenario more below. The issue I think is when I have a block with an attribute like this: height: {
type: 'number',
default: 400,
}, I then create a page with that block and leave the Then I deprecate the block's attributes and then change the default value in my original attribute list: height: {
type: 'number',
default: 300,
}, Note that the deprecated attribute still has the value at Editing the page now shows an error. |
Did a bit of debugging and managed to reproduce the issue on the columns block by deprecating it and changing the default columns attribute to a different value. The issue seems to be a problem for attributes that aren't sourced. When assessing whether a deprecation is valid, the default from the current set of attributes is applied instead of the default from the deprecated attributes. This causes the deprecation to fail validation, and so it's skipped here in the gutenberg/packages/blocks/src/api/parser.js Lines 338 to 353 in 40d1282
|
The root cause of the issue is that when I initially saved the columns block, its default
Which seems weird, I would have expected this as the first line:
Not sure if this is a recent change or if it has always been the case. Will continue digging. edit - this has been the case for a long time, I must never have noticed this behaviour - gutenberg/packages/blocks/src/api/serializer.js Lines 162 to 164 in 40d1282
|
Hi @bfintal - thanks for the report. I also think this might be a bug. I've put in a PR for a fix, will hopefully get some guidance from a developer with more experience of this part of the codebase. |
Describe the bug
Changing a custom block's default attribute value results in the error:
This block contains unexpected or invalid content.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The previously added block shouldn't have an error. Since the block with the error was old, I expect that it shouldn't be affected with a change in an attribute's default value.
Also, removing the default value doesn't result in an error, but changing it does.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: