Skip to content

perf: mount the cell delete button on hover or focus - #12247

Merged
kirangadhave merged 2 commits into
mainfrom
kg/lazy-cell-delete
Dec 3, 2026
Merged

kirangadhave merged 2 commits into
mainfrom
kg/lazy-cell-delete

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

📝 Summary

Each editable cell mounted a Delete button that CSS hid until hover. A 500-cell notebook carried 500 idle buttons and 3,500 elements for them. This change covers the Delete task in MO-8795.

Mount the Delete button only while the cell is hovered or holds focus on fine-pointer devices. Touch devices keep the button mounted, and the gate follows pointer capability changes through one shared media query listener. The shoulder wrapper always renders, so layout and the hit area do not change. The canDelete, code-visibility, running, queued and connection guards are unchanged, and so are delete and undo.

A focused Delete button now stays visible, shows its focus ring, and activates with Enter or Space. Before, the button lost focus when the pointer was outside the cell, and an unmodified Enter reached cell navigation. Focus on any other element in the cell does not show the button.

Evidence

Production builds in headless Chromium, 500 Python cells, no outputs. Median of 7 runs per build in alternating order.

Idle notebook main this change
Delete buttons mounted 500 0
Elements in document 40,723 36,723
JS event listeners 8,073 7,596
JS heap after GC 210.9 MiB 200.5 MiB
  • The heap ranges do not overlap (210.0 to 216.4 MiB against 199.3 to 201.5 MiB). Load time does not change: the ranges overlap.
  • Over 30 hovers, the button appeared within one frame on both builds (p50 16 ms, p95 17 ms), with zero long tasks.
  • In Chromium, hover, click, undo, touch tap, setup-cell hover, and Enter and Space on a focused button each passed. The cell rectangle was identical before and after hover.
  • 1,175 frontend tests passed across 111 files in src/components/editor. The frontend type check, changed-file lint, and formatting checks passed.

Part of MO-8795

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes.

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 4d8fd20.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 69.27% 28714 / 41451
🔵 Statements 69.22% 29271 / 42286
🔵 Functions 64.6% 6910 / 10695
🔵 Branches 64.7% 16831 / 26010
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/components/editor/notebook-cell.tsx 55.88% 48.32% 40% 56.43% 113-118, 129-149, 187-196, 203-204, 283-289, 337, 441, 490-498, 516-523, 544-547, 598-602, 611, 614, 739-752, 820, 824, 958-1183
frontend/src/components/editor/cell/CellDeleteShoulder.tsx 100% 100% 100% 100%
frontend/src/components/editor/cell/DeleteButton.tsx 100% 100% 100% 100%
frontend/src/css/common.css 0% 0% 0% 0%
frontend/src/hooks/useFinePointer.ts 90% 100% 83.33% 100% 29
Generated in workflow #26504 for commit 4d8fd20 by the Vitest Coverage Report Action

@kirangadhave
kirangadhave requested a balanced review from Copilot December 2, 2026 21:19
@kirangadhave
kirangadhave marked this pull request as ready for review December 2, 2026 21:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests hide an invalid connection-state fixture behind a cast, and the pointer hook bypasses the required shared-subscription helper.

2 open issues
What changed in this PR

Reduces idle DOM overhead in marimo notebooks by mounting cell delete buttons only when needed, while preserving touch access and improving keyboard interaction.

Changes:

  • Mount delete controls on hover or cell focus, using a shared pointer-capability listener.
  • Preserve focused-button visibility and native Enter/Space activation.
  • Add tests for mounting, pointer changes, deletion guards, and keyboard events.
File Description
frontend/​src/​hooks/​useFinePointer.ts Tracks pointer capabilities through a shared listener.
frontend/​src/​css/​common.css Keeps delete controls visible during non-editor focus.
frontend/​src/​components/​editor/​notebook-cell.tsx Integrates conditional delete controls into editable and setup cells.
frontend/​src/​components/​editor/​cell/​DeleteButton.tsx Preserves focus styling and keyboard activation.
frontend/​src/​components/​editor/​cell/​CellDeleteShoulder.tsx Gates button mounting by hover, focus, and pointer capabilities.
frontend/​src/​components/​editor/​cell/​__tests__/​CellDeleteShoulder.test.tsx Tests mounting behavior and delete-button interactions.

Review effort: Balanced

Comment thread frontend/src/hooks/useFinePointer.ts Resolved
mscolnick
mscolnick previously approved these changes Dec 2, 2026
@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label Dec 3, 2026
@kirangadhave
kirangadhave enabled auto-merge (squash) December 3, 2026 01:05
Fine-pointer devices mount the button only while the cell is hovered or holds focus. Touch devices keep it mounted. A focused button stays visible and activates with Enter or Space.
Focus on an output control no longer shows the button. The pointer hook uses the shared subscription helper.
@kirangadhave
kirangadhave merged commit 68c7388 into main Dec 3, 2026
31 checks passed
@kirangadhave
kirangadhave deleted the kg/lazy-cell-delete branch December 3, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants