Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(md): potentially fix md comment clone bug (#2685)

Seamuse7b439399135
diff --git a/js/app/packages/block-md/component/MarkdownCollabProvider.tsx b/js/app/packages/block-md/component/MarkdownCollabProvider.tsx
index 1ea23ca1ce..e5b8919549 100644
--- a/js/app/packages/block-md/component/MarkdownCollabProvider.tsx
+++ b/js/app/packages/block-md/component/MarkdownCollabProvider.tsx
@@ -40,6 +40,7 @@ import {
$updateAllNodeIds,
COLLABORATION_TAG,
CustomCodeNode,
+ LOCAL_STATUS_TAG,
type NodeIdMappings,
SKIP_DOM_SELECTION_TAG,
SKIP_SCROLL_INTO_VIEW_TAG,
@@ -360,9 +361,13 @@ export function MarkdownCollabProvider(props: MarkdownCollabProviderProps) {
}
// State updates tagged with 'FROM_LORO' are from the syncToLexical function
// and should not be synced to the loroManager. This would cause an infinite loop.
+ // LOCAL_STATUS_TAG updates carry only per-peer ownership state, which is
+ // resolved independently on each client — producers of this tag must not
+ // mutate node content in the same update, or those changes will be dropped here.
if (
tags.has(FROM_LORO_TAG) ||
tags.has(COLLABORATION_TAG) ||
+ tags.has(LOCAL_STATUS_TAG) ||
tags.has(CODE_HIGHLIGHT_IDS_TAG)
) {
return false;
diff --git a/js/app/packages/block-md/definition.ts b/js/app/packages/block-md/definition.ts
index 2b3a73af36..25fc0a690d 100644
--- a/js/app/packages/block-md/definition.ts
+++ b/js/app/packages/block-md/definition.ts
@@ -27,6 +27,9 @@ const nodeSchema = schema.LoroMap({
text: schema.LoroText({
required: false,
}),
+ ids: schema.LoroList(schema.String(), (idStr) => idStr, {
+ required: false,
+ }),
children: schema.LoroMovableList(
{} as SchemaType,
(item) => {
diff --git a/js/app/packages/core/component/LexicalMarkdown/collaboration/reconcile.ts b/js/app/packages/core/component/LexicalMarkdown/collaboration/reconcile.ts
index 69d2390811..82d5b14f35 100644
--- a/js/app/packages/core/component/LexicalMarkdown/collaboration/reconcile.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/collaboration/reconcile.ts
@@ -23,9 +23,6 @@ type NodeWithChildren = {
} & SerializedLexicalNode;
type NodeWithCustomId = { $: { id: string } } & SerializedLexicalNode;
-type NodeWithPeerId = {
- $: { peerId: string; local: boolean };
-} & SerializedLexicalNode;
// Improved type guards with clearer naming
function hasChildren(node: SerializedLexicalNode): node is NodeWithChildren {
@@ -36,12 +33,6 @@ function hasCustomId(node: SerializedLexicalNode): node is NodeWithCustomId {
return '$' in node && 'id' in node.$!;
}
-function _hasPeerId(
- node: SerializedLexicalNode | Partial<SerializedLexicalNode>
-): node is NodeWithPeerId {
- return '$' in node && 'peerId' in node.$!;
-}
-
function getNodeId(node: SerializedLexicalNode): string | undefined {
if (hasCustomId(node)) {
return node.$.id;
diff --git a/js/app/packages/lexical-core/plugins/peerIdPlugin.ts b/js/app/packages/lexical-core/plugins/peerIdPlugin.ts
index 126f5072d3..2e71a6cc4c 100644
--- a/js/app/packages/lexical-core/plugins/peerIdPlugin.ts
+++ b/js/app/packages/lexical-core/plugins/peerIdPlugin.ts
@@ -21,6 +21,9 @@ import { $isSerializedNode } from '../utils';
/**
* An update tag that signifies this update only included updates to the local status of nodes.
+ * Contract: updates carrying this tag MUST NOT mutate node content — collab providers skip
+ * syncing them entirely, so any content change would be silently dropped on other peers.
+ * Local ownership is per-peer by design and resolved independently on each client.
*/
export const LOCAL_STATUS_TAG = 'local-status';
@@ -154,18 +157,23 @@ function registerPeerIdPlugin(editor: LexicalEditor, props: PeerIdProps) {
if (mutation === 'created') createdNodes.push(nodeKey);
}
if (createdNodes.length > 0) {
- editor.update(() => {
- $addUpdateTag(LOCAL_STATUS_TAG);
- for (const key of createdNodes) {
- const node = $getNodeByKey(key);
- if (!node) continue;
- const nodePeerId = $getPeerId(node);
- const nodeLocalState = $getLocal(node);
- if (nodePeerId !== null && nodeLocalState === null) {
- $setLocal(node, nodePeerId === props.peerId());
+ editor.update(
+ () => {
+ $addUpdateTag(LOCAL_STATUS_TAG);
+ for (const key of createdNodes) {
+ const node = $getNodeByKey(key);
+ if (!node) continue;
+ const nodePeerId = $getPeerId(node);
+ const nodeLocalState = $getLocal(node);
+ if (nodePeerId !== null && nodeLocalState === null) {
+ $setLocal(node, nodePeerId === props.peerId());
+ }
}
- }
- });
+ },
+ // discrete: flush sync in the mutation listener so local resolves
+ // before downstream listeners read
+ { discrete: true }
+ );
}
};
};