Skip to content

perf: Resolve notebook outline headings in one pass - #12238

Merged
kirangadhave merged 3 commits into
mainfrom
kg/outline-heading-targets
Dec 3, 2026
Merged

kirangadhave merged 3 commits into
mainfrom
kg/outline-heading-targets

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

📝 Summary

Resolve notebook outline headings in one page query per refresh. Clicks, keyboard activation, and active-heading tracking use the same element, including for duplicate IDs and repeated headings without IDs. Rerunning unchanged markdown preserves the targets. If a rerun replaces a heading element, navigation and tracking follow its replacement.

All 150 focused tests passed, along with frontend type checking. Mounted tests cover zero heading queries on a timestamp-only rerun and one pass after an identical DOM replacement.

In the 500-cell production benchmark on the #12166 merge baseline, the outline changes made Run All faster in 9 of 12 alternating pairs. The median paired gain was 139 ms (3.1%). The 96.1% interval ranged from 33 ms slower to 259 ms faster, so the end-to-end speedup remains unconfirmed.

Addresses the outline work in MO-8797.

Searching the page for each outline entry made refreshes expensive in
large notebooks. Share resolved elements across click navigation,
keyboard activation, and active tracking so each interaction targets
the same occurrence, including for repeated headings without IDs.
A timestamp-only output update used to rebuild the outline and search
for headings again. Preserve outline values across those updates and
refresh navigation targets when the rendered heading elements change,
so rerunning a cell can replace its DOM without leaving stale targets.
@kirangadhave
kirangadhave marked this pull request as ready for review December 2, 2026 18:00
@kirangadhave
kirangadhave requested a balanced review from Copilot December 2, 2026 18:02

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 outline hook duplicates document-wide heading scans across consumers and can target sidebar copies instead of notebook headings, breaking navigation and active-heading tracking.

2 open issues
What changed in this PR

This PR streamlines notebook outline resolution and keeps navigation and active-heading tracking aligned after output updates.

Changes:

  • Resolve heading targets in one DOM pass per refresh.
  • Preserve unchanged outline values and track replacement elements.
  • Expand tests for duplicate headings, keyboard navigation, and reruns.
File Description
frontend/​src/​plugins/​layout/​OutlinePlugin.tsx Use resolved outline entries.
frontend/​src/​core/​executions/​atoms.ts Avoid reparsing unchanged output.
frontend/​src/​core/​dom/​outline.ts Simplify heading identifiers and selectors.
frontend/​src/​core/​dom/​__tests__/​outline.test.ts Update parser expectations.
frontend/​src/​core/​cells/​outline.ts Replace locators with optional IDs.
frontend/​src/​core/​cells/​cells.ts Preserve equivalent notebook outlines.
frontend/​src/​core/​cells/​__tests__/​notebook-outline.test.ts Update expectations and cover missing DOMParser.
frontend/​src/​core/​cells/​__tests__/​layout.test.ts Update outline fixtures.
frontend/​src/​components/​editor/​chrome/​panels/​outline/​useActiveOutline.tsx Resolve, observe, and navigate shared targets.
frontend/​src/​components/​editor/​chrome/​panels/​outline/​floating-outline.tsx Render and activate resolved entries.
frontend/​src/​components/​editor/​chrome/​panels/​outline/​__tests__/​useActiveOutline.test.ts Adapt ID-less heading tests.
frontend/​src/​components/​editor/​chrome/​panels/​outline/​__tests__/​outline-keyboard.test.tsx Cover mounted navigation and target refreshes.
frontend/​src/​components/​editor/​chrome/​panels/​outline-panel.tsx Adopt the updated outline hook.

Review effort: Balanced

@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

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 0017c8d.

@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.18% 28682 / 41454
🔵 Statements 69.13% 29236 / 42288
🔵 Functions 64.37% 6871 / 10673
🔵 Branches 64.59% 16788 / 25991
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/__mocks__/intersection-observer.ts 92.3% 100% 85.71% 92.3% 15
frontend/src/components/editor/Output.tsx 69.76% 66.66% 46.66% 69.76% 109, 199-203, 217-252, 274-345, 426, 453, 469-490
frontend/src/components/editor/chrome/panels/outline-panel.tsx 80% 50% 100% 80% 15-20
frontend/src/components/editor/chrome/panels/outline/floating-outline.tsx 89.65% 91.17% 83.33% 89.65% 27, 30-31
frontend/src/components/editor/chrome/panels/outline/useActiveOutline.tsx 92.94% 81.52% 97.36% 92.66% 108, 159-165, 233, 283, 364-365, 371
frontend/src/core/cells/cells.ts 84.9% 84.93% 76.54% 88.23% 271-278, 307-328, 429, 438-442, 445, 517, 524, 539, 544, 549, 561, 568, 573, 576, 634-636, 677, 693-698, 716-720
frontend/src/core/cells/outline.ts 0% 0% 0% 0%
frontend/src/core/dom/outline.ts 91.07% 89.28% 100% 90.74% 47, 77, 84-85, 113
frontend/src/core/executions/atoms.ts 100% 98.5% 100% 100%
frontend/src/core/islands/components/output-wrapper.tsx 86.36% 81.81% 80% 86.36% 82, 123-128, 139
frontend/src/plugins/layout/OutlinePlugin.tsx 33.33% 0% 0% 33.33% 18-37, 49-54
Generated in workflow #26481 for commit 0017c8d by the Vitest Coverage Report Action

@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label Dec 2, 2026
Folding a cell could redirect its outline entry to a duplicate heading in another cell. Resolve targets inside their owning output and exclude rich labels rendered by the outline itself. Share one subscription across outline views so opening the panel does not repeat the page scan.
@kirangadhave kirangadhave changed the title Resolve notebook outline headings in one pass perf: Resolve notebook outline headings in one pass Dec 2, 2026
@kirangadhave
kirangadhave merged commit 352adf6 into main Dec 3, 2026
37 checks passed
@kirangadhave
kirangadhave deleted the kg/outline-heading-targets branch December 3, 2026 00:55
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.26.1-dev108

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