Fix a bug in crdt array sync

This commit is contained in:
Hakan Shehu
2024-11-09 19:25:20 +01:00
parent a4b2e5d533
commit 307b191b75
2 changed files with 2 additions and 16 deletions

View File

@@ -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>;

View File

@@ -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);
}
};