Skip to content

Conversation

@alecgeatches
Copy link
Contributor

What?

Closes

Why?

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

chriszarate and others added 29 commits June 27, 2025 11:30
* [Yjs Collab] WIP - Sync changes on (auto)save using Yjs

Previously, Gutenberg implemented a basic Yjs editor binding. Changes
were synced using y-webrtc when collaborative editing is enabled.
However, the previous implementation did not reliably sync the
backend-state with the Yjs document. Hence, the previous implementation
could result in content duplication, or loss of changes that were
created in the collaborative session.

This commit implements the initial approach to sync the backend document
(HTML encoded) with the Yjs document without the server understanding
Yjs.

Following things were implemented:

- We save the Yjs document in an HTML comment, that is stored in the
  HTML document stored in WordPress
- When the client notices that the Yjs document stored in the comment
  does not reflect the state of the HTML document, we assume that the
  changes were generated by the backend. Hence we update the document
  that is stored in the HTML comment, and merge the Yjs update to the
  Yjs document that is used in the collaborative session. Then we save
  the merged document once again to the backend.

The changes from a backend are applied as a simulated "system user".
This should guarantee that everyone applies the changes in the same way,
so we avoid content duplication. The
approach in this commit is still insufficient. We need to store
additional information in the backend to ensure that certain edge-cases
are handled.

* [Yjs Collab] update used dependencies

* [Yjs Collab] fix collab issues introduced in upstream - ensure that entities are always registered.

* [Yjs Collab] Use heartbeat api to pull ydoc updates

* [Yjs Collab] cleanup

* [Yjs Collab] improve diffing

* [Yjs Collab] loss of selection & focus when content is saved

* [Yjs Collab] add origin to changes originating from gutenberg

* [Yjs Collab] documentation

* [Yjs Collab] improve docs

* [Yjs Collab] several bugfixes

* [Yjs Collab] add different feature flags for sync on save / heartbeat sync / webrtc sync

* [Yjs Collab] Fix typo in lib/experimental/synchronization.php

Co-authored-by: Aaron Jorbin <[email protected]>

* [Yjs Collab] user wp_rand instead of rand

Co-authored-by: Aaron Jorbin <[email protected]>

* [Yjs Collab] Update regexes and priorities for synchronization filters

As @aaronjorbin rightfully pointed out, the new filters approach don't
need to run at the end anymore.

* [Yjs Collab] implement get_yinfo function in synchronization.php

* [Yjs Collab] fix tests

* [Yjs Collab] fix php lint issues

* [Yjs Collab] fix mobile tests

* Remove heartbeat experiment

* Add core.getSyncProvider filter

---------

Co-authored-by: Kevin Jahns <[email protected]>
Co-authored-by: Aaron Jorbin <[email protected]>
* Refactor filtering to avoid import conflicts

* Add "node" to the base types array

Without this, type building fails for the sync package, despite the fact
that itself has this statement in its `tsconfig.json`. Is that config
ignored? Why are types so fragile?

* Revert "Add "node" to the base types array"

This reverts commit e0c4ecf.

* Add "node" types to packages that consume @wordpress/sync
Going to override the setting within the plugin rather than this way :)
* Add the Yjs undo manager

* Got undo manager working

* Cleaned up the code a bit, and added comments

* Redo the entire undomanager to work agnostic of the objectType. Also began to allow switching between the different undo managers

* Fix the type errors

* Document the methods better

* Add comments, and fix the package-lock not being complete

* Updated the lib0 package to fix the react native problem

* ignore the launch.json

* Update the packages, and enable the remoteMap fix
* Convert the sync packages to typescript - part 1

* Converted everything else to typescript as well

* Remove the last @type

* Undo renaming js to ts for files that should stay the same
…editing' into add/experimental-collaboration-awareness
@github-actions
Copy link

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: chriszarate <[email protected]>
Co-authored-by: ingeniumed <[email protected]>
Co-authored-by: alecgeatches <[email protected]>
Co-authored-by: pkevan <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants