Skip to content

Commit 1420180

Browse files
authored
Assistant: Prevent sending queries multiple times (#3565)
1 parent e1b2cf6 commit 1420180

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/gitbook/src/components/AI/useAIChat.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function useAIChatController(): AIChatController {
138138
// Post a message to the AI chat
139139
const onPostMessage = React.useCallback(
140140
async (input: { message: string }) => {
141-
const { messages } = globalState.getState().state;
141+
const { query, messages } = globalState.getState().state;
142142

143143
// For first message, update the ask parameter in URL
144144
if (messages.length === 0) {
@@ -150,6 +150,11 @@ export function useAIChatController(): AIChatController {
150150
}));
151151
}
152152

153+
if (query === input.message) {
154+
// Return early if the message is the same as the previous message
155+
return;
156+
}
157+
153158
trackEvent({ type: 'ask_question', query: input.message });
154159

155160
// Add user message and placeholder for AI response

0 commit comments

Comments
 (0)