Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

fix defaultSrc behavior if src is null#106

Merged
modernserf merged 2 commits intomasterfrom
modernserf/ch14996/fix-defaultsrc-behavior-for-avatar-shared
Apr 30, 2020
Merged

fix defaultSrc behavior if src is null#106
modernserf merged 2 commits intomasterfrom
modernserf/ch14996/fix-defaultsrc-behavior-for-avatar-shared

Conversation

@modernserf
Copy link
Copy Markdown
Contributor

Previously, <Avatar src={null} defaultSrc={fallbackImg} /> would flicker with the fallback image, and then go blank. I believe this is because:

  • if an img src is a string, it will try to load the URL at that string and error if it fails; however, if src is nullish then it just shows nothing
  • useEffect runs after mount, not just after updates, so the useEffect handler immediately overwrites the initial value of activeSrc
  • the previous version of the useEffect handler did not have defaultSrc as a fallback value if src was falsy, so it was setting activeSrc to src's nullish value

With this PR, <Avatar src={null} defaultSrc={fallbackImg} /> shows the fallback image consistently. I also added a story that demonstrates the defaultSrc behavior and verifies that the provided change works correctly.

@modernserf modernserf requested a review from clottman April 29, 2020 19:29
@modernserf modernserf merged commit 6200fba into master Apr 30, 2020
@modernserf modernserf deleted the modernserf/ch14996/fix-defaultsrc-behavior-for-avatar-shared branch April 30, 2020 14:12
@keithk
Copy link
Copy Markdown
Contributor

keithk commented Nov 10, 2020

🚀 PR was released in v0.19.0 🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants