From 59decd10f6f8f5f68793b99b7fc3c6e00ef94ca8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 01:51:57 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20ProseMirror=20de?= =?UTF-8?q?coration=20recycling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes a global \`decorationGeneration\` counter that was forcing ProseMirror to recreate cursor and selection DOM nodes on every single transaction. Instead, widget keys are now derived from their underlying dynamic data properties (opacity, color, connection state), allowing ProseMirror to efficiently recycle DOM nodes and avoid layout thrashing. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> --- .jules/bolt.md | 1 + pkgs/id/web/src/cursors.ts | 15 ++++----------- 2 files changed, 5 insertions(+), 11 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000000..b420d0fe7d --- /dev/null +++ b/.jules/bolt.md @@ -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. diff --git a/pkgs/id/web/src/cursors.ts b/pkgs/id/web/src/cursors.ts index b127290321..333769427b 100644 --- a/pkgs/id/web/src/cursors.ts +++ b/pkgs/id/web/src/cursors.ts @@ -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; @@ -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; @@ -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}`, }), ); } @@ -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}`, }), ); }); @@ -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}`, }), ); } @@ -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}`, }, ), );