-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Image Component for Blazor #63360
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
Image Component for Blazor #63360
Conversation
…eaming of variable size
This reverts commit 3e674f7.
…for loading and error styling using css data-state
…helper, use AbortController for stale stream cancelation
Initial image component is in good shape, I'll compare with ASP.NET core now
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 PR introduces a new Image component for Blazor that efficiently renders images from non-HTTP sources such as byte arrays or streams. The component provides automatic browser-side caching, streaming support with progress tracking, and proper memory management through blob URL lifecycle management.
- Implements ImageSource class for single-use image data with automatic caching
- Adds Image component with streaming JS interop and CSS-driven loading states
- Provides comprehensive test coverage including unit tests and E2E scenarios
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Components/Web/src/Image/ImageSource.cs |
Core image source model with stream and byte array constructors |
src/Components/Web/src/Image/Image.cs |
Main Image component implementation with rendering and lifecycle management |
src/Components/Web.JS/src/Rendering/BinaryImageComponent.ts |
TypeScript implementation for browser-side streaming and caching |
src/Components/Web.JS/src/GlobalExports.ts |
Exports BinaryImageComponent to global Blazor namespace |
src/Components/Web/test/Image/ImageTest.cs |
Unit tests for Image component functionality |
src/Components/test/E2ETest/Tests/ImageTest.cs |
End-to-end integration tests |
src/Components/test/testassets/BasicTestApp/ImageTest/ImageTestComponent.razor |
Test component for E2E scenarios |
src/Components/Web/src/PublicAPI.Unshipped.txt |
Public API surface additions |
src/Components/test/testassets/BasicTestApp/_Imports.razor |
Adds namespace import for test app |
src/Components/test/testassets/BasicTestApp/Index.razor |
Adds test component to navigation |
src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj |
Adds project reference |
…aspnetcore into roland/image-component
src/Components/test/testassets/BasicTestApp/ImageTest/ImageTestComponent.razor
Outdated
Show resolved
Hide resolved
javiercn
left a comment
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.
Looks great!
Have some minimal feedback on a couple things and a couple things on the tests, but other than that it looks great!
…sk.Delay from tests
|
updated |
|
I have a general question about this component. Does it support any kind of retry functionality? Sometimes when there are lots of images on the same page (say like 100), a few of them might not render properly. I was wondering if there's a mechanism that allows the component to retry fetching the image data, ideally without needing to refresh the entire page or trigger a full rerender. |
Retry is up to you. Same as if you loaded an We can't automagically retry because we don't require the stream to be seekable and we don't plan on buffering |
javiercn
left a comment
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.
Looks great!
Congrats @rolandVi on getting this done!
Image Component
Summary
This PR introduces an Image component that renders images from non-HTTP sources (bytes or streams) with streaming JS interop and optional browser-side caching.
Features
DotNetStreamReferencefor efficient streaming from .NET to JS--blazor-image-progress--blazor-image-progressfor simple progress UI.API surface
Implementation
src/Components/Web/src/Image/Image.cssrc/Components/Web/src/Image/ImageSource.cssrc/Components/Web.JS/src/Rendering/BinaryImageComponent.tssrc/Components/Web/test/Image/ImageTest.cssrc/Components/test/testassets/BasicTestApp/ImageTest/ImageTestComponent.razorsrc/Components/test/E2ETest/Tests/ImageTest.csPerformance considerations
Related to -> #25274