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 22, 10:45 UTC
fix(docs): prevent infinite fetch loop on API failure in ToolItem
Replace useCallback+useEffect pattern with a single useEffect guarded by a `fetched` flag. Previously, a failed fetch left detailedParams null and loading false, creating a new callback ref each render and retriggering the effect indefinitely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sushmithamallesh committed
Feb 5, 2026 at 21:04 UTC
751175a2d8e1f18509a14ab49a9e2a918ccc00a7
1 file changed
+20
-27
docs/components/toolkits/toolkit-detail.tsx
+20
-27
@@ -1,6 +1,6 @@
1
'use client';
2
3
-import { useState, useMemo, useEffect, useCallback, type ReactNode } from 'react';
3
+import { useState, useMemo, useEffect, type ReactNode } from 'react';
4
import Link from 'next/link';
5
import { ExternalLink, Search, Copy, Check, ChevronDown, ChevronRight, ArrowLeft } from 'lucide-react';
6
import { TypeTable } from 'fumadocs-ui/components/type-table';
@@ -124,7 +124,7 @@ function ToolItem({ item, toolkitVersion }: { item: Tool | Trigger; toolkitVersi
124
input?: Record<string, ParameterSchema>;
125
output?: Record<string, ParameterSchema>;
126
} | null>(null);
127
- const [loading, setLoading] = useState(false);
127
+ const [fetched, setFetched] = useState(false);
128
129
const copySlug = (e: React.MouseEvent) => {
130
e.stopPropagation();
@@ -136,32 +136,25 @@ function ToolItem({ item, toolkitVersion }: { item: Tool | Trigger; toolkitVersi
136
const tool = isTool(item) ? item : null;
137
const trigger = isTrigger(item) ? item : null;
138
139
- // Fetch detailed schema when a tool is expanded
140
- const fetchDetailedSchema = useCallback(async () => {
141
- if (!tool || detailedParams || loading) return;
142
- setLoading(true);
143
- try {
144
- const versionParam = toolkitVersion ? `?version=${encodeURIComponent(toolkitVersion)}` : '';
145
- const res = await fetch(`/api/tools/${item.slug}${versionParam}`);
146
- if (res.ok) {
147
- const data = await res.json();
148
- setDetailedParams({
149
- input: processSchema(data.input_parameters),
150
- output: processSchema(data.output_parameters),
151
- });
152
- }
153
- } catch {
154
- // silently fall back to basic params
155
- } finally {
156
- setLoading(false);
157
- }
158
- }, [tool, item.slug, toolkitVersion, detailedParams, loading]);
159
-
139
+ // Fetch detailed schema once when a tool is first expanded
140
useEffect(() => {
161
- if (expanded && tool) {
162
- fetchDetailedSchema();
163
- }
164
- }, [expanded, tool, fetchDetailedSchema]);
141
+ if (!expanded || !tool || fetched) return;
142
+ setFetched(true);
143
+ const versionParam = toolkitVersion ? `?version=${encodeURIComponent(toolkitVersion)}` : '';
144
+ fetch(`/api/tools/${item.slug}${versionParam}`)
145
+ .then((res) => (res.ok ? res.json() : null))
146
+ .then((data) => {
147
+ if (data) {
148
+ setDetailedParams({
149
+ input: processSchema(data.input_parameters),
150
+ output: processSchema(data.output_parameters),
151
+ });
152
+ }
153
+ })
154
+ .catch(() => {
155
+ // silently fall back to basic params
156
+ });
157
+ }, [expanded, tool, fetched, item.slug, toolkitVersion]);
158
159
const inputParams = detailedParams?.input || tool?.input_parameters;
160
const outputParams = detailedParams?.output || tool?.output_parameters;