mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Fix a bug in crdt array sync
This commit is contained in:
@@ -7,7 +7,7 @@ export const messageAttributesSchema = z.object({
|
||||
type: z.literal('message'),
|
||||
parentId: z.string().nullable(),
|
||||
content: z.record(z.string(), blockSchema),
|
||||
reactions: z.record(z.array(z.string())),
|
||||
reactions: z.record(z.string(), z.array(z.string())),
|
||||
});
|
||||
|
||||
export type MessageAttributes = z.infer<typeof messageAttributesSchema>;
|
||||
|
||||
@@ -143,20 +143,6 @@ const applyArrayChanges = (
|
||||
yArray.insert(i, [nestedMap]);
|
||||
}
|
||||
|
||||
applyRecordChanges(itemSchema, item, nestedMap);
|
||||
} else if (itemSchema instanceof z.ZodRecord) {
|
||||
if (yArray.length <= i) {
|
||||
const nestedMap = new Y.Map();
|
||||
yArray.insert(i, [nestedMap]);
|
||||
}
|
||||
|
||||
let nestedMap = yArray.get(i);
|
||||
if (!(nestedMap instanceof Y.Map)) {
|
||||
nestedMap = new Y.Map();
|
||||
yArray.delete(i, 1);
|
||||
yArray.insert(i, [nestedMap]);
|
||||
}
|
||||
|
||||
applyRecordChanges(itemSchema, item, nestedMap);
|
||||
} else if (itemSchema instanceof ZodText) {
|
||||
if (yArray.length <= i) {
|
||||
@@ -186,7 +172,7 @@ const applyArrayChanges = (
|
||||
}
|
||||
|
||||
if (yArray.length > length) {
|
||||
yArray.delete(yArray.length, yArray.length - length);
|
||||
yArray.delete(yArray.length - 1, yArray.length - length);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user