Repository navigation
[avatar] Fix image status edge cases - #4835
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,188.71 ms -91.66 ms(-7.2%) | Renders: 78 (+0)
13 tests within noise — details Check out the code infra dashboard for more information about this PR. |
6259b46 to
28a5958
Compare
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR addresses Avatar image-loading edge cases by improving native <img> prop forwarding and aligning the internal loading probe logic with responsive image inputs, while adding targeted regression + type coverage for the affected behaviors.
Changes:
- Forward additional native image props (
crossOrigin,referrerPolicy,srcSet,sizes) and use them consistently for both the rendered<img>and the loading-status probe. - Reset
imageLoadingStatuswhenAvatar.Imageunmounts soAvatar.Fallbackcan re-render after an image is removed. - Add regression tests and type tests covering the updated Avatar image/fallback behavior and public typing contract.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/avatar/image/useImageLoadingStatus.ts | Extends the loading probe to support responsive image inputs (srcSet, sizes) and adjusts status initialization when src is missing. |
| packages/react/src/avatar/image/AvatarImage.tsx | Uses broader element props for loading status, forwards status into root context, and resets status on unmount. |
| packages/react/src/avatar/image/AvatarImage.test.tsx | Adds JSDOM regression tests for native prop forwarding, srcSet-only rendering, probe prop usage, and onLoadingStatusChange. |
| packages/react/src/avatar/fallback/AvatarFallback.tsx | Updates delay handling to allow showing immediately when delay becomes undefined. |
| packages/react/src/avatar/fallback/AvatarFallback.test.tsx | Adds regression coverage for image unmount fallback visibility and delay prop reconciliation. |
| packages/react/src/avatar/Avatar.spec.tsx | Adds type-level assertions for ImageLoadingStatus and forwarded native <img> props. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
michaldudak
left a comment
There was a problem hiding this comment.
PR review
No merge-blocking issues found. The focused Avatar jsdom suites pass, but there is one small regression in dynamic delay behavior.
Bugs (1)
1. 🟡 Preserve visible fallback when delay is added after mount
Location: packages/react/src/avatar/fallback/AvatarFallback.tsx:23
const [delayPassed, setDelayPassed] = React.useState(false);
// ...
enabled: imageLoadingStatus !== 'loaded' && (delay === undefined || delayPassed),When Avatar.Fallback starts without a delay, the fallback is visible immediately because delay === undefined. If the prop later changes to a number, delayPassed is still false, so the fallback disappears until the timer elapses. On master, delayPassed initialized to delay === undefined, so this transition kept the already-visible fallback mounted.
Failure scenario: A controlled avatar renders fallback immediately, then a settings/state update changes delay from undefined to 600; the initials disappear for 600ms even though the image is still missing or errored.
Fix: Initialize delayPassed with delay === undefined, and add the inverse regression test for undefined -> number.
Tests (0)
No findings.
Simplifications (0)
No findings.
Docs (0)
No findings.
Verdict
Approve after nits — one non-blocking dynamic prop regression should be fixed.
dc40e44 to
bbca359
Compare
bbca359 to
13295a4
Compare
michaldudak
left a comment
There was a problem hiding this comment.
I found one non-blocking delay reconciliation bug. CI is green, and the rest of the Avatar image/status changes looked okay in this pass.
michaldudak
left a comment
There was a problem hiding this comment.
The last issue Codex found looks like a very unlikely edge case. No need to fix it IMO if it increases the bundle size.
This is part of the Codex component behavior and test coverage sweep. It fixes Avatar behavior/API issues found during review and adds focused regression coverage for the affected paths.
Root cause
Avatar had edge cases where its implementation and tests did not fully cover the expected image loading, fallback, and native image prop contract.
Changes
crossOrigin,referrerPolicy,srcSet, andsizes.Avatar.Imageunmounts so fallback can render again.Avatar.Fallbackdelay changes.Original findings addressed
Avatar.ImagedropscrossOriginandreferrerPolicyfrom the rendered<img>.srcSet/sizesare part of the native image API but loading status only looks atsrc.Avatar.Imagecan leave fallback hidden forever.Fallback.delayis one-shot state and does not reconcile prop changes.