-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Real-time collaboration: Add support for syncing post meta #72332
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
Conversation
|
Size Change: +208 B (+0.01%) Total Size: 2.07 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 36afbb3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18505483594
|
| const shouldSync = Boolean( | ||
| applyFilters( | ||
| 'sync.shouldSyncMeta', | ||
| ! metaKey.startsWith( '_' ), |
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 we also consider meta which can be multiple? i.e. when single is false as per: https://developer.wordpress.org/reference/functions/register_meta/. Unsure how often this is used but given it's a default, it's probably worth considering, particularly if we are syncing the 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.
This will work as-is since the values are merged using our existing (recursive) mergeValues. Added a test for this in 6ec79a0
| */ | ||
| const shouldSync = Boolean( | ||
| applyFilters( | ||
| 'sync.shouldSyncMeta', |
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.
Why do we need a filter, why can't we just sync everything? Also, why aren't we syncing private meta (that starts with _). I'm wondering if the security should be at another level, in other words, if a user is able to start a collaborative session for a given "document"/"post" than that user probably already has the right permissions to see the full object.
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.
Why do we need a filter, why can't we just sync everything?
It was initially committed because we implemented CRDT persistence in our plugin and needed a way to exempt it from syncing. If CRDT persistence is merged upstream it can be a single hardcoded exception in the Gutenberg codebase.
Since post meta intersects significantly with plugins, we did wonder if there might be very large post meta values or quirky implementations that need an opt-out filter. I'll remove it until specific examples materialize.
Also, why aren't we syncing private meta (that starts with _).
This is due to an overabundance of caution and an incomplete understanding of "hidden" post meta. The docs seem to indicate that they are used with "classic" meta boxes which might not be compatible with syncing anyway. Again, I'll remove it pending a stronger reason.
if a user is able to start a collaborative session for a given "document"/"post" than that user probably already has the right permissions to see the full object.
Agreed, thanks.
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.
Done in 6814b70
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
36afbb3 to
6814b70
Compare
| // should be synced. | ||
| Object.entries( newValue ?? {} ).forEach( | ||
| ( [ metaKey, metaValue ] ) => { | ||
| if ( disallowedPostMetaKeys.has( metaKey ) ) { |
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 is an empty array, we can remove it as well.
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.
When I merge #72373, I will need to add the CRDT post meta to the set.
youknowriad
left a comment
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 :)
6ec79a0 to
3e14fbe
Compare
* Add support for syncing post meta * Sync all meta by default * Add test for non-single meta * Add CRDT persistence meta key to disallowed set
* Add support for syncing post meta * Sync all meta by default * Add test for non-single meta * Add CRDT persistence meta key to disallowed set
What?
Add support for syncing post
metafields in addition to core fields liketitle,blocks, etc.Why?
Post meta fields are central to the editing experience.
How?
In order to be synced, post meta must be registered with the
show_in_restargument set totrue. Otherwise, it is not available to thecore-datastore.Automatically syncing all post meta is probably not desirable behavior. As a default stance, we exclude "hidden" post meta fields (whose meta key begins with an underscore). This gives plugins a code-free path to opting out. We provide a filter that allows plugins to override that default stance.
Testing Instructions
Testing Instructions for Keyboard
No UI changes in this PR.
Screenshots or screencast
post-meta.mov