-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Avatar] Expose onError
hook
#4052
Conversation
@whizkydee I am wondering if the error could be handled in your app before using the component? It feels like the wrong level of abstraction. Interested to know what blockers exist there? |
@alex-page The problem is we have know way of knowing that the image errored, so we can't handle it. This hook is meant to inform us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to ship this, but I still think this check should happen before rendering the Avatar
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense to add but also agree with Alex that the best UX would be to determine if the image request 404'd before trying to render the Avatar.
Sounds like your situation is a bit different with the re-rendering on click though so I think if this works for your use case then 🚢
WHY are these changes introduced?
Due to surface area constraints, in our app, we use custom a user menu — the activator is a standalone avatar within a button which toggles a
Popover
. The popover includes an avatar and the full name of the user in question, as opposed to displaying the full name alongside the avatar directly on the top bar.For Identity users that haven't uploaded an avatar, we attempt to grab an image from gravatar based on their
uuid
which eventually resolves to their email — that request can either return the image or404
if the account doesn't exist.The problem with that is each time the user menu activator is clicked, the popover is re-rendered which results in extraneous requests to the same url that previously failed in an attempt to retrieve the gravatar.
WHAT is this pull request doing?
This adds an
onError
hook to theAvatar
component, which provides consumers with an avenue to make decisions when the HTTP request for an avatar fails. In our case, we'll simply prevent subsequent requests to the same url.How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist
README.md
with documentation changes