Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(docs): address product switcher review
Brendan O'Leary committed
Sep 2, 2026 at 13:32 UTC
72dbbcbee7d13cee946b29f3797904623409314d
7 files changed
+103
-101
docs/components/docs-product-context.tsx
+17
-12
@@ -12,10 +12,8 @@ import {
12
} from 'react';
13
import { flushSync } from 'react-dom';
14
import { usePathname, useRouter } from 'next/navigation';
15
-import { useTheme } from 'fumadocs-ui/provider/base';
15
import {
16
classifyDocsProduct,
18
- DOCS_PRODUCTS,
17
serializeDocsProductCookie,
18
shouldAnimateDocsProductSwitch,
19
type DocsProduct,
@@ -56,7 +54,6 @@ export function DocsProductProvider({
54
}) {
55
const pathname = usePathname();
56
const router = useRouter();
59
- const { setTheme } = useTheme();
57
const [persistedProduct, setPersistedProduct] = useState(initialProduct);
58
const [pendingProduct, setPendingProduct] = useState<DocsProduct | null>(null);
59
const pendingNavigation = useRef<{
@@ -104,9 +101,8 @@ export function DocsProductProvider({
101
flushSync(() => {
102
setPersistedProduct(nextProduct);
103
setPendingProduct(nextProduct);
107
- setTheme(DOCS_PRODUCTS[nextProduct].defaultTheme);
104
});
109
- router.push(href);
105
+ if (href !== pathname) router.push(href);
106
};
107
108
const viewTransitionDocument = document as ViewTransitionDocument;
@@ -137,19 +133,28 @@ export function DocsProductProvider({
133
root.style.removeProperty('--docs-reveal-x');
134
root.style.removeProperty('--docs-reveal-y');
135
};
140
- window.setTimeout(cleanup, 6000);
136
+ window.setTimeout(cleanup, 2500);
137
138
try {
139
const transition = startViewTransition(() => {
140
+ if (href === pathname) {
141
+ commitNavigation();
142
+ return;
143
+ }
144
+
145
return new Promise<void>(resolve => {
146
pendingNavigation.current?.resolve();
146
- const timeout = window.setTimeout(resolve, 5000);
147
+ const finish = () => resolve();
148
+ window.setTimeout(() => {
149
+ if (pendingNavigation.current?.resolve === finish) {
150
+ pendingNavigation.current = null;
151
+ setPendingProduct(null);
152
+ }
153
+ finish();
154
+ }, 1500);
155
pendingNavigation.current = {
156
from: pathname,
149
- resolve: () => {
150
- window.clearTimeout(timeout);
151
- resolve();
152
- },
157
+ resolve: finish,
158
};
159
commitNavigation();
160
});
@@ -160,7 +165,7 @@ export function DocsProductProvider({
165
commitNavigation();
166
}
167
},
163
- [pathname, router, setTheme],
168
+ [pathname, router],
169
);
170
171
const value = useMemo(
docs/components/product-lockup.tsx
+22
-18
@@ -53,6 +53,27 @@ export function ProductBadge({ product }: { product: DocsProduct }) {
53
);
54
}
55
56
+export function ComposioWordmark({ compactOnMobile = false }: { compactOnMobile?: boolean }) {
57
+ return (
58
+ <span className={compactOnMobile ? 'max-[420px]:hidden' : undefined}>
59
+ <Image
60
+ alt="Composio"
61
+ className="h-[22px] w-auto dark:hidden"
62
+ height={20}
63
+ src="/Composio Logo.svg"
64
+ width={110}
65
+ />
66
+ <Image
67
+ alt="Composio"
68
+ className="hidden h-[22px] w-auto dark:block"
69
+ height={20}
70
+ src="/Composio Logo Dark.svg"
71
+ width={110}
72
+ />
73
+ </span>
74
+ );
75
+}
76
+
77
export function ProductLockup({
78
product,
79
compactOnMobile = false,
@@ -62,24 +83,7 @@ export function ProductLockup({
83
}) {
84
return (
85
<span className="inline-flex min-w-0 items-center gap-2">
65
- <span className={compactOnMobile ? 'max-[420px]:hidden' : undefined}>
66
- <Image
67
- alt="Composio"
68
- className="h-[22px] w-auto dark:hidden"
69
- height={20}
70
- priority
71
- src="/Composio Logo.svg"
72
- width={110}
73
- />
74
- <Image
75
- alt="Composio"
76
- className="hidden h-[22px] w-auto dark:block"
77
- height={20}
78
- priority
79
- src="/Composio Logo Dark.svg"
80
- width={110}
81
- />
82
- </span>
86
+ <ComposioWordmark compactOnMobile={compactOnMobile} />
87
<ProductBadge product={product} />
88
</span>
89
);
docs/components/product-selection-link.tsx
+5
-4
@@ -1,13 +1,14 @@
1
'use client';
2
3
-import Link, { type LinkProps } from 'next/link';
3
+import Link from 'next/link';
4
import type { AnchorHTMLAttributes, MouseEvent, ReactNode } from 'react';
5
import type { DocsProduct } from '@/lib/home-navigation';
6
import { useDocsProduct } from './docs-product-context';
7
8
-type ProductSelectionLinkProps = LinkProps &
9
- Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkProps> & {
8
+type ProductSelectionLinkProps =
9
+ Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {
10
children: ReactNode;
11
+ href: string;
12
product: DocsProduct;
13
};
14
@@ -32,7 +33,7 @@ export function ProductSelectionLink({
33
}
34
35
event.preventDefault();
35
- navigateToProduct(product, String(href), event.currentTarget);
36
+ navigateToProduct(product, href, event.currentTarget);
37
};
38
39
return (
docs/components/product-switcher.tsx
+29
-27
@@ -1,7 +1,8 @@
1
'use client';
2
3
-import { useRef, useState } from 'react';
3
+import { useState } from 'react';
4
import type { ComponentProps } from 'react';
5
+import Link from 'next/link';
6
import { usePathname, useRouter } from 'next/navigation';
7
import { Check, ChevronsUpDown } from 'lucide-react';
8
import {
@@ -13,31 +14,19 @@ import {
14
DOCS_PRODUCT_ORDER,
15
DOCS_PRODUCTS,
16
docsProductDestination,
16
- type DocsProduct,
17
} from '@/lib/home-navigation';
18
-import { ProductLockup } from './product-lockup';
18
+import { ComposioWordmark, ProductBadge, ProductLockup } from './product-lockup';
19
+import { ProductSelectionLink } from './product-selection-link';
20
import { useDocsProduct } from './docs-product-context';
21
import { cn } from '@/lib/utils';
22
23
export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' | 'sidebar' }) {
24
const pathname = usePathname();
25
const router = useRouter();
25
- const { product, navigateToProduct } = useDocsProduct();
26
+ const { product } = useDocsProduct();
27
const [open, setOpen] = useState(false);
27
- const triggerRef = useRef<HTMLButtonElement>(null);
28
const current = DOCS_PRODUCTS[product];
29
30
- const selectProduct = (nextProduct: DocsProduct) => {
31
- if (nextProduct === product) {
32
- setOpen(false);
33
- return;
34
- }
35
-
36
- const destination = docsProductDestination(pathname, nextProduct);
37
- setOpen(false);
38
- navigateToProduct(nextProduct, destination, triggerRef.current);
39
- };
40
-
30
return (
31
<Popover open={open} onOpenChange={setOpen}>
32
<PopoverTrigger asChild>
@@ -65,10 +54,13 @@ export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' |
54
}
55
}
56
}}
68
- ref={triggerRef}
57
type="button"
58
>
71
- <ProductLockup compactOnMobile={placement === 'nav'} product={product} />
59
+ {placement === 'nav' ? (
60
+ <ProductBadge product={product} />
61
+ ) : (
62
+ <ProductLockup product={product} />
63
+ )}
64
<span className="inline-flex shrink-0 items-center gap-1 text-xs font-medium text-fd-muted-foreground group-hover:text-fd-foreground">
65
{placement === 'sidebar' && 'Switch'}
66
<ChevronsUpDown aria-hidden="true" className="size-3.5" />
@@ -77,25 +69,28 @@ export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' |
69
</PopoverTrigger>
70
<PopoverContent
71
align="start"
72
+ aria-label="Choose a Composio product"
73
className="w-[min(20rem,calc(100vw-2rem))] p-1"
74
side="bottom"
75
sideOffset={8}
76
>
84
- <div aria-label="Choose a Composio product" role="radiogroup">
77
+ <div>
78
{DOCS_PRODUCT_ORDER.map((productId, index) => {
79
const option = DOCS_PRODUCTS[productId];
80
const isCurrent = productId === product;
81
+ const destination = docsProductDestination(pathname, productId);
82
return (
83
<div key={productId}>
84
{index > 0 && <div aria-hidden="true" className="mx-2 my-1 h-px bg-fd-border" />}
91
- <button
92
- aria-checked={isCurrent}
85
+ <ProductSelectionLink
86
aria-current={isCurrent ? 'page' : undefined}
94
- aria-label={`${option.product}: ${option.switcherDescription}`}
87
className="flex w-full items-start gap-3 p-2.5 text-left transition-colors hover:bg-fd-accent/60 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-fd-ring"
96
- onClick={() => selectProduct(productId)}
97
- role="radio"
98
- type="button"
88
+ href={destination}
89
+ onClick={event => {
90
+ setOpen(false);
91
+ if (isCurrent) event.preventDefault();
92
+ }}
93
+ product={productId}
94
>
95
<span className="flex min-w-0 flex-1 flex-col gap-2">
96
<ProductLockup product={productId} />
@@ -107,7 +102,7 @@ export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' |
102
aria-hidden="true"
103
className={`mt-1 size-4 shrink-0 text-fd-primary ${isCurrent ? '' : 'invisible'}`}
104
/>
110
- </button>
105
+ </ProductSelectionLink>
106
</div>
107
);
108
})}
@@ -119,7 +114,14 @@ export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' |
114
115
export function ProductNavTitle({ className }: ComponentProps<'a'>) {
116
return (
122
- <div className={cn(className, 'min-w-0')}>
117
+ <div className={cn(className, 'flex min-w-0 items-center gap-1')}>
118
+ <Link
119
+ aria-label="Composio home"
120
+ className="shrink-0 rounded-sm px-1.5 max-[420px]:hidden"
121
+ href="/"
122
+ >
123
+ <ComposioWordmark />
124
+ </Link>
125
<ProductSwitcher placement="nav" />
126
</div>
127
);
docs/lib/home-navigation.ts
+9
-6
@@ -29,15 +29,18 @@ interface DocsProductConfig {
29
product: HomeIntent['product'];
30
switcherDescription: string;
31
landingRoute: string;
32
- defaultTheme: 'light' | 'dark';
32
routePrefixes: readonly string[];
33
sidebar: readonly ProductSidebarGroup[];
34
home: Omit<HomeIntent, 'productId' | 'product'>;
35
}
36
38
-const SHARED_SIDEBAR_ITEMS = [
37
+const SHARED_SIDEBAR_ITEMS: readonly ProductSidebarItem[] = [
38
{ type: 'folder', path: 'security', label: 'Security and data' },
40
-] as const satisfies readonly ProductSidebarItem[];
39
+];
40
+
41
+const SHARED_ROUTE_PREFIXES = SHARED_SIDEBAR_ITEMS.map(item =>
42
+ item.type === 'page' ? item.url : `/docs/${item.path}`,
43
+);
44
45
/**
46
* Canonical product model for the docs shell and homepage.
@@ -56,7 +59,6 @@ export const DOCS_PRODUCTS = {
59
product: 'For You',
60
switcherDescription: 'Connect your apps to AI clients.',
61
landingRoute: '/docs/agent-plugins',
59
- defaultTheme: 'light',
62
routePrefixes: [
63
'/docs/agent-plugins',
64
'/docs/claude-code-plugin',
@@ -102,7 +104,6 @@ export const DOCS_PRODUCTS = {
104
product: 'Platform',
105
switcherDescription: 'Build agents with the Composio SDK.',
106
landingRoute: '/docs/quickstart',
105
- defaultTheme: 'dark',
107
routePrefixes: [
108
'/docs/quickstart',
109
'/docs/providers',
@@ -228,7 +229,9 @@ export function resolveDocsProduct(
229
export function docsProductDestination(pathname: string, target: DocsProduct): string {
230
const sourceProduct = target === 'platform' ? 'for-you' : 'platform';
231
const counterpart = PRODUCT_COUNTERPARTS.find(pair => matchesRoute(pathname, pair[sourceProduct]));
231
- return counterpart?.[target] ?? DOCS_PRODUCTS[target].landingRoute;
232
+ if (counterpart) return counterpart[target];
233
+ if (SHARED_ROUTE_PREFIXES.some(prefix => matchesRoute(pathname, prefix))) return pathname;
234
+ return DOCS_PRODUCTS[target].landingRoute;
235
}
236
237
export function serializeDocsProductCookie(product: DocsProduct): string {
docs/lib/layout.shared.tsx
+1
-28
@@ -1,40 +1,13 @@
1
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
2
-import Image from 'next/image';
2
import { Play } from 'lucide-react';
3
import { SearchAndAskAI, SearchAndAskAIMobile } from '@/components/ask-ai-button';
4
import { NavVersionSelector } from '@/components/version-selector';
5
import { ProductNavTitle } from '@/components/product-switcher';
6
8
-// Composio Logo Component with light/dark mode switching
9
-function ComposioLogo() {
10
- return (
11
- <>
12
- {/* Light mode logo (black) */}
13
- <Image
14
- src="/Composio Logo.svg"
15
- alt="Composio"
16
- width={110}
17
- height={20}
18
- className="dark:hidden"
19
- priority
20
- />
21
- {/* Dark mode logo (white) */}
22
- <Image
23
- src="/Composio Logo Dark.svg"
24
- alt="Composio"
25
- width={110}
26
- height={20}
27
- className="hidden dark:block"
28
- priority
29
- />
30
- </>
31
- );
32
-}
33
-
7
export function baseOptions(): BaseLayoutProps {
8
return {
9
nav: {
37
- title: <ComposioLogo />,
10
+ title: null,
11
transparentMode: 'top',
12
},
13
slots: { navTitle: ProductNavTitle },
docs/tests/static/product-navigation.test.ts
+20
-6
@@ -14,19 +14,17 @@ import { buildProductPageTree, pageTreeUrls } from '../../lib/product-page-tree'
14
import { source } from '../../lib/source';
15
16
describe('Docs product navigation', () => {
17
- test('defines the product labels, descriptions, landings, and theme defaults once', () => {
17
+ test('defines the product labels, descriptions, and landings once', () => {
18
expect(DEFAULT_DOCS_PRODUCT).toBe('platform');
19
expect(DOCS_PRODUCTS['for-you']).toMatchObject({
20
product: 'For You',
21
switcherDescription: 'Connect your apps to AI clients.',
22
landingRoute: '/docs/agent-plugins',
23
- defaultTheme: 'light',
23
});
24
expect(DOCS_PRODUCTS.platform).toMatchObject({
25
product: 'Platform',
26
switcherDescription: 'Build agents with the Composio SDK.',
27
landingRoute: '/docs/quickstart',
29
- defaultTheme: 'dark',
28
});
29
});
30
@@ -69,6 +67,12 @@ describe('Docs product navigation', () => {
67
'/docs/agent-plugins',
68
);
69
expect(docsProductDestination('/docs/cli', 'platform')).toBe('/docs/quickstart');
70
+ expect(docsProductDestination('/docs/security/overview', 'for-you')).toBe(
71
+ '/docs/security/overview',
72
+ );
73
+ expect(docsProductDestination('/docs/security/data-retention', 'platform')).toBe(
74
+ '/docs/security/data-retention',
75
+ );
76
});
77
78
test('animates only when view transitions are available and motion is allowed', () => {
@@ -122,6 +126,13 @@ describe('Docs product navigation', () => {
126
expect(forYouUrls).toContain(sharedUrl);
127
expect(platformUrls).toContain(sharedUrl);
128
}
129
+
130
+ const coveredUrls = new Set([...forYouUrls, ...platformUrls]);
131
+ const excludedUrls = new Set(['/docs']);
132
+ const omittedUrls = pageTreeUrls(source.pageTree).filter(
133
+ url => !coveredUrls.has(url) && !excludedUrls.has(url),
134
+ );
135
+ expect(omittedUrls).toEqual([]);
136
});
137
138
test('keeps accessibility-critical switcher semantics and visible focus styles', async () => {
@@ -133,11 +144,14 @@ describe('Docs product navigation', () => {
144
).text();
145
146
expect(switcherSource).toContain('aria-label={`Switch Composio product. Current product:');
136
- expect(switcherSource).toContain('role="radiogroup"');
137
- expect(switcherSource).toContain('role="radio"');
138
- expect(switcherSource).toContain('aria-checked={isCurrent}');
147
+ expect(switcherSource).toContain('ProductSelectionLink');
148
+ expect(switcherSource).not.toContain('role="radiogroup"');
149
+ expect(switcherSource).not.toContain('role="radio"');
150
+ expect(switcherSource).not.toContain('aria-checked={isCurrent}');
151
expect(switcherSource).toContain("aria-current={isCurrent ? 'page' : undefined}");
152
expect(switcherSource).toContain('focus-visible:outline-2');
153
+ expect(switcherSource).toContain('aria-label="Composio home"');
154
+ expect(switcherSource).toContain('href="/"');
155
expect(sharedLayoutSource).toContain('slots: { navTitle: ProductNavTitle }');
156
});
157
});