Align default document initialization ids#370
Merged
Conversation
Reviewer's GuideAlign default document initialization IDs and Yjs client IDs with the Rust/collab server by deriving them deterministically from the document UUID, and adjust initialization/deletion logic and tests to ensure stable paragraph/children/text IDs and correct CRDT merging behavior. Sequence diagram for deterministic default document initializationsequenceDiagram
participant Caller
participant YDoc
participant YSharedRoot as SharedRoot
participant Utils as YjsUtils
Caller->>Utils: initializeDocumentStructure(doc, documentId, includeInitialParagraph)
alt documentId is provided
Utils->>Utils: defaultDocumentInitClientId(documentId)
Utils->>YDoc: set clientID to defaultDocumentInitClientId(documentId)
end
opt includeInitialParagraph
Utils->>Utils: nanoidFromDocumentId(documentId, block)
Utils->>Utils: nanoidFromDocumentId(documentId, children)
Utils->>Utils: nanoidFromDocumentId(documentId, text)
Utils->>YSharedRoot: sharedRoot.set(document)
end
alt documentId is provided
Utils->>YDoc: restore original clientID
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Directly mutating
doc.clientIDininitializeDocumentStructurecould be fragile if Yjs treats this as internal/readonly state; consider using a separate initialization doc or a Yjs-supported way to emulate a stable init client rather than reassigning the client ID on the existing instance. - Now that
pageIdFromDocumentIdandidFromDocumentIdthrow on invalid UUIDs, it may be worth reviewing/guarding call sites so that unexpected runtime errors are avoided and invalid IDs are rejected closer to their source. - In
deleteBlock, the new cleanup logic assumesblock_childrenandblock_external_idare always present and valid; if older data or malformed blocks are ever encountered, you may want to null-check these IDs before using them to delete fromchildrenMap/textMapto avoid runtime errors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Directly mutating `doc.clientID` in `initializeDocumentStructure` could be fragile if Yjs treats this as internal/readonly state; consider using a separate initialization doc or a Yjs-supported way to emulate a stable init client rather than reassigning the client ID on the existing instance.
- Now that `pageIdFromDocumentId` and `idFromDocumentId` throw on invalid UUIDs, it may be worth reviewing/guarding call sites so that unexpected runtime errors are avoided and invalid IDs are rejected closer to their source.
- In `deleteBlock`, the new cleanup logic assumes `block_children` and `block_external_id` are always present and valid; if older data or malformed blocks are ever encountered, you may want to null-check these IDs before using them to delete from `childrenMap`/`textMap` to avoid runtime errors.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
Tests
Companion server PR: https://github.com/AppFlowy-IO/AppFlowy-Cloud-Premium/pull/681
Summary by Sourcery
Align default document initialization with server-generated IDs and deterministic client identification for collaborative editing.
New Features:
Bug Fixes:
Enhancements:
Tests: