Skip to content

⚡ Bolt: Optimize cursor decoration DOM recycling - #379

Merged
dezren39 merged 4 commits into
mainfrom
bolt-cursor-dom-recycling-15044504201595192371
Oct 24, 2026
Merged

dezren39 merged 4 commits into
mainfrom
bolt-cursor-dom-recycling-15044504201595192371

Conversation

@dezren39

@dezren39 dezren39 commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

💡 What: Refactored cursor decorations in pkgs/id/web/src/cursors.ts to utilize ProseMirror's native DOM recycling instead of brute-forcing widget recreations with a global generation counter. Changed Decoration.widget to use factory functions (() => HTMLElement) and computed stable keys based on dynamic data like opacity and connectionState.
🎯 Why: Generating unique keys for widgets on every editor update bypasses ProseMirror's optimization to recycle DOM elements, triggering significant layout thrashing and garbage collection when cursors move or fade.
📊 Impact: Prevents costly O(N) widget recreation on every local/remote editor state change. Cursors are now properly recycled.
🔬 Measurement: Verify by inspecting the DOM during remote cursor updates — the <span> elements will now update and move gracefully rather than being completely destroyed and re-attached to the tree on every transaction.


PR created automatically by Jules for task 15044504201595192371 started by @dezren39


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

- Replaced global `decorationGeneration` with stable widget keys
- Switched to using factory functions `() => HTMLElement` for `Decoration.widget`
- Integrated dynamic states (`opacity`, `color`, `connectionState`) into widget keys to ensure ProseMirror correctly triggers updates instead of constant DOM recreation

This optimization reduces significant garbage collection overhead and layout thrashing.

Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

google-labs-jules Bot and others added 3 commits October 20, 2026 01:39
Formatted the bolt.md file with Prettier to resolve the treefmt check failure in CI.

Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>
Resolved formatting errors caught by the biome-check CI.

Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant