Skip to content

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): isolate product theme from next-themes storage, switcher link fixes (#4349)

Alberto Schiabel0d4383c4f74e
diff --git a/docs/app/layout.tsx b/docs/app/layout.tsx
index ceabf9db7..4d644fa13 100644
--- a/docs/app/layout.tsx
+++ b/docs/app/layout.tsx
@@ -88,11 +88,10 @@ export default async function Layout({ children }: LayoutProps<'/'>) {
<head>
<script
dangerouslySetInnerHTML={{
- __html: `try{localStorage.setItem('theme','${initialTheme}')}catch{}document.documentElement.classList.remove('light','dark');document.documentElement.classList.add('${initialTheme}');document.documentElement.style.colorScheme='${initialTheme}'`,
+ __html: `try{document.documentElement.classList.remove('light','dark');document.documentElement.classList.add('${initialTheme}');document.documentElement.style.colorScheme='${initialTheme}'}catch{}`,
}}
/>
- <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
- <meta name="theme-color" content="#131211" media="(prefers-color-scheme: dark)" />
+ <meta name="theme-color" content={DOCS_PRODUCTS[initialProduct].themeColor} />
<script
type="application/ld+json"
dangerouslySetInnerHTML={{
@@ -132,9 +131,12 @@ export default async function Layout({ children }: LayoutProps<'/'>) {
<ProductTransitionLoader />
<Analytics />
<PostHogProvider>
+ {/* DocsProductProvider owns the rendered theme; useTheme().resolvedTheme is not a product-theme signal. */}
<RootProvider
theme={{
defaultTheme: 'system',
+ forcedTheme: initialTheme,
+ storageKey: 'composio-docs-theme',
attribute: 'class',
enableSystem: true,
hotKey: false,
diff --git a/docs/components/docs-product-context.tsx b/docs/components/docs-product-context.tsx
index 4d53afb5b..393a8791c 100644
--- a/docs/components/docs-product-context.tsx
+++ b/docs/components/docs-product-context.tsx
@@ -12,7 +12,6 @@ import {
} from 'react';
import { flushSync } from 'react-dom';
import { usePathname, useRouter } from 'next/navigation';
-import { useTheme } from 'fumadocs-ui/provider/base';
import {
classifyDocsProduct,
DOCS_PRODUCTS,
@@ -47,6 +46,23 @@ function writeProductCookie(product: DocsProduct): void {
document.cookie = serializeDocsProductCookie(product);
}
+/**
+ * The product theme is derived state, not a user preference: apply it directly
+ * to the document element instead of routing it through next-themes' shared
+ * `theme` localStorage key, whose cross-tab storage events would repaint other
+ * tabs that are viewing the other product.
+ */
+function applyProductTheme(product: DocsProduct): void {
+ const { theme, themeColor } = DOCS_PRODUCTS[product];
+ const root = document.documentElement;
+ root.classList.remove('light', 'dark');
+ root.classList.add(theme);
+ root.style.colorScheme = theme;
+ document
+ .querySelector('meta[name="theme-color"]')
+ ?.setAttribute('content', themeColor);
+}
+
export function DocsProductProvider({
initialProduct,
children,
@@ -56,7 +72,6 @@ export function DocsProductProvider({
}) {
const pathname = usePathname();
const router = useRouter();
- const { setTheme } = useTheme();
const [persistedProduct, setPersistedProduct] = useState(initialProduct);
const [pendingProduct, setPendingProduct] = useState<DocsProduct | null>(null);
const pendingNavigation = useRef<{
@@ -68,8 +83,8 @@ export function DocsProductProvider({
const product = pendingProduct ?? inferredProduct ?? persistedProduct;
useEffect(() => {
- setTheme(DOCS_PRODUCTS[product].theme);
- }, [product, setTheme]);
+ applyProductTheme(product);
+ }, [product]);
const persistProduct = useCallback((nextProduct: DocsProduct) => {
writeProductCookie(nextProduct);
@@ -108,7 +123,7 @@ export function DocsProductProvider({
flushSync(() => {
setPersistedProduct(nextProduct);
setPendingProduct(nextProduct);
- setTheme(DOCS_PRODUCTS[nextProduct].theme);
+ applyProductTheme(nextProduct);
});
if (href !== pathname) router.push(href);
};
@@ -167,7 +182,7 @@ export function DocsProductProvider({
commitNavigation();
}
},
- [pathname, router, setTheme],
+ [pathname, router],
);
const value = useMemo(
diff --git a/docs/components/home-surfaces.tsx b/docs/components/home-surfaces.tsx
index 2f21446ab..7580fba50 100644
--- a/docs/components/home-surfaces.tsx
+++ b/docs/components/home-surfaces.tsx
@@ -40,7 +40,6 @@ function IntentCard({ intent }: { intent: HomeIntent }) {
return (
<article className="grid overflow-hidden border border-fd-border bg-fd-card shadow-[0_1px_0_rgba(15,15,15,0.04)] md:grid-cols-[minmax(0,1fr)_calc(50%-0.75rem)]">
<ProductSelectionLink
- aria-label={`Explore ${intent.product} docs`}
className="relative overflow-hidden border-b border-fd-border bg-fd-background p-5 pb-40 no-underline transition-colors hover:bg-fd-accent/20 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-fd-ring sm:p-6 sm:pb-44 md:min-h-72 md:border-b-0 md:border-r md:pb-6"
href={DOCS_PRODUCTS[intent.productId].landingRoute}
product={intent.productId}
diff --git a/docs/components/product-switcher.tsx b/docs/components/product-switcher.tsx
index 7e8a9a642..de6db936d 100644
--- a/docs/components/product-switcher.tsx
+++ b/docs/components/product-switcher.tsx
@@ -78,7 +78,9 @@ export function ProductSwitcher({ placement = 'sidebar' }: { placement?: 'nav' |
{DOCS_PRODUCT_ORDER.map((productId, index) => {
const option = DOCS_PRODUCTS[productId];
const isCurrent = productId === product;
- const destination = docsProductDestination(pathname, productId);
+ const destination = isCurrent
+ ? pathname
+ : docsProductDestination(pathname, productId);
return (
<div key={productId}>
{index > 0 && <div aria-hidden="true" className="mx-2 my-1 h-px bg-fd-border" />}
diff --git a/docs/lib/home-navigation.ts b/docs/lib/home-navigation.ts
index 60f79f053..a5053c44b 100644
--- a/docs/lib/home-navigation.ts
+++ b/docs/lib/home-navigation.ts
@@ -30,6 +30,7 @@ interface DocsProductConfig {
switcherDescription: string;
landingRoute: string;
theme: 'light' | 'dark';
+ themeColor: '#131211' | '#ffffff';
routePrefixes: readonly string[];
sidebar: readonly ProductSidebarGroup[];
home: Omit<HomeIntent, 'productId' | 'product'>;
@@ -61,6 +62,7 @@ export const DOCS_PRODUCTS = {
switcherDescription: 'Connect your apps to AI clients.',
landingRoute: '/docs/agent-plugins',
theme: 'light',
+ themeColor: '#ffffff',
routePrefixes: [
'/docs/agent-plugins',
'/docs/claude-code-plugin',
@@ -107,6 +109,7 @@ export const DOCS_PRODUCTS = {
switcherDescription: 'Build agents with the Composio SDK.',
landingRoute: '/docs/quickstart',
theme: 'dark',
+ themeColor: '#131211',
routePrefixes: [
'/docs/quickstart',
'/docs/providers',
diff --git a/docs/tests/static/product-navigation.test.ts b/docs/tests/static/product-navigation.test.ts
index 06de35fc8..aedbd71ad 100644
--- a/docs/tests/static/product-navigation.test.ts
+++ b/docs/tests/static/product-navigation.test.ts
@@ -21,12 +21,14 @@ describe('Docs product navigation', () => {
switcherDescription: 'Connect your apps to AI clients.',
landingRoute: '/docs/agent-plugins',
theme: 'light',
+ themeColor: '#ffffff',
});
expect(DOCS_PRODUCTS.platform).toMatchObject({
product: 'Platform',
switcherDescription: 'Build agents with the Composio SDK.',
landingRoute: '/docs/quickstart',
theme: 'dark',
+ themeColor: '#131211',
});
});
@@ -162,9 +164,17 @@ describe('Docs product navigation', () => {
expect(switcherSource).toContain('href="/"');
expect(sharedLayoutSource).toContain('slots: { navTitle: ProductNavTitle }');
expect(sharedLayoutSource).toContain('themeSwitch: { enabled: false }');
- expect(contextSource).toContain('setTheme(DOCS_PRODUCTS[product].theme)');
+ expect(contextSource).toContain('applyProductTheme(product)');
+ expect(contextSource).toContain('.querySelector(\'meta[name="theme-color"]\')');
+ expect(contextSource).toContain("?.setAttribute('content', themeColor)");
expect(contextSource).toContain('window.setTimeout(finish, 1500)');
- expect(rootLayoutSource).toContain("localStorage.setItem('theme','${initialTheme}')");
+ expect(rootLayoutSource).toContain('forcedTheme: initialTheme');
+ expect(rootLayoutSource).toContain("storageKey: 'composio-docs-theme'");
+ expect(rootLayoutSource).toContain(
+ 'content={DOCS_PRODUCTS[initialProduct].themeColor}',
+ );
+ expect(contextSource).not.toContain("localStorage.setItem('theme'");
+ expect(rootLayoutSource).not.toContain("localStorage.setItem('theme'");
expect(rootLayoutSource).toContain('hotKey: false');
});
});