Skip to content

fix: render TOC after content arrives in init handler#170

Merged
tomasz-tomczyk merged 1 commit intomainfrom
fix-toc-render
May 4, 2026
Merged

fix: render TOC after content arrives in init handler#170
tomasz-tomczyk merged 1 commit intomainfrom
fix-toc-render

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

@tomasz-tomczyk tomasz-tomczyk commented May 4, 2026

Summary

The renderer's mount node has no data-content attribute, so mounted() ran with an empty rawContent. extractTocItems returned [], buildToc hid the panel, the wide-viewport auto-open block was skipped, and the scroll-spy closure captured an empty list. The init handler later rebuilt the visible list but never re-ran auto-open or refreshed scroll-spy items.

Reported on https://crit.md/r/BOldGf1BCDSYla_hpRfbv — wide screen, single 46KB markdown file with 8+ headings, TOC stayed collapsed.

  • Expose ctx.rebuildToc + ctx.tocItems so init can repopulate items, re-run the auto-open heuristic, and feed the scroll-spy.
  • Hide toggle when fewer than two headings — a one-entry TOC has nothing to navigate.

Test plan

  • 5 Playwright tests in e2e/toc.spec.ts (auto-open on wide viewport, scroll-spy active highlight, single-heading hide, no-headings hide, localStorage override)
  • mix precommit: 555 tests, 0 failures

See also: tomasz-tomczyk/crit#443 (parity change)

🤖 Generated with Claude Code

The mount node has no data-content attribute, so the renderer's mounted()
hook ran with an empty rawContent — extractTocItems returned [], buildToc
hid the panel, the wide-viewport auto-open block was skipped, and the
scroll-spy closure captured an empty list.

The init handler later rebuilt the visible list but never re-ran auto-open
or refreshed the scroll-spy items. Result: on a wide screen the TOC stayed
collapsed and active-heading highlighting never updated.

Expose ctx.rebuildToc + ctx.tocItems so init can repopulate items, re-run
the auto-open heuristic, and feed the scroll-spy. Also hide the toggle
when there's only one heading — a single-entry TOC has nothing to navigate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.70%. Comparing base (0c5a899) to head (40edece).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #170   +/-   ##
=======================================
  Coverage   78.70%   78.70%           
=======================================
  Files          55       55           
  Lines        1700     1700           
=======================================
  Hits         1338     1338           
  Misses        362      362           
Flag Coverage Δ
unit 78.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tomasz-tomczyk tomasz-tomczyk merged commit 6d7f4ab into main May 4, 2026
4 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix-toc-render branch May 4, 2026 09:25
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