Skip to content

fix: hide TOC button and panel when document has no headings#113

Merged
tomasz-tomczyk merged 1 commit intomainfrom
fix-empty-toc-render
Apr 25, 2026
Merged

fix: hide TOC button and panel when document has no headings#113
tomasz-tomczyk merged 1 commit intomainfrom
fix-empty-toc-render

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • TOC toggle button and panel previously rendered (empty) for documents without headings on wide viewports because the localStorage open-state restoration ran unconditionally.
  • buildToc now adds crit-toc-hidden to the panel when the heading list is empty, and the mount-time restoration only runs when there are items.

Test plan

  • New e2e/toc.spec.ts covers:
    • Toggle visible + 2 entries when doc has headings
    • Toggle hidden + panel hidden when doc has no headings
    • Panel stays hidden when no headings even with localStorage["crit-toc"] = "open" pre-seeded
  • See also: tomasz-tomczyk/crit#TBD (sibling fix in crit local for parity)

🤖 Generated with Claude Code

The table-of-contents toggle button was correctly hidden when a document
had no headings, but the localStorage open-state restoration unconditionally
removed the `crit-toc-hidden` class on wide viewports — leaving an empty
TOC panel visible. Now buildToc adds the hidden class on the panel when
items are empty, and the mount-time restoration only runs when items exist.

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

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@31bc49b). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #113   +/-   ##
=======================================
  Coverage        ?   77.35%           
=======================================
  Files           ?       50           
  Lines           ?     1356           
  Branches        ?        0           
=======================================
  Hits            ?     1049           
  Misses          ?      307           
  Partials        ?        0           
Flag Coverage Δ
unit 77.35% <ø> (?)

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 55d6ea8 into main Apr 25, 2026
2 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix-empty-toc-render branch April 25, 2026 10:58
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.

2 participants