From 117e947f11a94b63cbd1b0179b2fd7fccfee5fd0 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Mon, 18 Mar 2024 19:48:24 +0545 Subject: [PATCH] Fix username fetch on every keystroke issue in `commentInput` component - Fixes #6166 --- frontend/src/components/comments/commentInput.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/comments/commentInput.js b/frontend/src/components/comments/commentInput.js index 47c119fdc9..d5ad00ee8b 100644 --- a/frontend/src/components/comments/commentInput.js +++ b/frontend/src/components/comments/commentInput.js @@ -49,9 +49,10 @@ export const CommentInputField = ({ try { if (!query) return cb(contributors.map((username) => ({ username }))); - // do not fetch data if the value comes from suggestions popup click - const isValueFromSuggestion = /^\[.*?\]\s$/.test(query); - if (isValueFromSuggestion) return; + // address trigger js allowSpaces=true issue + // which triggers this function every keystroke + const isUsernameAlreadyFetched = /^\[.*?\]\s/.test(query); + if (isUsernameAlreadyFetched) return; const res = await fetchLocalJSONAPI(`users/queries/filter/${query}/`, token); cb(res.usernames.map((username) => ({ username })));