Avoid duplicate error toasts when a user does not exist#3496
Avoid duplicate error toasts when a user does not exist#3496yateendogra2109 wants to merge 20 commits intometabrainz:masterfrom
Conversation
MonkeyDo
left a comment
There was a problem hiding this comment.
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.
79f35c0 to
6526871
Compare
- Add test to verify only one toast appears for multiple 404 errors - Verify toastId 'user-not-found-error' is used for deduplication - Preserve existing test coverage for other error types
|
@MonkeyDo I also refined the previous changes and updated the tests to reflect this behavior. |
MonkeyDo
left a comment
There was a problem hiding this comment.
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:
- you must explicitly disclose if you are using AI tools, and where/for what parts
- we strongly prefer and encourage you to use and improve your own skills
- where GSOC is concerned, no AI usage is allowed
| 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", | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.6.0 to 2.6.3. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](urllib3/urllib3@2.6.0...2.6.3) --- updated-dependencies: - dependency-name: urllib3 dependency-version: 2.6.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
MonkeyDo
left a comment
There was a problem hiding this comment.
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 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 :) |
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.
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