Skip to content

Real-time collaboration: Add type guard for rich-text attributes#73946

Merged
chriszarate merged 2 commits into
trunkfrom
fix/crdt-ytext-guard
Dec 15, 2025
Merged

Real-time collaboration: Add type guard for rich-text attributes#73946
chriszarate merged 2 commits into
trunkfrom
fix/crdt-ytext-guard

Conversation

@chriszarate
Copy link
Copy Markdown
Contributor

What?

Introduce a type guard to ensure that a rich-text attribute is represented by a Y.Text type.

Why?

Our assumption that an attribute is represented in the CRDT doc as a Y.Text instance was based on the current block name, which may have changed as part of the current changeset. For example, a block can be transformed from core/freeform to core/paragraph. Both of those blocks carry a content attribute, but only the latter's is a rich-text attribute.

When this happens, we can encounter a fatal error in mergeRichTextUpdate by assuming a primitive string is a Y.Text instance.

How?

  1. Use an instanceof check.
  2. Add a test case.

Testing Instructions

  1. Check out this branch.
  2. Add a "Classic" block and type a sentence.
  3. Click "Convert to blocks."

Testing Instructions for Keyboard

n/a

ingeniumed and others added 2 commits December 11, 2025 19:32
* Check for the current attribute existing before proceeding

* Add a test for the new check added
@chriszarate chriszarate requested a review from nerrad as a code owner December 12, 2025 02:49
@chriszarate chriszarate added [Type] Bug An existing feature does not function as intended [Feature] Real-time Collaboration Phase 3 of the Gutenberg roadmap around real-time collaboration [Type] Experimental Experimental feature or API. labels Dec 12, 2025
@github-actions
Copy link
Copy Markdown

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.

  • Required label: Any label starting with [Type].
  • Labels found: [Type] Bug, [Feature] Real-time Collaboration, [Type] Experimental.

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.

@chriszarate chriszarate removed the [Type] Bug An existing feature does not function as intended label Dec 12, 2025
@github-actions
Copy link
Copy Markdown

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: ingeniumed <ingeniumed@git.wordpress.org>
Co-authored-by: chriszarate <czarate@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

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

@chriszarate chriszarate merged commit ccde9c0 into trunk Dec 15, 2025
42 of 48 checks passed
@chriszarate chriszarate deleted the fix/crdt-ytext-guard branch December 15, 2025 16:05
@github-actions github-actions Bot added this to the Gutenberg 22.4 milestone Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Real-time Collaboration Phase 3 of the Gutenberg roadmap around real-time collaboration [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants