-
Notifications
You must be signed in to change notification settings - Fork 0
Initial Image Component for Blazor #2
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
Conversation
…eaming of variable size
This reverts commit 3e674f7.
…for loading and error styling using css data-state
|
updated |
| try { | ||
| await reader.cancel(); | ||
| } catch { | ||
| // ignore | ||
| } |
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.
I don't think this is correct?
This is calling cancel once you've effectively read the entire stream. I think what we would want is to use an AbortController (the JS equivalent of CancellationTokenSource) to check if the source for our image changed and we need to abort reading more data, aren't we?
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.
You are right, that was incorrect.
I've implemented AbortController tracking:
- Each streamAndCreateUrl creates and tracks an AbortController per element
- When a new cache key comes in, we abort the previous controller, the signal is passed to iterateStream which cancels the reader on abort
| const chunks: Uint8Array[] = []; | ||
| let bytesRead = 0; | ||
|
|
||
| for await (const chunk of this.iterateStream(displayStream)) { | ||
| if (this.activeCacheKey.get(imgElement) !== cacheKey) { | ||
| return null; | ||
| } | ||
|
|
||
| chunks.push(chunk); | ||
| bytesRead += chunk.byteLength; |
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.
Somewhere around in this method, we need to track the cache keys that we are currently loading and trigger an abort to stop reading chunks from the stream.
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.
Instead, I trigger an abort from setImageAsync when a stream with new cache key comes in
…helper, use AbortController for stale stream cancelation
Initial Image Component for Blazor
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 - dotnet#25274