From d2d8d132ea7182ae76d070ba3b842dc2d8bbdc82 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 01:44:26 +0000 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9A=A1=20Bolt:=20improve=20ProseMirror?= =?UTF-8?q?=20collaborative=20cursor=20rendering=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Changed ProseMirror `Decoration.widget` construction in collaborative cursor plugin to use DOM factory functions (`() => HTMLElement`) and stable recycling keys based on dynamic properties (`opacity`, `connectionState`, `color`). Eliminated `decorationGeneration` logic which bypassed recycling. 🎯 Why: Instantiating DOM nodes directly during decoration mapping without recycling causes severe layout thrashing and continuous garbage collection when cursors move. 📊 Impact: Expected to dramatically reduce memory pressure and layout recalculation pauses when typing in collaboratively edited documents. 🔬 Measurement: Verify cursor updates now simply move existing DOM nodes rather than continuously creating/destroying nodes in browser DevTools. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> --- .jules/bolt.md | 3 + pkgs/id/web/src/cursors.ts | 133 +++++++++++++++++++------------------ 2 files changed, 71 insertions(+), 65 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000000..7b83bf0695 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-14 - ProseMirror DOM Node Recycling +**Learning:** ProseMirror's `Decoration.widget` requires using a factory function (`() => HTMLElement`) to construct the DOM node. Instantiating the node directly during the decoration generation loop bypasses ProseMirror's node recycling mechanism and causes severe layout thrashing/GC spikes, especially for dynamic decorations like cursors that update frequently. Furthermore, any visual attribute that dynamically changes the appearance of the widget (e.g. `opacity`, `connectionState`, `color`) must be explicitly embedded in the widget's `key` string. +**Action:** When implementing ProseMirror decorations, always use the factory function pattern `() => HTMLElement` for `Decoration.widget` construction and derive the `key` string from underlying data properties to enable DOM node recycling and avoid performance bottlenecks. diff --git a/pkgs/id/web/src/cursors.ts b/pkgs/id/web/src/cursors.ts index b127290321..3b7f108c80 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; @@ -647,16 +640,21 @@ function createCursorDecorations( // Create own cursor decoration if present in cluster if (clusterHasOwnCursor && ownCursor) { - const ownCursorLine = document.createElement("span"); - ownCursorLine.className = "collab-cursor collab-cursor-own"; - ownCursorLine.style.borderColor = ownCursor.color; - ownCursorLine.setAttribute("data-client-id", String(ownCursor.clientID)); - decorations.push( - Decoration.widget(ownCursor.head, ownCursorLine, { - side: 1, - key: `cursor-own-${ownCursor.clientID}-g${gen}`, - }), + Decoration.widget( + ownCursor.head, + () => { + const ownCursorLine = document.createElement("span"); + ownCursorLine.className = "collab-cursor collab-cursor-own"; + ownCursorLine.style.borderColor = ownCursor.color; + ownCursorLine.setAttribute("data-client-id", String(ownCursor.clientID)); + return ownCursorLine; + }, + { + side: 1, + key: `cursor-own-${ownCursor.clientID}-color-${ownCursor.color}`, + }, + ), ); } @@ -684,66 +682,71 @@ function createCursorDecorations( .sort() .join("-"); + // Generate a cluster hash based on opacities for the key so it recreates when opacities change + const clusterOpacityHash = groupsForBar + .flatMap((g) => g.cursors.map((c) => c.opacity.toFixed(2))) + .join("-"); + // Create cursor lines for each position group (no attached labels) groupsForBar.forEach((group) => { - const firstCursor = group.cursors[0]; - const allClientIDs = group.cursors.map((c) => c.clientID); - const cursorLine = createCursorLine(firstCursor, true, connectionState, allClientIDs); - cursorLine.style.borderColor = group.mostRecentColor; - - // For merged cursor lines with bars, use full opacity on the line - // (the bar segments handle their own individual opacities) - if (group === leftmostGroup) { - cursorLine.style.opacity = "1"; - cursorLine.style.setProperty("--base-opacity", "1"); - cursorLine.style.animation = "none"; // No strobe on bar container - } - - // Track the leftmost cursor line for bar attachment - if (group === leftmostGroup) { - leftmostCursorLine = cursorLine; - } + decorations.push( + Decoration.widget( + group.position, + () => { + const firstCursor = group.cursors[0]; + const allClientIDs = group.cursors.map((c) => c.clientID); + const cursorLine = createCursorLine(firstCursor, true, connectionState, allClientIDs); + cursorLine.style.borderColor = group.mostRecentColor; + + // For merged cursor lines with bars, use full opacity on the line + // (the bar segments handle their own individual opacities) + if (group === leftmostGroup) { + cursorLine.style.opacity = "1"; + cursorLine.style.setProperty("--base-opacity", "1"); + cursorLine.style.animation = "none"; // No strobe on bar container + + const mergedBar = createMergedBar(groupsForBar, handleMouseEnter, handleMouseLeave, connectionState); + cursorLine.appendChild(mergedBar); + } - // Register all cursors in this group for strobe tracking - if (viewState) { - group.cursors.forEach((cursor) => { - viewState.strobeInfos.set(cursor.clientID, { - element: cursorLine, - baseOpacity: cursor.opacity, - paused: false, - }); - }); - } + // Register all cursors in this group for strobe tracking + if (viewState) { + group.cursors.forEach((cursor) => { + viewState.strobeInfos.set(cursor.clientID, { + element: cursorLine, + baseOpacity: cursor.opacity, + paused: false, + }); + }); + } - // Use cluster-wide key + generation to force recreation on every update - decorations.push( - Decoration.widget(group.position, cursorLine, { - side: 1, - key: `cursor-cluster-${group.position}-${clusterKey}-g${gen}`, - }), + return cursorLine; + }, + { + side: 1, + // Include connectionState, color, and cluster opacities in the key + key: `cursor-cluster-${group.position}-${clusterKey}-conn-${connectionState}-color-${group.mostRecentColor}-op-${clusterOpacityHash}`, + } + ) ); }); - - // Create merged tooltip bar and attach to leftmost cursor line - // (appending to cursor line ensures proper positioning via position: relative) - const mergedBar = createMergedBar(groupsForBar, handleMouseEnter, handleMouseLeave, connectionState); - - if (leftmostCursorLine) { - (leftmostCursorLine as HTMLElement).appendChild(mergedBar); - } } else { // Single remote cursor, no overlap - simple standalone cursor const group = groupsForBar[0]; const cursor = group.cursors[0]; - const cursorWidget = viewState - ? createStandaloneCursor(cursor, connectionState, viewState, handleMouseEnter, handleMouseLeave) - : createCursorLine(cursor, false, connectionState); decorations.push( - Decoration.widget(cursor.head, cursorWidget, { - side: 1, - key: `cursor-${cursor.clientID}-g${gen}`, - }), + Decoration.widget( + cursor.head, + () => viewState + ? createStandaloneCursor(cursor, connectionState, viewState, handleMouseEnter, handleMouseLeave) + : createCursorLine(cursor, false, connectionState), + { + side: 1, + // Key based on dynamic properties dictating rendering + key: `cursor-${cursor.clientID}-conn-${connectionState}-op-${cursor.opacity.toFixed(2)}-color-${cursor.color}`, + } + ) ); } }); @@ -765,7 +768,7 @@ function createCursorDecorations( style: `background-color: ${cursor.color}${selectionOpacity};`, }, { - key: `selection-${cursor.clientID}-g${gen}`, + key: `selection-${cursor.clientID}-op-${cursor.opacity.toFixed(2)}-color-${cursor.color}`, }, ), ); From c3cbae84ecd73f458c4cea307413ff86573f296d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 01:50:46 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9A=A1=20Bolt:=20fix=20biome=20lint=20wa?= =?UTF-8?q?rnings=20in=20ProseMirror=20cursors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Fixed two biome lint warnings for an unused/unassigned `leftmostCursorLine` variable in `pkgs/id/web/src/cursors.ts` that were uncovered during CI. 🎯 Why: The CI `nix flake check` failed due to the `id-biome-check` job failing on formatting and unused variables which were introduced when refactoring DOM node generation to utilize factory functions in the previous commit. 📊 Impact: Expected to pass CI formatting and linting checks. 🔬 Measurement: Verify `bunx @biomejs/biome check src/cursors.ts` reports no errors or warnings locally. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> --- pkgs/id/web/src/cursors.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pkgs/id/web/src/cursors.ts b/pkgs/id/web/src/cursors.ts index 3b7f108c80..1672b1da59 100644 --- a/pkgs/id/web/src/cursors.ts +++ b/pkgs/id/web/src/cursors.ts @@ -673,7 +673,6 @@ function createCursorDecorations( // Find the leftmost group (we'll attach the bar to its cursor line) const leftmostGroup = groupsForBar.find((g) => g.position === leftmostPos); - let leftmostCursorLine: HTMLElement | null = null; // Create a cluster-wide key that includes ALL client IDs AND positions in the cluster // This ensures widgets are recreated when cluster membership OR positions change @@ -683,9 +682,7 @@ function createCursorDecorations( .join("-"); // Generate a cluster hash based on opacities for the key so it recreates when opacities change - const clusterOpacityHash = groupsForBar - .flatMap((g) => g.cursors.map((c) => c.opacity.toFixed(2))) - .join("-"); + const clusterOpacityHash = groupsForBar.flatMap((g) => g.cursors.map((c) => c.opacity.toFixed(2))).join("-"); // Create cursor lines for each position group (no attached labels) groupsForBar.forEach((group) => { @@ -726,8 +723,8 @@ function createCursorDecorations( side: 1, // Include connectionState, color, and cluster opacities in the key key: `cursor-cluster-${group.position}-${clusterKey}-conn-${connectionState}-color-${group.mostRecentColor}-op-${clusterOpacityHash}`, - } - ) + }, + ), ); }); } else { @@ -738,15 +735,16 @@ function createCursorDecorations( decorations.push( Decoration.widget( cursor.head, - () => viewState - ? createStandaloneCursor(cursor, connectionState, viewState, handleMouseEnter, handleMouseLeave) - : createCursorLine(cursor, false, connectionState), + () => + viewState + ? createStandaloneCursor(cursor, connectionState, viewState, handleMouseEnter, handleMouseLeave) + : createCursorLine(cursor, false, connectionState), { side: 1, // Key based on dynamic properties dictating rendering key: `cursor-${cursor.clientID}-conn-${connectionState}-op-${cursor.opacity.toFixed(2)}-color-${cursor.color}`, - } - ) + }, + ), ); } }); From 79392f8a0bf302a2693bd80da1701c94d7c2462b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 01:55:57 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9A=A1=20Bolt:=20fix=20biome=20lint=20wa?= =?UTF-8?q?rnings=20in=20ProseMirror=20cursors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Fixed two biome lint warnings for an unused/unassigned `leftmostCursorLine` variable in `pkgs/id/web/src/cursors.ts` that were uncovered during CI. 🎯 Why: The CI `nix flake check` failed due to the `id-biome-check` job failing on formatting and unused variables which were introduced when refactoring DOM node generation to utilize factory functions in the previous commit. 📊 Impact: Expected to pass CI formatting and linting checks. 🔬 Measurement: Verify `bunx @biomejs/biome check src/cursors.ts` reports no errors or warnings locally. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> From a11242740d0157ff9928f2fe88114325c7d055b4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 01:59:56 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9A=A1=20Bolt:=20fix=20treefmt=20formatt?= =?UTF-8?q?ing=20for=20.jules/bolt.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Fixed formatting in `.jules/bolt.md` using prettier. 🎯 Why: CI `treefmt check` job failed due to formatting issues in the markdown file generated during previous code changes. 📊 Impact: Expected to pass CI formatting checks. 🔬 Measurement: Verify tests run cleanly on CI. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> --- .jules/bolt.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.jules/bolt.md b/.jules/bolt.md index 7b83bf0695..2da87d4796 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,4 @@ ## 2024-05-14 - ProseMirror DOM Node Recycling + **Learning:** ProseMirror's `Decoration.widget` requires using a factory function (`() => HTMLElement`) to construct the DOM node. Instantiating the node directly during the decoration generation loop bypasses ProseMirror's node recycling mechanism and causes severe layout thrashing/GC spikes, especially for dynamic decorations like cursors that update frequently. Furthermore, any visual attribute that dynamically changes the appearance of the widget (e.g. `opacity`, `connectionState`, `color`) must be explicitly embedded in the widget's `key` string. **Action:** When implementing ProseMirror decorations, always use the factory function pattern `() => HTMLElement` for `Decoration.widget` construction and derive the `key` string from underlying data properties to enable DOM node recycling and avoid performance bottlenecks. From ae948db885a6b401d5e9addd61298f8d24c40388 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 02:09:54 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9A=A1=20Bolt:=20fix=20cargo=20fmt=20iss?= =?UTF-8?q?ue=20in=20pkgs/id/src/blob=5Fgate.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Fixed rust code formatting in `pkgs/id/src/blob_gate.rs` using `cargo fmt`. 🎯 Why: CI `cargo-fmt-check` failed. Even though this isn't in a file touched by this agent run, fixing it resolves the overall CI check suite failure. 📊 Impact: Expected to pass CI formatting checks. 🔬 Measurement: Verify `cargo fmt --check` succeeds. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com> --- pkgs/id/src/blob_gate.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkgs/id/src/blob_gate.rs b/pkgs/id/src/blob_gate.rs index d8d207fd60..e64b3bdd34 100644 --- a/pkgs/id/src/blob_gate.rs +++ b/pkgs/id/src/blob_gate.rs @@ -125,10 +125,7 @@ pub struct FoldedWorlds { impl FoldedWorlds { /// Pairs the folded worlds with a reference index. pub const fn new(worlds: Worlds, references: HashMap>) -> Self { - Self { - worlds, - references, - } + Self { worlds, references } } } From fcbd467ad1bd01fae6de94e8ce2781749567b9c8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 03:06:07 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=E2=9A=A1=20Bolt:=20fix=20cargo=20fmt=20iss?= =?UTF-8?q?ue=20in=20pkgs/id/src/blob=5Fgate.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Fixed rust code formatting in `pkgs/id/src/blob_gate.rs` using `cargo fmt`. 🎯 Why: CI `cargo-fmt-check` failed. Even though this isn't in a file touched by this agent run, fixing it resolves the overall CI check suite failure. 📊 Impact: Expected to pass CI formatting checks. 🔬 Measurement: Verify `cargo fmt --check` succeeds. Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>