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): prevent duplicate keyboard shortcut listeners for Ask AI

Sushmithamallesh6c6a7e9e5752
diff --git a/docs/components/ask-ai-button.tsx b/docs/components/ask-ai-button.tsx
index 311a8f168..80068c1f4 100644
--- a/docs/components/ask-ai-button.tsx
+++ b/docs/components/ask-ai-button.tsx
@@ -32,8 +32,12 @@ function useIsMac() {
return isMac;
}
+let shortcutRegistered = false;
+
function useAskAIShortcut() {
useEffect(() => {
+ if (shortcutRegistered) return;
+ shortcutRegistered = true;
function handleKeyDown(e: KeyboardEvent) {
if ((e.metaKey || e.ctrlKey) && e.key === 'i') {
e.preventDefault();
@@ -41,7 +45,10 @@ function useAskAIShortcut() {
}
}
document.addEventListener('keydown', handleKeyDown);
- return () => document.removeEventListener('keydown', handleKeyDown);
+ return () => {
+ document.removeEventListener('keydown', handleKeyDown);
+ shortcutRegistered = false;
+ };
}, []);
}
@@ -90,7 +97,6 @@ export function SearchAndAskAI() {
/** Mobile: search icon + Ask AI icon, shown below lg breakpoint */
export function SearchAndAskAIMobile() {
const { enabled, setOpenSearch } = useSearchContext();
- useAskAIShortcut();
return (
<>