-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Real-time collaboration: Enable CRDT doc state map changes #72763
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
Closed
+205
−0
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59ed61c
Re-add state map specific notifications
ingeniumed 891bc45
Remove the post restored toasts
ingeniumed 200b5ce
Simplify the code and update the tests
ingeniumed 56b0141
Correct the name of the function
ingeniumed 6175b5f
Move from using the pre post save fcn to an action run post save
ingeniumed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Move from using the pre post save fcn to an action run post save
- Loading branch information
commit 6175b5ff1227c1246f18b095628a70b0e1d400c3
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,11 @@ | |
| */ | ||
| import * as Y from 'yjs'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { addAction } from '@wordpress/hooks'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
|
|
@@ -11,6 +16,7 @@ import { | |
| LOCAL_SYNC_MANAGER_ORIGIN, | ||
| CRDT_STATE_PERSISTED_AT_KEY as PERSISTED_AT_KEY, | ||
| CRDT_STATE_PERSISTED_BY_KEY as PERSISTED_BY_KEY, | ||
| LOCAL_EDITOR_ORIGIN, | ||
| } from './config'; | ||
| import { createPersistedCRDTDoc, getPersistedCrdtDoc } from './persistence'; | ||
| import { getProviderCreators } from './providers'; | ||
|
|
@@ -147,6 +153,20 @@ export function createSyncManager(): SyncManager { | |
| handlers.editRecord( { meta } ); | ||
| handlers.saveRecord(); | ||
| } | ||
|
|
||
| addAction( | ||
| 'editor.savePost', | ||
| 'sync.markCRDTDocPersisted', | ||
| async ( post, options ) => { | ||
| // Skip if the post's id doesn't match (including different ID types), or if it's an autosave. | ||
| if ( post.id !== objectId || options.isAutosave ) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I skipped auto saves at the moment, to keep it similar to Gutenberg where a notice would be sent if you hit the save yourself. The post ID check is for safety, and would account for even the ID format not being supported. Is it worth adding an extra post type check too? |
||
| return; | ||
| } | ||
|
|
||
| // Mark the CRDT document as having been persisted. | ||
| recordPersistence( objectType, objectId, LOCAL_EDITOR_ORIGIN ); | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@chriszarate - lemme know what you think about this new way to track a post being saved. This action is fired async at the very end of a post save, so we know it's been persisted.
Now, it's possible to actually use this key to track if a refetch needs to happen or stick to just notifications.
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 kept this here as it felt like the right place, since it's where the ydoc is bootstrapped. We aren't changing anything about the post just tracking it really.