From 9801e5e840b602e326f9eb977cebfece6a8709f1 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 21 Oct 2026 12:05:03 +0200 Subject: [PATCH 1/3] 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 --- .../docusaurus-theme-common/src/internal.ts | 6 +-- .../__snapshots__/tocUtils.test.ts.snap | 40 ------------------- .../src/utils/__tests__/tocUtils.test.ts | 10 +---- .../src/utils/tocUtils.ts | 10 +---- 4 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 packages/docusaurus-theme-common/src/utils/__tests__/__snapshots__/tocUtils.test.ts.snap diff --git a/packages/docusaurus-theme-common/src/internal.ts b/packages/docusaurus-theme-common/src/internal.ts index fa8979347891..8d689b7d942f 100644 --- a/packages/docusaurus-theme-common/src/internal.ts +++ b/packages/docusaurus-theme-common/src/internal.ts @@ -63,11 +63,7 @@ export { useQueryStringValue, } from './utils/historyUtils'; -export { - useFilteredAndTreeifiedTOC, - useTreeifiedTOC, - type TOCTreeNode, -} from './utils/tocUtils'; +export {useFilteredAndTreeifiedTOC, type TOCTreeNode} from './utils/tocUtils'; export { ScrollControllerProvider, diff --git a/packages/docusaurus-theme-common/src/utils/__tests__/__snapshots__/tocUtils.test.ts.snap b/packages/docusaurus-theme-common/src/utils/__tests__/__snapshots__/tocUtils.test.ts.snap deleted file mode 100644 index 786ba4892ad6..000000000000 --- a/packages/docusaurus-theme-common/src/utils/__tests__/__snapshots__/tocUtils.test.ts.snap +++ /dev/null @@ -1,40 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`useTreeifiedTOC > treeifies TOC without filtering 1`] = ` -[ - { - "children": [ - { - "children": [ - { - "children": [ - { - "children": [ - { - "children": [], - "id": "foxtrot", - "level": 6, - "value": "Foxtrot", - }, - ], - "id": "echo", - "level": 5, - "value": "Echo", - }, - ], - "id": "delta", - "level": 4, - "value": "Delta", - }, - ], - "id": "charlie", - "level": 3, - "value": "Charlie", - }, - ], - "id": "bravo", - "level": 2, - "value": "Bravo", - }, -] -`; diff --git a/packages/docusaurus-theme-common/src/utils/__tests__/tocUtils.test.ts b/packages/docusaurus-theme-common/src/utils/__tests__/tocUtils.test.ts index 11bc5f332277..e7217c6d6ac5 100644 --- a/packages/docusaurus-theme-common/src/utils/__tests__/tocUtils.test.ts +++ b/packages/docusaurus-theme-common/src/utils/__tests__/tocUtils.test.ts @@ -7,7 +7,7 @@ // @vitest-environment jsdom import {describe, expect, it} from 'vitest'; import {renderHook} from '@testing-library/react'; -import {useFilteredAndTreeifiedTOC, useTreeifiedTOC} from '../tocUtils'; +import {useFilteredAndTreeifiedTOC} from '../tocUtils'; import type {TOCItem} from '@docusaurus/mdx-loader'; const mockTOC: TOCItem[] = [ @@ -38,14 +38,6 @@ const mockTOC: TOCItem[] = [ }, ]; -describe('useTreeifiedTOC', () => { - it('treeifies TOC without filtering', () => { - expect( - renderHook(() => useTreeifiedTOC(mockTOC)).result.current, - ).toMatchSnapshot(); - }); -}); - describe('useFilteredAndTreeifiedTOC', () => { it('filters a toc with all heading levels', () => { expect( diff --git a/packages/docusaurus-theme-common/src/utils/tocUtils.ts b/packages/docusaurus-theme-common/src/utils/tocUtils.ts index 64be4cb51191..e23b25a805a3 100644 --- a/packages/docusaurus-theme-common/src/utils/tocUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/tocUtils.ts @@ -52,14 +52,6 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] { return rootNodes; } -/** - * Takes a flat TOC list (from the MDX loader) and treeifies it into what the - * TOC components expect. Memoized for performance. - */ -export function useTreeifiedTOC(toc: TOCItem[]): readonly TOCTreeNode[] { - return useMemo(() => treeifyTOC(toc), [toc]); -} - function filterTOC({ toc, minHeadingLevel, @@ -96,7 +88,7 @@ function filterTOC({ * TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`. * Memoized for performance. * - * **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`, + * **Important**: this is not the same as `treeifyTOC(toc.filter(...))`, * because we have to filter the TOC after it has been treeified. This is mostly * to ensure that weird TOC structures preserve their semantics. For example, an * h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with From 7e401a6f64dc3444f29296908cdaafece6717ca6 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 23 Oct 2026 13:21:50 +0200 Subject: [PATCH 2/3] 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 --- packages/docusaurus-theme-common/src/internal.ts | 15 ++------------- .../src/utils/scrollUtils.tsx | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/docusaurus-theme-common/src/internal.ts b/packages/docusaurus-theme-common/src/internal.ts index 8d689b7d942f..9786c9d65932 100644 --- a/packages/docusaurus-theme-common/src/internal.ts +++ b/packages/docusaurus-theme-common/src/internal.ts @@ -48,29 +48,18 @@ export { export {DEFAULT_SEARCH_TAG} from './utils/searchUtils'; -export { - TitleFormatterProvider, - useTitleFormatter, -} from './utils/titleFormatterUtils'; - -export {useLocationChange} from './utils/useLocationChange'; +export {TitleFormatterProvider} from './utils/titleFormatterUtils'; export {useLocalPathname} from './utils/useLocalPathname'; -export { - useHistoryPopHandler, - useHistorySelector, - useQueryStringValue, -} from './utils/historyUtils'; +export {useQueryStringValue} from './utils/historyUtils'; export {useFilteredAndTreeifiedTOC, type TOCTreeNode} from './utils/tocUtils'; export { ScrollControllerProvider, - useScrollController, useScrollPosition, useScrollPositionBlocker, - useSmoothScrollTo, } from './utils/scrollUtils'; export {useHomePageRoute, isSamePath} from './utils/routesUtils'; diff --git a/packages/docusaurus-theme-common/src/utils/scrollUtils.tsx b/packages/docusaurus-theme-common/src/utils/scrollUtils.tsx index 44a05d6221e8..c1a5fdd1eb76 100644 --- a/packages/docusaurus-theme-common/src/utils/scrollUtils.tsx +++ b/packages/docusaurus-theme-common/src/utils/scrollUtils.tsx @@ -64,7 +64,7 @@ export function ScrollControllerProvider({ * This API permits to temporarily disable/ignore scroll events. Motivated by * https://github.com/facebook/docusaurus/pull/5618 */ -export function useScrollController(): ScrollController { +function useScrollController(): ScrollController { const context = useContext(ScrollMonitorContext); if (context == null) { throw new ReactContextError('ScrollControllerProvider'); From 90bfad77d7d0b7bfaefd4769b50841d5c91aa7db Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 23 Oct 2026 18:09:02 +0200 Subject: [PATCH 3/3] 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 --- packages/docusaurus-theme-common/src/internal.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-common/src/internal.ts b/packages/docusaurus-theme-common/src/internal.ts index 9786c9d65932..89897f95a6b2 100644 --- a/packages/docusaurus-theme-common/src/internal.ts +++ b/packages/docusaurus-theme-common/src/internal.ts @@ -48,7 +48,10 @@ export { export {DEFAULT_SEARCH_TAG} from './utils/searchUtils'; -export {TitleFormatterProvider} from './utils/titleFormatterUtils'; +export { + TitleFormatterProvider, + useTitleFormatter, +} from './utils/titleFormatterUtils'; export {useLocalPathname} from './utils/useLocalPathname';