Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
docs: build the reference nav index from the tree the layout already awaited
getNavIndex() awaited buildReferenceTree() on its own while Layout had already awaited the same tree for DocsLayout, so the first render built and filtered the reference tree twice. The memo it protected was a module-level singleton with no key, which is what prompted removing the parameter in the first place. Dropping the memo resolves both: the index is one traversal over ~64 nodes built from the tree already in hand, matching how the docs and examples layouts work. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Kshitij Jhunjhunwala committed
Aug 17, 2026 at 12:23 UTC
68c6c0a889b0f715a73042b91b8df92687b4c2c9
2 files changed
+4
-22
docs/app/(home)/reference/(v31)/layout.tsx
+2
-11
@@ -2,7 +2,7 @@ import { getReferenceSource } from '@/lib/source';
2
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
3
import type { ReactNode } from 'react';
4
import { prepareTree } from '@/lib/filter-api-version';
5
-import { buildSidebarNavIndex, type SidebarNavIndex } from '@/lib/sidebar-nav-index';
5
+import { buildSidebarNavIndex } from '@/lib/sidebar-nav-index';
6
import { SidebarAnalytics } from '@/components/sidebar-analytics';
7
8
async function buildReferenceTree() {
@@ -25,15 +25,6 @@ async function buildReferenceTree() {
25
};
26
}
27
28
-// The tree is only reachable after an await, so the index is memoized here
29
-// rather than hoisted to module scope like the docs and examples sidebars.
30
-let navIndex: SidebarNavIndex | undefined;
31
-
32
-async function getNavIndex(): Promise<SidebarNavIndex> {
33
- navIndex ??= buildSidebarNavIndex(await buildReferenceTree());
34
- return navIndex;
35
-}
36
-
28
export default async function Layout({ children }: { children: ReactNode }) {
29
const pageTree = await buildReferenceTree();
30
@@ -45,7 +36,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
36
sidebar={{ collapsible: false, footer: null, tabs: false }}
37
themeSwitch={{ enabled: false }}
38
>
48
- <SidebarAnalytics index={await getNavIndex()} />
39
+ <SidebarAnalytics index={buildSidebarNavIndex(pageTree)} />
40
{children}
41
</DocsLayout>
42
);
docs/app/(home)/reference/v3/layout.tsx
+2
-11
@@ -2,7 +2,7 @@ import { getReferenceSource } from '@/lib/source';
2
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
3
import type { ReactNode } from 'react';
4
import { prepareTree } from '@/lib/filter-api-version';
5
-import { buildSidebarNavIndex, type SidebarNavIndex } from '@/lib/sidebar-nav-index';
5
+import { buildSidebarNavIndex } from '@/lib/sidebar-nav-index';
6
import { SidebarAnalytics } from '@/components/sidebar-analytics';
7
8
async function buildReferenceTree() {
@@ -10,15 +10,6 @@ async function buildReferenceTree() {
10
return prepareTree(source.pageTree, '3.0');
11
}
12
13
-// The tree is only reachable after an await, so the index is memoized here
14
-// rather than hoisted to module scope like the docs and examples sidebars.
15
-let navIndex: SidebarNavIndex | undefined;
16
-
17
-async function getNavIndex(): Promise<SidebarNavIndex> {
18
- navIndex ??= buildSidebarNavIndex(await buildReferenceTree());
19
- return navIndex;
20
-}
21
-
13
export default async function Layout({ children }: { children: ReactNode }) {
14
const tree = await buildReferenceTree();
15
@@ -30,7 +21,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
21
sidebar={{ collapsible: false, footer: null, tabs: false }}
22
themeSwitch={{ enabled: false }}
23
>
33
- <SidebarAnalytics index={await getNavIndex()} />
24
+ <SidebarAnalytics index={buildSidebarNavIndex(tree)} />
25
{children}
26
</DocsLayout>
27
);