Repository navigation
perf: Resolve notebook outline headings in one pass - #12238
Merged
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
Contributor
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
commented
Dec 2, 2026
kirangadhave
commented
Dec 2, 2026
kirangadhave
commented
Dec 2, 2026
kirangadhave
commented
Dec 2, 2026
mscolnick
approved these changes
Dec 2, 2026
Contributor
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.26.1-dev108 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📝 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.