Description
Currently, each block can have at most one top-level note attached to it. Subsequent notes are always forced to be a reply to the existing thread. This is because the block→note relationship is created by storing a single noteId in the block's metadata (block.attributes.metadata.noteId).
This limitation causes issues in several scenarios:
Related Issues
Current Implementation
The current code in packages/editor/src/components/collab-sidebar/hooks.js:
- Creates a 1:1 mapping:
blocksWithComments[clientId] = commentId (single value)
- Overwrites on create: When a new note is created during collaborative editing before a sync, it overwrites any existing note (instead of having two separate top level notes added)
- Clears entirely on delete: Removes the entire
noteId instead of a specific ID
Proposed Solution
Extend the existing noteId field to support either a scalar (number) or an array (number[]):
- Backwards compatible: Existing posts with scalar
noteId values work unchanged
- Lazy migration: Scalar converts to array only when a second note is added
- Same field name: No new metadata field required
Implementation Changes
-
Add utility functions to normalize noteId handling:
getNoteIdsFromMetadata() - returns array for both scalar and array input
addNoteIdToMetadata() - appends to array
removeNoteIdFromMetadata() - removes specific ID from array
-
Update useBlockComments() hook to build array-based mappings
-
Update onCreate() to append rather than overwrite
-
Update onDelete() to remove specific ID from array
-
In floating notes mode, the first added note is aligned with the block and subsequent notes are placed below that.
Benefits
Description
Currently, each block can have at most one top-level note attached to it. Subsequent notes are always forced to be a reply to the existing thread. This is because the block→note relationship is created by storing a single
noteIdin the block's metadata (block.attributes.metadata.noteId).This limitation causes issues in several scenarios:
Related Issues
Current Implementation
The current code in
packages/editor/src/components/collab-sidebar/hooks.js:blocksWithComments[clientId] = commentId(single value)noteIdinstead of a specific IDProposed Solution
Extend the existing
noteIdfield to support either a scalar (number) or an array (number[]):noteIdvalues work unchangedImplementation Changes
Add utility functions to normalize noteId handling:
getNoteIdsFromMetadata()- returns array for both scalar and array inputaddNoteIdToMetadata()- appends to arrayremoveNoteIdFromMetadata()- removes specific ID from arrayUpdate
useBlockComments()hook to build array-based mappingsUpdate
onCreate()to append rather than overwriteUpdate
onDelete()to remove specific ID from arrayIn floating notes mode, the first added note is aligned with the block and subsequent notes are placed below that.
Benefits