-
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
Block API: Deprecate property
source
#7349
Conversation
I really like the proposed changes, in particular using |
a9578cd
to
c3b8354
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.
This looks great in general. I have some concerns regarding the deprecation strategy. While it is going to work for some time, what is your plan for getting rid of the source type completely. All deprecated schemas for blocks won’t work properly in such case.
blocks/api/parser.js
Outdated
@@ -70,6 +71,12 @@ export function matcherFromSource( sourceConfig ) { | |||
case 'attribute': | |||
return attr( sourceConfig.selector, sourceConfig.attribute ); | |||
case 'property': | |||
deprecated( '`property` source', { | |||
version: '3.3', |
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.
It’s now 3.4 🙁
...omit( schema, [ 'level' ] ), | ||
nodeName: { | ||
type: 'string', | ||
source: 'property', |
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.
What is going to happen when we completely remove source type property?
@@ -108,11 +174,12 @@ export const settings = { | |||
edit, | |||
|
|||
save( { attributes } ) { | |||
const { align, nodeName, content } = attributes; | |||
const { align, level, content } = attributes; | |||
const tagName = 'h' + level; |
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.
It’s alwas gambling to mix string and number in JS, but this is okey. Just noting 😃
...omit( schema, [ 'ordered' ] ), | ||
nodeName: { | ||
type: 'string', | ||
source: 'property', |
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 same issue applies when deprecated source is removed.
@@ -33,28 +33,6 @@ const multipleH1Headings = [ | |||
<em key="incorrect-message-multiple-h1">{ __( '(Multiple H1 headings are not recommended)' ) }</em>, | |||
]; | |||
|
|||
const getHeadingLevel = ( heading ) => { |
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.
Yeah, the best part of the refactoring introduced 👌
I think ultimately it will have to be removed, even if that means the deprecation will stop working as well (meaning it may as well be removed). Also hints at a question of: Will deprecations be included in the final merge of Gutenberg? Or will we assume a clean slate at that point? |
c3b8354
to
5e3b50e
Compare
Rebased to resolve conflicts and bump the deprecation version. Also updated To the point on deprecation: I think we'll just have to bite the bullet, remove the source and all the existing deprecations with it. |
anchor: true, | ||
}; | ||
|
||
const schema = { |
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 sometimes call this schema and sometimes attributes. We should be consistent.
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 sometimes call this schema and sometimes attributes. We should be consistent.
It's a silly variable shadowing issue. We assign attributes
in the edit
function as a variable from props, which would conflict with a variable of the same name in the top-level scope.
More generally, I wish there were an easier way to inherit overlapping values between the deprecation and the current version. Nothing coming to mind at the moment, but I'll think on it some.
@@ -13,6 +13,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo | |||
- `blocks.BlockEdit` filter removed. Please use `editor.BlockEdit` instead. | |||
- `blocks.BlockListBlock` filter removed. Please use `editor.BlockListBlock` instead. | |||
- `blocks.MediaUpload` filter removed. Please use `editor.MediaUpload` instead. | |||
- `property` source removed. Please use equivalent `text`, `html`, or `attribute` source, or comment attribute instead. |
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.
Hast to be moved to 3.2 list.
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.
It's good as is, this list contains details when a given feature is going to be removed rather when it was deprecated.
I fixed one bug which breaks deprecations for both blocks. With 1e0d25c it works as expected :) |
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.
To the point on deprecation: I think we'll just have to bite the bullet, remove the source and all the existing deprecations with it.
Yes, I didn't come up with anything that would help mitigate this. Let's proceed and hope for the best. It's the last release where this kind of breaking change is acceptable. I'll merge as soon as I figure out why Travis error.s
5a7ebec
to
ef36691
Compare
ef36691
to
7e9be8f
Compare
source: 'children', | ||
selector: 'h1,h2,h3,h4,h5,h6', | ||
}, | ||
level: { |
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.
Changing block attributes (nodeName replaced by level) is a breaking change and until now we don't warn about it (deprecated
call). This broke one of my plugins, I wonder if we can/should ensure Backwards compatibility 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.
Changing block attributes (nodeName replaced by level) is a breaking change and until now we don't warn about it (
deprecated
call).
I'm not sure I totally understand. The block attributes are a public API we should be guaranteeing compatibility for? Is this to do with block transforms? There is a deprecated
definition, though I sense it would not be enough for transforms (at least as currently implemented, though maybe possible to support).
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.
In this PR we removed the nodeName
attribute from the heading block and added a level
attribute. A plugin retrieving blocks (wp.data.select('code/editor').getBlocks()
) can expect heading blocks to have a nodeName
string attribute but it will fail since it will only find a level
instead.
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.
In this PR we removed the
nodeName
attribute from the heading block and added alevel
attribute. A plugin retrieving blocks (wp.data.select('code/editor').getBlocks()
) can expect heading blocks to have anodeName
string attribute but it will fail since it will only find alevel
instead.
So hypothetically speaking: What's the point of deprecated
if it's not enough to prevent cascading breaking effects?
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.
What I'm saying is should we support both nodeName
and level
for some time coupled with deprecated
? which hasn't been done in this PR (and it's not the only PR, just happened to be the one I noticed a bug with)
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 understand the breakage and potential remedy, just trying to think through how this is communicated: When deprecating a block attribute, is it not enough for a developer to be confident in using deprecated
, as this is all that we currently document in the handbook ? Does this apply to all blocks, or just core blocks ?
Related: #2751
This pull request seeks to deprecate the
property
source type. This was never publicly documented since it was always discouraged for use, but has been leveraged by core block implementations since earliest version of the plugin. Thus, while it's not expected that many plugin blocks will have used this source, there may be those where the core blocks had been used as a reference. The source will be removed in3.2.03.3.0.There was a single instance of the
property
source being used incorrectly when a more appropriate alternative exists (code).textContent
andinnerHTML
can be substituted with thetext
andhtml
sources respectively.The heading and list blocks were not as simple to transition, since they use
nodeName
as an indicator of heading level and ordered vs. unordered lists. These have been updated to newlevel
(number) andordered
(boolean) attributes, serialized by the block comment attributes, including deprecated migrations for each block. Alternatively, we could consider an equivalent source type for retrieving thenodeName
(or tag name) of a node, but this did not seem strictly necessary or a common enough use-case to justify.Testing instructions:
Verify that existing posts containing lists and/or heading and/or code blocks are migrated gracefully.
Verify that a deprecated warning is shown for blocks which use the
property
source.