Skip to content

refactor: make MDX export a flat TOC list instead of tree - #6729

Merged
slorber merged 3 commits into
mainfrom
jc/refactor-toc
Feb 23, 2022
Merged

slorber merged 3 commits into
mainfrom
jc/refactor-toc

Conversation

@Josh-Cena

@Josh-Cena Josh-Cena commented Feb 21, 2022 •

Copy link
Copy Markdown
Collaborator

Breaking change

  • The props received by TOCItems have changed. You may need to re-swizzle TOCItems. Good news is, TOC, TOCCollapsible, etc. don't need to be changed.
  • The documented behavior of splicing TOC headings through toc={[toc[2], toc[4]]} has been removed. If you previously used TOCInline but treated toc as an opaque data structure (only passing it as toc={toc}, you are safe; but if you relied on its tree structure properties, you may need to implement your own helper function to select all the wanted headings.

@slorber Do you think we should provide this helper function ourselves? Something like useTOCNodes([2, 4]). We may even allow a prop callback: filterTOC={(tocTree) => [toc[2], toc[4]]} which gets called after the TOC has been treeified. It would not be hard to build, just unsure of the value.

Motivation

This is a necessary step to work on #3915. See also #6201.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Made more tests

@Josh-Cena Josh-Cena added the pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. label Feb 21, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Feb 21, 2022
@netlify

netlify Bot commented Feb 21, 2022 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Feb 21, 2022 •

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 49
🟢 Accessibility 100
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 92

Lighthouse ran on https://deploy-preview-6729--docusaurus-2.netlify.app/

@github-actions

github-actions Bot commented Feb 21, 2022 •

Copy link
Copy Markdown

Size Change: +478 B (0%)

Total Size: 782 kB

Filename Size Change
website/build/assets/js/main.********.js 590 kB +478 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 48 kB
website/build/assets/css/styles.********.css 106 kB
website/build/index.html 37.6 kB

compressed-size-action

@Josh-Cena Josh-Cena added the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Feb 22, 2022
@slorber

slorber commented Feb 23, 2022

Copy link
Copy Markdown
Collaborator

Thanks, LGTM 👍

Couldn't see any issue even on weird page like this one:

https://deploy-preview-6729--docusaurus-2.netlify.app/tests/docs/toc/toc-test-bad/
https://docusaurus.io/tests/docs/toc/toc-test-bad/


Let's wait for users to complain before implementing anything extra that maybe nobody needs

@slorber
slorber merged commit c3370be into main Feb 23, 2022
@slorber
slorber deleted the jc/refactor-toc branch February 23, 2022 14:12
@Josh-Cena Josh-Cena removed the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Feb 23, 2022
ISSOtm added a commit to gbdev/rgbds-www that referenced this pull request Apr 19, 2024
Until Docusaurus 2.0.0-beta16, the ToC was a tree structure;
since meta/docusaurus#6729, it is flat instead.
The mismatch caused level 3 headings not to appear in the ToC.
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
slorber added a commit that referenced this pull request Oct 23, 2026
…12764)

* refactor(theme-common): remove unused internal useTreeifiedTOC hook (AI-assisted)

Added with the flat TOC refactor (#6729), but no theme ever used it: themes
use useFilteredAndTreeifiedTOC. Only its own test called it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(theme-common): remove unused hook re-exports from /internal (AI-assisted)

No package or website code imports useTitleFormatter, useLocationChange,
useHistoryPopHandler, useScrollController, useSmoothScrollTo or
useHistorySelector from @docusaurus/theme-common/internal. The hooks stay:
theme-common uses them internally, and useHistorySelector stays public.

useScrollController is now only used in scrollUtils.tsx, so it's no longer
exported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(theme-common): keep exposing useTitleFormatter in /internal (AI-assisted)

Some users likely rely on it to format page titles: it's the hook to use
alongside TitleFormatterProvider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants