From bdadd09645b6d3a577b078b2b45644a393d23764 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Tue, 23 Jan 2024 12:17:29 +0545 Subject: [PATCH 1/2] Do not fetch user data on suggestions popup click in `Comments Section` - Fixes #6166 --- frontend/src/components/comments/commentInput.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/components/comments/commentInput.js b/frontend/src/components/comments/commentInput.js index 839ba179f2..47c119fdc9 100644 --- a/frontend/src/components/comments/commentInput.js +++ b/frontend/src/components/comments/commentInput.js @@ -48,6 +48,11 @@ export const CommentInputField = ({ values: async (query, cb) => { 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; + const res = await fetchLocalJSONAPI(`users/queries/filter/${query}/`, token); cb(res.usernames.map((username) => ({ username }))); } catch (e) { From 117e947f11a94b63cbd1b0179b2fd7fccfee5fd0 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Mon, 18 Mar 2024 19:48:24 +0545 Subject: [PATCH 2/2] 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 })));