-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Avatar] Makes Avatar Image load only if Image load without error #712
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
Conversation
Leaving this as a WIP until we can verify that this approach will work in production. |
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 have some concerns about calling setState in componentDidUpdate
. Is there anything we can do here as an alternative? Can it be guarded so it's not called needlessly?
0fa5af8
to
6601426
Compare
6601426
to
4b50181
Compare
A couple questions:
|
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 a better approach here is to use !isServer
(easy to test) and getDerivedStateFromProps
for handling changes to the source
prop
I’m okay either way. I prefer taking advantage of the lifecycle hooks, it feels more like a React approach but I’ll give this a shot. The other PR was reverted because it broke in prod because of an issue with how Avatar was being exported. |
I would disagree – just because we use a lifecycle hook doesn’t necessarily mean it is a better React approach. In this case, it adds complexity (extra state and lifecycle hook) and is harder to test. It also adds an extra render we can avoid:
|
b1f709a
to
a2589dd
Compare
@tmlayton all changes have been applied and added a test for the isServer. Once you approve we can retry a test on web. |
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.
Code changes, test coverage, and the getDerivedStateFromProps
approach in particular LGTM. I guess we give this another try in web
at some point this week. What do you think @lemonmade and @tmlayton?
8e267ea
to
13b7ade
Compare
13b7ade
to
94406fe
Compare
94406fe
to
9346729
Compare
@@ -1,4 +1,4 @@ | |||
import Avatar from './Avatar'; | |||
|
|||
export * from './Avatar'; |
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.
@danrosenthal this should ensure we don't get the issue we experienced in web. There's no need to export * now that Avatar is a class component.
WHY are these changes introduced?
Resolves https://github.com/Shopify/shopify/issues/174824
The default option we want for our Avatar component is to show the logged in user initials if an avatar image is not found. Gravatar gives us the possibility of providing a default image when an image is not found or to return a 404.
In this pr we attempted to return a transparent image. This was done with the following option in the query:
The idea being that if the fallback was a transparent image it would simply lay over the Initials and wouldn't be visible.
However the Initials are in circle coloured background. As a result when an image was present it would show through pr
WHAT is this pull request doing?
This PR is taking the is relying on gravatar returning a 404.
If an image requested returns a 404 the onError attribute of the image tag will trigger and no image will be outputted.
In previous attempts server side rendering was causing the onLoad and onError of the image to not trigger. This PR adds the image only on the componentDidMount Lifecycle.
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist