fix: preserve block identity during type conversion#325
Merged
Conversation
Reviewer's GuideThis PR updates the Yjs block type conversion and Slate sync pipeline so that compatible text block type changes happen in-place (preserving block/text IDs and children), while incompatible conversions continue to replace/flatten blocks, and remote same-id type/data updates are applied to matching Slate nodes with new tests covering these behaviors. Sequence diagram for applying same-id Yjs block type/data updates to SlatesequenceDiagram
participant YjsDoc
participant translateYEvents
participant applyUpdateBlockYEvent
participant SlateEditor as editor
YjsDoc->>translateYEvents: YMapEvent
translateYEvents->>applyUpdateBlockYEvent: applyUpdateBlockYEvent
applyUpdateBlockYEvent->>applyUpdateBlockYEvent: block.get block_type
applyUpdateBlockYEvent->>applyUpdateBlockYEvent: block.get block_data
applyUpdateBlockYEvent->>applyUpdateBlockYEvent: dataStringTOJson
applyUpdateBlockYEvent->>applyUpdateBlockYEvent: findSlateEntryByBlockId
applyUpdateBlockYEvent->>applyUpdateBlockYEvent: isEqual oldData, newData
alt type or data changed
applyUpdateBlockYEvent->>SlateEditor: apply { type: set_node, path, newProperties, properties }
else no change
applyUpdateBlockYEvent-->>translateYEvents: []
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR aligns the web editor with the desktop shared-block fix by preserving block identity during safe text block type conversions.
Key changes:
turnToBlockso paragraph/list/heading/quote/todo-style conversions update the existing Yjs block type/data in place when the target block can safely keep the same child shape.Related GitHub Issues
Failed to apply update: block parent ... Type: 8.Type: 8document-open failure on Linux.Root Cause
The old conversion path modeled type changes as delete old block plus insert new block. That preserved the visual document shape, but changed block identity and regenerated related refs. Under high edit churn, especially markdown shortcuts and list/toggle conversions, persisted Yjs updates could later contain a child item whose parent was not a shared collection or tombstone, producing the
Type: 8open failure.Compatibility
Desktop Alignment
Companion desktop PR: AppFlowy-IO/AppFlowy-Premium#979
Desktop uses the same architecture end-to-end through Flutter editor operations, the transaction adapter, Rust
update_type, collab in-place type updates, and remote diff support.Test Coverage
Verification
pnpm jest src/application/slate-yjs/__tests__/yjs-utils.test.ts src/application/slate-yjs/__tests__/applyToSlate.test.ts --runInBand --no-coveragepnpm run type-checkpnpm exec eslint --quiet --ext .ts src/application/slate-yjs/__tests__/applyToSlate.test.ts src/application/slate-yjs/__tests__/yjs-utils.test.ts src/application/slate-yjs/utils/yjs.ts --ignore-path .eslintignore.webpnpm exec prettier --check src/application/slate-yjs/__tests__/applyToSlate.test.ts src/application/slate-yjs/__tests__/yjs-utils.test.ts src/application/slate-yjs/utils/yjs.tsSummary by Sourcery
Preserve Yjs block identity during safe text block type conversions and ensure remote block type/data updates apply correctly to matching Slate nodes.
Bug Fixes:
Enhancements:
Tests: