Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 2026-10-19 - [ProseMirror Performance]\n**Learning:** In ProseMirror, when using stable keys for `Decoration.widget` to enable DOM node recycling, ensure any properties that dynamically dictate the widget's appearance (such as opacity, connectionState, or color) are explicitly included in the key string. Do not use global generation counters. This ensures the node is correctly recreated or updated when those specific visual attributes change.\n**Action:** Always derive the `key` string from underlying data properties to enable DOM node recycling and avoid performance bottlenecks from layout thrashing.
15 changes: 4 additions & 11 deletions pkgs/id/web/src/cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const RECONNECT_CLEANUP_DELAY_MS = 3_000; // Wait 3s after Init before cleanup (
const HOVER_RESTORE_DELAY_MS = 1_000; // 1s delay before restoring after hover
const PENDING_REMOVAL_MS = 5_000; // Show fading cursor for 5s after disconnect

// Global counter to force widget recreation on every decoration call
let decorationGeneration = 0;

export interface CursorInfo {
clientID: string | number;
head: number;
Expand Down Expand Up @@ -457,10 +454,6 @@ function createCursorDecorations(
const now = Date.now();
const localHead = state.selection.head;

// Increment generation to force widget recreation
decorationGeneration++;
const gen = decorationGeneration;

// Normalize myClientID to number for comparison (handles string/number mismatch)
const myClientIDNum = myClientID !== null ? Number(myClientID) : null;

Expand Down Expand Up @@ -655,7 +648,7 @@ function createCursorDecorations(
decorations.push(
Decoration.widget(ownCursor.head, ownCursorLine, {
side: 1,
key: `cursor-own-${ownCursor.clientID}-g${gen}`,
key: `cursor-own-${ownCursor.clientID}-c${ownCursor.color}`,
}),
);
}
Expand Down Expand Up @@ -719,7 +712,7 @@ function createCursorDecorations(
decorations.push(
Decoration.widget(group.position, cursorLine, {
side: 1,
key: `cursor-cluster-${group.position}-${clusterKey}-g${gen}`,
key: `cursor-cluster-${group.position}-${clusterKey}-c${group.mostRecentColor}`,
}),
);
});
Expand All @@ -742,7 +735,7 @@ function createCursorDecorations(
decorations.push(
Decoration.widget(cursor.head, cursorWidget, {
side: 1,
key: `cursor-${cursor.clientID}-g${gen}`,
key: `cursor-${cursor.clientID}-o${cursor.opacity}-c${connectionState}`,
}),
);
}
Expand All @@ -765,7 +758,7 @@ function createCursorDecorations(
style: `background-color: ${cursor.color}${selectionOpacity};`,
},
{
key: `selection-${cursor.clientID}-g${gen}`,
key: `selection-${cursor.clientID}-o${cursor.opacity}`,
},
),
);
Expand Down
Loading