enhance ImageWithFallback with retry, accessibility, loading, and tests#216
Merged
Merged
Conversation
Contributor
|
the retry, accessibility, and loading improvements to ImageWithFallback plus the tests are a great robustness upgrade. rebased on latest main and dropped one unused import to keep the typecheck clean. thanks! |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enhances the Figma
ImageWithFallbackcomponent with improved accessibility, performance options, security compliance, and robust error-handling retry capabilities. It also adds a comprehensive suite of unit tests, achieving 100% test coverage.Key Improvements
1. Robust Retry Logic
?retry=1or&retry=1) is automatically appended on the first failure to guarantee the browser initiates a new network request instead of reusing cached error states.hasErrorandretryCount) is automatically reset when thesrcprop changes.2. Enhanced Accessibility
aria-label="Error loading image".alttext (alt="Image") when the prop is omitted to prevent screen readers from skipping the image or announcing missing alt tags.3. Performance Boost
loading="lazy"by default on normal image renders.loadingbehavior via props (e.g.,loading="eager").4. DOM Exposure Security
data-original-urlattribute from the fallback image tag. Once the component switches to the fallback state, the original (possibly unsafe/private) source URL is completely unmounted and no longer exposed anywhere in the DOM.5. High-Coverage Unit Tests
Created
src/app/components/figma/ImageWithFallback.test.tsxcovering all execution paths:loading="eager")onLoadcallback firingsrcexposed in DOM during fallback)srcchangesVerification Results
Unit Tests
Ran Vitest checks: