Skip to content

fix: stop emitting a delete op for attributes that are already absent - #84

Open
bxff wants to merge 1 commit into
loro-dev:mainfrom
bxff:fix-null-attr-delete-ops
Open

bxff wants to merge 1 commit into
loro-dev:mainfrom
bxff:fix-null-attr-delete-ops

Conversation

@bxff

@bxff bxff commented Aug 24, 2026

Copy link
Copy Markdown

When a ProseMirror schema declares an attribute with default: null, updateLoroMapAttributes calls attrs.delete(key) on every sync even if the key was never written to the Loro map, and LoroMap.delete records an op whether or not the key exists. The visible symptom: every editor transaction over such a node produces an empty Loro change, which between two peers becomes an endless idle back-and-forth of updates. It can also lose data, since the spurious delete is a real concurrent op — if peer A sets checked: true while peer B types anywhere, B's delete can win the merge and silently revert the attribute, leaving it gone on both peers. Fix: guard the delete with the key set the function already builds from attrs.keys(), so a null attribute that's actually in the map still gets removed and one that was never there produces no op. Added a test that fails on main with [{ type: 'delete', key: 'checked' }], plus one for the non-null → null case to make sure the real delete path still works.

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.

1 participant