-
Notifications
You must be signed in to change notification settings - Fork 1
Bug/69230 Handle 404 errors in AvatarWithFallback with client-side fallback #396
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 36d8fb8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Pull request overview
This pull request implements client-side error handling for avatar images that fail to load (404 errors, network failures, etc.). The component now automatically falls back to displaying SVG initials when an image fails to load, avoiding broken image icons.
Key changes:
- All avatars are now wrapped in an
<avatar-fallback>custom element with pre-generated fallback SVG - Client-side error listener detects image load failures and swaps to fallback SVG
- Race condition handling for errors that fire before listener attachment
- Updated tests to reflect new always-wrapped behavior
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| app/components/primer/open_project/avatar_with_fallback.rb | Changed from conditionally wrapping in avatar-fallback to always wrapping; added fallback_src data attribute |
| app/components/primer/open_project/avatar_fallback.ts | Added error event handling, race condition checking, and image-broken detection logic |
| test/components/open_project/avatar_with_fallback_test.rb | Updated tests to verify always-wrapped behavior and fallback SVG presence |
| test/components/open_project/avatar_stack_test.rb | Updated avatar-fallback count expectation from 1 to 2 to reflect new behavior |
| previews/primer/open_project/avatar_with_fallback_preview.rb | Added two new preview methods for demonstrating 404 error handling |
| previews/primer/open_project/avatar_with_fallback_preview/multiple_broken_images.html.erb | New template demonstrating multiple broken images |
| static/previews.json | Auto-generated: Added entries for new preview methods |
| static/info_arch.json | Auto-generated: Added entries for new preview methods |
| .changeset/olive-eyes-juggle.md | Added changeset entry for this patch-level change |
Server-side URL validation would add latency and can't handle relative URLs without knowing the host. Instead, we use client-side error handling: - Always wrap avatars in <avatar-fallback> element with pre-generated SVG stored in data-fallback-src attribute - Listen for img error events to swap broken images to fallback SVG - Check img.complete && naturalWidth === 0 on connect to catch errors that fired before the listener was attached (race condition fix) Co-Authored-By: Claude Opus 4.5 <[email protected]>
ce938a3 to
be01160
Compare
|
UX/UI Meeting Outcome: https://community.openproject.org/meetings/8147#meeting-agenda-item-23298
|
d8ff04f to
fdd9db0
Compare
|
See: Note Flickering addressed for known hosts (Gravatars) avatar-fallback-server-side.mp4 |
370680d to
6e5fab8
Compare
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.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
d515ed4 to
be01160
Compare
https://community.openproject.org/wp/69230
Server-side URL validation would add latency and can't handle relative URLs without knowing the host. Hence, we use client-side error handling:
Warning
There is a brief flicker from client-side based fallback- not sure if there's a way around this issue. One idea is switching to server-size validation, but requires the component to know about the host. As this is a fallback mechanism for broken images, I suppose this flicker is acceptable.