Skip to content

Commit

Permalink
Fix username fetch on every keystroke issue in commentInput component
Browse files Browse the repository at this point in the history
- Fixes #6166
  • Loading branch information
royallsilwallz committed Mar 18, 2024
1 parent bdadd09 commit 117e947
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frontend/src/components/comments/commentInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })));
Expand Down

0 comments on commit 117e947

Please sign in to comment.