Skip to content

Avoid duplicate error toasts when a user does not exist#3496

Closed
yateendogra2109 wants to merge 20 commits intometabrainz:masterfrom
yateendogra2109:suppress-duplicate-user-not-found-errors
Closed

Avoid duplicate error toasts when a user does not exist#3496
yateendogra2109 wants to merge 20 commits intometabrainz:masterfrom
yateendogra2109:suppress-duplicate-user-not-found-errors

Conversation

@yateendogra2109
Copy link
Copy Markdown
Contributor

Problem

In some edge cases, the user page mounts successfully but several independent API calls (followers, following, similar users, etc.) fail with the same root cause: “User not found”.
Each failure currently raises its own toast, resulting in a cascade of duplicate error messages for what is fundamentally a single problem.

This creates a noisy and confusing user experience, especially for new or partially-initialized accounts in development and transient backend states in production.

Screenshot 2026-01-11 035828

Solution

This change introduces a small guard in UserSocialNetwork to detect the “user not found” condition once and suppress subsequent errors caused by the same root issue.

  • A shared userNotFound state ensures the toast is shown only once.

  • All related API calls short-circuit when the root cause is detected.

  • Existing behavior for genuine, independent failures (e.g., followers API failing for a valid user) is preserved.

  • The state is reset when the viewed profile changes.

A regression test is added to ensure that multiple “User not found” failures result in a single toast.

Action

No additional action is required. This change is safe to merge as-is.

Copy link
Copy Markdown
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thanks for opening a PR :)

I think this can be solved in a much easier manner, by ensuring the toastId is the same for all these notifications.
This prevents duplicates, see https://fkhadra.github.io/react-toastify/prevent-duplicate#simply-provide-a-toast-id

So you can still use your isUserNotFoundError utility, but use it instead to set the toastID to "user-not-found-error" (for example) when this type of error is detected.

@yateendogra2109 yateendogra2109 force-pushed the suppress-duplicate-user-not-found-errors branch from 79f35c0 to 6526871 Compare January 13, 2026 13:48
@yateendogra2109
Copy link
Copy Markdown
Contributor Author

@MonkeyDo
Thanks for the suggestion.
You were right — I simplified the approach by switching to a shared toastId for the “User not found” case instead of manually suppressing duplicates. I kept the isUserNotFoundError utility and now use it to consistently assign the same toastId, so React-Toastify handles the deduplication for us.

I also refined the previous changes and updated the tests to reflect this behavior.

Copy link
Copy Markdown
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for implementing these improvements.

I want to outline that we strongly prefer to review code that you wrote yourself, as opposed to written by an AI. This is true both for code and for our communications.

I see clear signs that you are using an AI to help out in the tasks and communication; the issue is that I do not know where your work ends and where the LLM's work begins, which makes it impossible for me to evaluate the quality of your problem solving skills.

So, from this point on, a few things you should be aware of:

  1. you must explicitly disclose if you are using AI tools, and where/for what parts
  2. we strongly prefer and encourage you to use and improve your own skills
  3. where GSOC is concerned, no AI usage is allowed

Comment on lines +63 to +72
title={isUserMissing ? "User not found" : "Error while fetching followers"}
message={
isUserMissing ? "This user does not exist yet." : err.toString()
}
/>,
{ toastId: "fetch-followers-error" }
{
toastId: isUserMissing
? "user-not-found-error"
: "fetch-followers-error",
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of code being duplicated, it would be better to separate the user not found error toast in a separate function that you can reuse, and avoid all these ternary expressions that make the code harder to read.

In pseudo code:

showUserMissingToast = React.useCallback(
  toast.error(
     title: "User not found",
     message: "This user does not exist",
     toastId: "user-not-found-error"
  )
)

.........
// later in the code:

if isUserMissing
  showUserMissingToast()
else
  // custom error toast for this API call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion , I just reframed the code as you said and used showUserNotFoundToast helper using useCallback, and then using a simple if / else structure in each catch block.

Also Regarding your concern about AI usage :Thanks for letting me know about the AI poilicies as I am new to the community.I did use an AI tool for some guidance here and should have made that explicit. I’ll make sure my contributions clearly reflect my own work and reasoning in future work

Copy link
Copy Markdown
Member

@MonkeyDo MonkeyDo Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for being candid.
To be clear, some companies expect you to use AI for productivity.
In open-source, where productivity is not important, it is rare that people like it, as we prefer community-oriented and long-lasting robust code.
Same goes for communication, we want human contact :)

In the context of GSOC it is much more important: I'm not here to mentor an AI, and you're not here to learn how to use an AI, but instead how to improve your reasoning, critical thinking and coding skills.

Comment thread frontend/js/tests/user/follow/UserSocialNetwork.test.tsx
Comment thread frontend/js/tests/user/follow/UserSocialNetwork.test.tsx Outdated
Comment thread frontend/js/tests/user/follow/UserSocialNetwork.test.tsx Outdated
Comment thread frontend/js/tests/user/follow/UserSocialNetwork.test.tsx Outdated
Copy link
Copy Markdown
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for those improvements.

I think your changes are good to merge now, except for one small issue:
I think your rebase process might have missed a step, the PR now contains a lot of unrelated changed files from master.

Generally, you don't need to update the PR when master changes. If you need to, the easiest option is to create a merge commit.

I think you might have forgotten to pull on master before doing the rebase?
See this StackOverflow answer for an example of how to rebase again or cherry-pick the commits you want: https://stackoverflow.com/a/73951458/4904467

Do you want to try that out?

@yateendogra2109
Copy link
Copy Markdown
Contributor Author

Thank you for those improvements.

I think your changes are good to merge now, except for one small issue: I think your rebase process might have missed a step, the PR now contains a lot of unrelated changed files from master.

Generally, you don't need to update the PR when master changes. If you need to, the easiest option is to create a merge commit.

I think you might have forgotten to pull on master before doing the rebase? See this StackOverflow answer for an example of how to rebase again or cherry-pick the commits you want: https://stackoverflow.com/a/73951458/4904467

Do you want to try that out?

Hi @MonkeyDo
I tried Rebasing again but there are many rebase issues ocuring that introduced unrelated commits from master. And the branch looks quite messy.

So reopening a new PR with a clean branch with PR id : #3506

Sorry for the confusion!

@MonkeyDo
Copy link
Copy Markdown
Member

So reopening a new PR with a clean branch with PR id : #3506
Sorry for the confusion!

That works too! No problem, PRs are free :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants