-
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
Automatically assign block ids to pattern blocks for use in partial synching of pattern instances #56495
Automatically assign block ids to pattern blocks for use in partial synching of pattern instances #56495
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/blocks.php ❔ lib/experimental/connection-sources/index.php |
Size Change: +585 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
This tested well for me. I think it would be worth investigating some sort of unique id generation so we can avoid the additional post meta if possible. |
8795b9f
to
c547ad3
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.
Looks really good! Most of the comments are pretty minor.
}, | ||
metadata: { | ||
...attributes.metadata, | ||
id, |
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 might not be a final name while we're in the early stages of development, but I think the id
could still be named a bit more descriptively.
connectionId
is an option, though I don't think it will be used by other types of connections (custom fields), so that could be misleading.partialSyncId
might be better for now. Anyone that encounters it will know exactly what it relates to.dynamicContentId
orpatternAttributeId
could also be options.
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 think id
could potentially be good if we want to extend it to similar features in the future. Otherwise, we might also want to consider putting this id inside connections
rather than metadata
.
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.
Moving it to the connections object might be a good short-term measure.
Metadata is quite general, so folks might consider it as used for an html id or something.
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.
Yeh, I can't remember the reason for using the new metadata
attrib in that original PR. I think given where we are now at with the pattern syncing it will be safer to move it into the connections object so the purpose is clearer.
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 believe it's because the Block Naming API is using metadata.name
? I don't mind switching it to connections.id
for now but we can't really change it (well we can but it'll be painful 😆) after it's saved. AFAIK, the metadata
attribute is a preserved attribute that only core could use it (or else the block naming API would be broken 😅). I'd prefer putting it inside metadata
so that other future APIs could reuse it if they want something like a serverId
or internalId
(as opposed to clientId
). Now that we're using nanoid
, it should be pretty safe to assume that it's unique across blocks too. But yet again, we could always change back to metadata.id
once we finalize the API in connections
😆.
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.
one option would be metadata.staticId
to indicate it is an id that is permanent and serialised with content as distinct from the dynamic clientId
|
||
function PartialSyncingControls( { attributes, setAttributes } ) { | ||
// Only the `content` attribute of the paragraph block is currently supported. | ||
const attributeName = 'content'; |
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 guess we need to think about how to control which blocks/attributes are supported. It might be as simple as some config:
`PARTIAL_SYNC_SUPPORT = {
'core/paragraph': { attributes: [ 'content' ] }
}
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 change in this file is basically reverting it to pre-#56235.
packages/patterns/package.json
Outdated
@@ -44,7 +44,8 @@ | |||
"@wordpress/icons": "file:../icons", | |||
"@wordpress/notices": "file:../notices", | |||
"@wordpress/private-apis": "file:../private-apis", | |||
"@wordpress/url": "file:../url" | |||
"@wordpress/url": "file:../url", | |||
"nanoid": "^4.0.2" |
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.
nanoid
is roughly 100 bytes gzipped.
This is testing well for me! Thanks for all your work on this. |
01c9aa9
to
f77ed76
Compare
f77ed76
to
e70b253
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.
It seems like this is in a good enough place to merge into #56235 so we can do some final testing there to make sure everything is working fine behind the new experimental flag - what do you think?
fd0d8e3
into
try/partial-sync-no-monkey-patching
* Try using the block connections api * Fix native * Rename dynamicContent to overrides * Add new experiment flag for partial syncing * Automatically assign block ids to pattern blocks for use in partial synching of pattern instances (#56495) * Automatically assign block ids * Downgrade package to fix tooling * Move to the editor package and allow core/button * Fix test resolver * Fix the flag and remove support for core/button * Address code reviews * Rename to pattern/overrides * Fix php lint error --------- Co-authored-by: Aaron Robertshaw <[email protected]> Co-authored-by: Glen Davies <[email protected]>
What?
Based on #56235. Automatically assign block ids when selecting blocks and attributes to be partially synced.
Why?
This is needed so that users don't have to manually assign ids which could be outdated and/or collide with each other.
How?
Use
nanoid
to generate unique id for each block. The size of 6 has 1% chance to collide when generating 37k ids, which is sufficient enough to prevent collision in our use case.Testing Instructions
Follow the instructions in #55807.
Screenshots or screencast
Kapture.2023-11-24.at.15.37.52.mp4