Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Fix a bug in crdt array sync

Hakan Shehu307b191b75ef
diff --git a/packages/core/src/registry/message.ts b/packages/core/src/registry/message.ts
index 77fe7b0d..c1935760 100644
--- a/packages/core/src/registry/message.ts
+++ b/packages/core/src/registry/message.ts
@@ -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>;
diff --git a/packages/crdt/src/index.ts b/packages/crdt/src/index.ts
index 0902e37f..cf870e3c 100644
--- a/packages/crdt/src/index.ts
+++ b/packages/crdt/src/index.ts
@@ -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);
}
};