-
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
Parser: Refactor meta parsing as filtered external source #5077
Conversation
Originally seemed redundant, but could be confused with e.g. block schema
My eyes apparently can't distinguish between an "if" and an "else if"
@@ -118,7 +119,15 @@ export function getBlockAttribute( attributeKey, attributeSchema, innerHTML, com | |||
break; | |||
} | |||
|
|||
return value === undefined ? attributeSchema.default : asType( value, attributeSchema.type ); | |||
value = applyFilters( 'blocks.getBlockAttribute.source', value, attributeSchema, innerHTML, commentAttributes ); |
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.
Do we really need two filters? blocks.getBlockAttribute
and blocks.getBlockAttribute.source
@@ -0,0 +1,28 @@ | |||
/** |
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'd expect this file to live in editor.hooks
for now. I understand that it's post related but I believe the refactoring to extract all post related stuff should be done in one step instead of introducing inconsistency.
// editor initialization firing post reset as an effect. | ||
partialRight( withChangeDetection, { resetTypes: [ 'SETUP_NEW_POST', 'RESET_POST' ] } ), | ||
// Track whether changes exist, resetting at initialization and each save. | ||
partialRight( withChangeDetection, { resetTypes: [ 'RESET_POST', 'SETUP_NEW_POST', 'RESET_BLOCKS' ] } ), |
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.
RESET_BLOCKS is also triggered in the text editor and it should not reset dirty detection in that case
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.
RESET_BLOCKS is also triggered in the text editor and it should not reset dirty detection in that case
Sigh... maybe we need a dedicated "editor ready" action in addition to the SETUP_EDITOR
one 😅
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.
Should switching editors affect history? It's kind of a destructive action that, as a user, I wouldn't expect from just switching editor modes.
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.
Should switching editors affect history? It's kind of a destructive action that, as a user, I wouldn't expect from just switching editor modes.
I'd look into preserving history across modes. I've experienced content loss firsthand through something like that (Calypso editor): some Heisenbug in Visual makes content disappear, toggle to Code, notice it's empty, come back to Visual, find no edit history to recover the content.
} | ||
|
||
return value; | ||
} |
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.
So right now, retrieving the attribute is done using a filter but updating this source type is still achieved using hard-coded code. I believe we should create a filter for it aswell?
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.
If I understand correctly, I believe this change is creating an issue if you use the same attribute in two different blocks. Their value won't be synced in which I case I'd prefer if we introduce a hook (or something else) to allow this syncing.
Thanks for the review @youknowriad . I'm going to set aside the meta refactoring for post-2.2, but we should really resolve the issue with an initial undo level for the release. I can take a look once I sort through other updates this morning. |
Removed from 2.2 milestone per separately addressing initial undo history in #5101. |
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.
Looks good so far, though I'll wait for answers/fixes to Riad's feedback.
// editor initialization firing post reset as an effect. | ||
partialRight( withChangeDetection, { resetTypes: [ 'SETUP_NEW_POST', 'RESET_POST' ] } ), | ||
// Track whether changes exist, resetting at initialization and each save. | ||
partialRight( withChangeDetection, { resetTypes: [ 'RESET_POST', 'SETUP_NEW_POST', 'RESET_BLOCKS' ] } ), |
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.
Should switching editors affect history? It's kind of a destructive action that, as a user, I wouldn't expect from just switching editor modes.
I'd look into preserving history across modes. I've experienced content loss firsthand through something like that (Calypso editor): some Heisenbug in Visual makes content disappear, toggle to Code, notice it's empty, come back to Visual, find no edit history to recover the content.
While I'm still curious to explore related refactoring, it's unlikely I'll resume this branch in its current form. |
Fixes #4989
This pull request seeks to refactor meta attributes as injected during a parse via filtering applied by the
edit-post
module. This resolves issues where validation could fail because meta attributes are not known at parse-time, and should improve performance of thegetBlock
selector by avoiding an iteration over block attributes.Testing instructions:
Verify that there are no regressions in the behavior of meta attribute usage.
Here's an example meta-based "Stars Block" plugin if you don't have a meta-driven block handy:
https://cloudup.com/files/i02CNzKdB5f/download
Specifically, ensure that meta values can be manipulated, saved, and restored (with value represented correctly, and validation passing).
Ensure unit tests pass:
Known Issues:
Need to ensure post doesn't have history when editing. This issue exists on master as well.Fixed in 4acb4f3.Edit: High priority reflects that this is not only concerning to performance of
getBlock
, but that having undo history immediately upon loading a saved post is quite non-ideal (and potentially destructive, because using the undo will remove all content).Edit 2: Initial undo history resolved separately in #5101.