@devries-cameron20 / composio Mirror · read-only / commits / da72336dc
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 16:00 UTC

docs: assert sidebar position relatively, drop the unkeyed nav-index cache

The position assertions pinned absolute indices into the live content tree, so adding any page to meta.json failed a test named for traversal semantics with "expected 12, received 13". Assert the invariant instead — a folder occupies one sibling slot, and its children restart at 1 — which stays green when content moves and still fails if position starts threading through folders again. getNavIndex(tree) ignored its argument on every call after the first. The reference tree is only reachable after an await, so it stays memoized, but the signature no longer claims to vary with a parameter it never read. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Kshitij Jhunjhunwala committed Aug 17, 2026 at 11:26 UTC da72336dc275214e5f1911034aa2579938b33c6c
3 files changed +40 -31
docs/app/(home)/reference/(v31)/layout.tsx
+17 -13
@@ -4,18 +4,8 @@ import type { ReactNode } from 'react';
4 import { prepareTree } from '@/lib/filter-api-version';
5 import { buildSidebarNavIndex, type SidebarNavIndex } from '@/lib/sidebar-nav-index';
6 import { SidebarAnalytics } from '@/components/sidebar-analytics';
7 -import type { Root } from 'fumadocs-core/page-tree';
7
9 -// The reference tree is only reachable after an await, so it is memoized here
10 -// rather than hoisted to module scope like the docs and examples sidebars.
11 -let navIndex: SidebarNavIndex | undefined;
12 -
13 -function getNavIndex(tree: Root): SidebarNavIndex {
14 - navIndex ??= buildSidebarNavIndex(tree);
15 - return navIndex;
16 -}
17 -
18 -export default async function Layout({ children }: { children: ReactNode }) {
8 +async function buildReferenceTree() {
9 const source = await getReferenceSource();
10 const tree = prepareTree(source.pageTree, '3.1');
11 const changelogPage = { type: 'page' as const, name: 'Changelog', url: '/reference/changelog' };
@@ -24,7 +14,8 @@ export default async function Layout({ children }: { children: ReactNode }) {
14 child => child.type === 'page' && child.name === 'Overview'
15 );
16 const insertIdx = overviewIdx === -1 ? Math.min(1, tree.children.length) : overviewIdx + 1;
27 - const pageTree = {
17 +
18 + return {
19 ...tree,
20 children: [
21 ...tree.children.slice(0, insertIdx),
@@ -32,6 +23,19 @@ export default async function Layout({ children }: { children: ReactNode }) {
23 ...tree.children.slice(insertIdx),
24 ] as typeof tree.children,
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 +
37 +export default async function Layout({ children }: { children: ReactNode }) {
38 + const pageTree = await buildReferenceTree();
39
40 return (
41 <DocsLayout
@@ -41,7 +45,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
45 sidebar={{ collapsible: false, footer: null, tabs: false }}
46 themeSwitch={{ enabled: false }}
47 >
44 - <SidebarAnalytics index={getNavIndex(pageTree)} />
48 + <SidebarAnalytics index={await getNavIndex()} />
49 {children}
50 </DocsLayout>
51 );
docs/app/(home)/reference/v3/layout.tsx
+10 -7
@@ -4,20 +4,23 @@ import type { ReactNode } from 'react';
4 import { prepareTree } from '@/lib/filter-api-version';
5 import { buildSidebarNavIndex, type SidebarNavIndex } from '@/lib/sidebar-nav-index';
6 import { SidebarAnalytics } from '@/components/sidebar-analytics';
7 -import type { Root } from 'fumadocs-core/page-tree';
7
9 -// The reference tree is only reachable after an await, so it is memoized here
8 +async function buildReferenceTree() {
9 + const source = await getReferenceSource();
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
13 -function getNavIndex(tree: Root): SidebarNavIndex {
14 - navIndex ??= buildSidebarNavIndex(tree);
17 +async function getNavIndex(): Promise<SidebarNavIndex> {
18 + navIndex ??= buildSidebarNavIndex(await buildReferenceTree());
19 return navIndex;
20 }
21
22 export default async function Layout({ children }: { children: ReactNode }) {
19 - const source = await getReferenceSource();
20 - const tree = prepareTree(source.pageTree, '3.0');
23 + const tree = await buildReferenceTree();
24
25 return (
26 <DocsLayout
@@ -27,7 +30,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
30 sidebar={{ collapsible: false, footer: null, tabs: false }}
31 themeSwitch={{ enabled: false }}
32 >
30 - <SidebarAnalytics index={getNavIndex(tree)} />
33 + <SidebarAnalytics index={await getNavIndex()} />
34 {children}
35 </DocsLayout>
36 );
docs/tests/static/sidebar-nav-index.test.ts
+13 -11
@@ -21,14 +21,14 @@ describe('buildSidebarNavIndex', () => {
21 group: 'Core concepts',
22 folder: 'Authentication',
23 depth: 2,
24 - position: 7,
24 + position: index['/docs/authentication/controlling-scopes'].position + 1,
25 });
26
27 expect(index['/docs/extending-sessions/shared-connections']).toEqual({
28 group: 'Guides',
29 folder: 'Extend sessions',
30 depth: 2,
31 - position: 3,
31 + position: index['/docs/extending-sessions/custom-tools-and-toolkits'].position + 1,
32 });
33 });
34
@@ -37,7 +37,7 @@ describe('buildSidebarNavIndex', () => {
37 group: 'Get Started',
38 folder: null,
39 depth: 1,
40 - position: 2,
40 + position: index['/docs'].position + 1,
41 });
42 });
43
@@ -46,13 +46,14 @@ describe('buildSidebarNavIndex', () => {
46 group: 'Core concepts',
47 folder: 'Authentication',
48 depth: 1,
49 - position: 3,
49 + position: index['/docs/configuring-sessions'].position + 1,
50 });
51 });
52
53 test('position resets at the next separator', () => {
54 + // Core concepts opens a new group, so its first entry restarts at 1 rather
55 + // than continuing Get Started's numbering.
56 expect(index['/docs'].position).toBe(1);
55 - expect(index['/docs/quickstart'].position).toBe(2);
57 expect(index['/docs/how-composio-works'].position).toBe(1);
58 });
59
@@ -61,11 +62,12 @@ describe('buildSidebarNavIndex', () => {
62 expect(index['/docs/extending-sessions/proxy-execute'].position).toBe(1);
63 });
64
64 - test('a folder counts as one row for its siblings', () => {
65 - // Authentication is row 3 in Core concepts and holds 7 children. Counting
66 - // through them would report Triggers as row 11 while it renders as row 4.
67 - expect(index['/docs/triggers'].position).toBe(4);
68 - expect(index['/docs/skills'].position).toBe(5);
65 + test('a folder counts as one entry for its siblings', () => {
66 + // Authentication holds 7 children, so a counter that threaded through them
67 + // would put Triggers 7 sibling slots later than Authentication instead of
68 + // directly after it.
69 + expect(index['/docs/triggers'].position).toBe(index['/docs/authentication'].position + 1);
70 + expect(index['/docs/skills'].position).toBe(index['/docs/triggers'].position + 1);
71 });
72
73 test('nested folders restart the sequence at each level', () => {
@@ -73,7 +75,7 @@ describe('buildSidebarNavIndex', () => {
75 group: 'Get Started',
76 folder: 'Custom providers',
77 depth: 2,
76 - position: 12,
78 + position: index['/docs/providers/mastra'].position + 1,
79 });
80 expect(index['/docs/providers/custom-providers/typescript'].position).toBe(1);
81 });