Skip to content

[lexical-yjs] Bug fix: don't rewrite unchanged non-primitive property/state values to yjs in collab v2#7990

Merged
etrepum merged 1 commit intofacebook:mainfrom
james-atticus:yjs-skip-sync-deep-equal-state
Nov 14, 2025
Merged

[lexical-yjs] Bug fix: don't rewrite unchanged non-primitive property/state values to yjs in collab v2#7990
etrepum merged 1 commit intofacebook:mainfrom
james-atticus:yjs-skip-sync-deep-equal-state

Conversation

@james-atticus
Copy link
Copy Markdown
Contributor

@james-atticus james-atticus commented Nov 14, 2025

Description

When syncing properties/state to Yjs in collab v2, I was doing a shallow equality check on the values in Yjs and Lexical. The former however was coming from yDomFragment.getAttributes() which may not have been reference-equal. This meant that any non-primitive values for properties or state could end up being re-written to Yjs whenever the node was dirty.

This is particularly a problem when GC is disabled on the ydoc as you end up building up a lot of cruft.

The fix is to do a deep equality check, which is what the code was already doing for equalYTypePNode, as equalAttrs is recursive.

Test plan

Added unit test fails before, passes after the change.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 14, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Nov 14, 2025 4:07am
lexical-playground Ready Ready Preview Comment Nov 14, 2025 4:07am

@james-atticus james-atticus changed the title [lexical-yjs] Bug fix: don't re-write unchanged non-primitive property/state values to yjs in collab v2 [lexical-yjs] Bug fix: don't rewrite unchanged non-primitive property/state values to yjs in collab v2 Nov 14, 2025
@etrepum etrepum added this pull request to the merge queue Nov 14, 2025
Merged via the queue into facebook:main with commit 4bbbd8b Nov 14, 2025
40 checks passed
@etrepum etrepum mentioned this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants