Skip to content

Commit cf91d89

Browse files
Reset the timeout when the ai panel pops up
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a093f6e commit cf91d89

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

apps/webapp/app/components/AskAI.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,19 @@ export function AskAIProvider({ children, websiteId }: AskAIProviderProps) {
8080
useEffect(() => {
8181
const aiHelp = searchParams.get("aiHelp");
8282
if (aiHelp) {
83-
setSearchParams((prev) => {
84-
prev.delete("aiHelp");
85-
return prev;
86-
});
87-
8883
const decodedAiHelp = decodeURIComponent(aiHelp);
8984

90-
// Add a delay to avoid triggering hCaptcha bot detection
91-
setTimeout(() => {
92-
openAskAI(decodedAiHelp);
93-
}, 1000);
94-
}
95-
}, [searchParams, setSearchParams, openAskAI]);
85+
// Delay to avoid hCaptcha bot detection
86+
const timeoutId = window.setTimeout(() => openAskAI(decodedAiHelp), 1000);
9687

97-
const contextValue: AskAIContextType = {
88+
// Clone instead of mutating in place
89+
const next = new URLSearchParams(searchParams);
90+
next.delete("aiHelp");
91+
setSearchParams(next);
92+
93+
return () => clearTimeout(timeoutId);
94+
}
95+
}, [searchParams.toString(), openAskAI]);
9896
isOpen,
9997
openAskAI,
10098
closeAskAI,

0 commit comments

Comments
 (0)