Skip to content

fix(SvgImageSource): Keep the load alive when an Image subscribes mid-open - #25166

Merged
MartinZikmund merged 2 commits into
masterfrom
dev/mazi/svg-image-source
Oct 11, 2026
Merged

MartinZikmund merged 2 commits into
masterfrom
dev/mazi/svg-image-source

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: n/a (found during Uno 7 QA of a real app)

PR Type

🐞 Bugfix

What is the current behavior? 🤔

An Image whose Source is an SvgImageSource that is still opening never renders: nothing is drawn and neither Opened nor OpenFailed fires. Typical trigger: <Image Source="ms-appx:///Assets/logo.svg" /> in a page created after startup (seen on Daily Plants' About page with Uno.Sdk 7.0.0-dev.54; renders on Uno 6.7 and on WinUI).

Root cause:

  • Setting UriSource calls InvalidateSource(), which opens an SvgImageSource even without subscribers.
  • Image.OnSourceChanged subscribes right away; the first Subscribe() calls Open() again, and _opening.Disposable = … cancels the first open's token.
  • SvgImageSource.TryOpenSvgImageData cached the load with _currentOpenTask ??= LoadSvgImageAsync(ct), bound to that first token. The re-open reuses a load that observes cancellation and returns ImageData.Empty silently.
  • It only bites when the first read is still pending at subscribe time (async ms-appx reads in apps, http). When the read completes synchronously (SamplesApp assets) it's masked, which is why the existing When_SVGImageSource rows never caught it.

Regressed in e9801ce (refactor(svg): unify on ISvgRenderer…), which made Image subscribe to SVG sources.

What is the new behavior? 🚀

The SVG load is owned by the source with its own CancellationTokenSource, cancelled only in UnloadImageSourceData, i.e. when the source itself changes. A superseded open reuses the in-flight load. A load aborted by a source change returns empty without raising OpenFailed.

WinUI alignment: a decode is aborted only by DisconnectImageOperation, reached from OnUriSourceChange / SetSource (dxaml/xcp/core/core/elements/imagesource.cpp), never because an Image attached.

Tests

New Given_Image.When_SVGImageSource_Assigned_While_Opening serves the SVG from a loopback TcpListener that answers after 200 ms, so the first open is deterministically in flight when the Image subscribes (excluded on WASM: no sockets).

  • Without the fix: fails (the client cancels the in-flight request).
  • With the fix: Given_Image 35/35 pass on Skia desktop (net10.0-desktop, Win32), incl. all existing SVG tests.
  • Real app: with the fixed Uno.UI / Uno.UI.Svg / Uno.UI.Composition* the About logo renders (lastStatus=Success).

Note: the final test tweak (stub server tolerating the aborted client + a WaitFor message) was not re-run locally because the machine ran out of memory; CI will cover it.

PR Checklist

  • Tested code with current supported SDKs
  • Runtime tests added
  • Docs: n/a

🤖 Generated with Claude Code

https://claude.ai/code/session_01LP133TsLEXjMo7XFGmakoS

MartinZikmund and others added 2 commits October 10, 2026 09:10
…-open

Setting UriSource opens the source right away, and the first Image.Subscribe
re-opens it, cancelling the first open's token. The cached load was bound to
that token, so the re-open reused a load that returned empty: nothing
rendered and neither Opened nor OpenFailed fired.

The load now has its own cancellation, cancelled only when the source itself
changes, like WinUI's DisconnectImageOperation (imagesource.cpp).

Regressed in e9801ce, which made Image subscribe to SVG sources.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LP133TsLEXjMo7XFGmakoS
Copilot AI balanced review requested due to automatic review settings October 10, 2026 07:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 17s —— View job


Review of #25166

Verdict: ship. No blocking issues, 0 inline findings.

What I checked (code review only, nothing built or run):

  • Root cause: the fix targets it. The shared _currentOpenTask is no longer bound to the first open's token. The source now owns _loadCts, which is cancelled only in UnloadImageSourceData, so a superseded open reuses the in-flight load.
  • Cancellation: Cancel() followed by Dispose() and nulling the fields is safe. The running load only observes ct.IsCancellationRequested, so disposal after cancel doesn't cause trouble.
  • Aborted loads: the new ct.IsCancellationRequested early return avoids a spurious OpenFailed when the source changes mid-read. It also avoids publishing stale data.
  • Tradeoff: an Image that unloads or unsubscribes no longer aborts the read. The load now runs to completion and its result is cached, which matches the WinUI behavior described in the PR.

Notes (non-blocking):

  • The ct parameter of TryOpenSourceAsync is now unused for SVG loading. That's fine given the override signature.
  • The PR says the final test tweak (the stub server tolerating an aborted client) wasn't re-run locally, so CI is the real validation for the new runtime test. I couldn't confirm it passes. The test is excluded on WASM, and that is stated openly.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238747 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1146

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • DisplayInformation.png-dark
    • DoubleImageBrushInList.png-dark
    • Examples.png
    • DoubleImageBrushInList.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ImageBrushAlignmentXY.png-dark
  • skia-windows-screenshots: 1146 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutoBorderStretchwithrightmargin.png
    • AutoSuggestBox_Icons.png-dark
    • AutoSuggestBox_Icons.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • Border_CornerRadius_Gradient.png-dark
    • Border_CornerRadius_Gradient.png
    • Button_IsEnabled_Automated.png-dark
    • Button_IsEnabled_Automated.png
    • Button_Opacity_Automated.png-dark
    • Button_Opacity_Automated.png
    • ClippingWithOpacity.png-dark
    • ClippingWithOpacity.png
    • ComboBox_Stretch.png-dark
    • ComboBox_Stretch.png
    • Contacts_Pick.png-dark
    • Contacts_Pick.png
    • ContentPresenter_NativeEmbedding_ZIndex.png-dark

@MartinZikmund MartinZikmund added the 7.0 PRs only. For issues, use the Release field. label Oct 11, 2026
@MartinZikmund
MartinZikmund merged commit 951b7b4 into master Oct 11, 2026
51 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/svg-image-source branch October 11, 2026 17:50
mikernet added a commit to Singulink/uno that referenced this pull request Oct 17, 2026
Port of unoplatform#25555 (43b47f5), the 6.8 backport of
unoplatform#25166.

On Skia, SetSourceAsync(stream) returned Other and drew nothing, and
neither Opened nor OpenFailed fired, whether Image.Source was set before
or after the call. SetSourceAsync subscribes to the source, which opens
it, then calls InvalidateSource, which opens it again and cancels the
first open's token, and the cached load was bound to that token. An
ImageBrush that subscribes while a UriSource is still loading re-opens
it the same way.
- The load has its own cancellation, cancelled only when the source
  itself changes (UnloadImageSourceData), as on master and as in WinUI,
  where only DisconnectImageOperation aborts a decode.
- Tests: When_SVGImageSource_SetSourceAsync_File_Stream,
  When_SVGImageSource_SetSourceAsync_Twice (Given_Image) and
  When_SvgImageSource_Assigned_While_Opening (Given_ImageBrush).

6.8 differences:
- None: unoplatform#25555 targets servicing/6.8 and cherry-picks clean, also on top
  of the unoplatform#25124 port. That port leaves an SvgImageSource's data alone
  while nothing subscribes, so the load this keeps alive is not released
  under it.
Xiaoy312 pushed a commit to mikernet/uno that referenced this pull request Nov 6, 2026
On Skia, SetSourceAsync(stream) returned Other and drew nothing, and
neither Opened nor OpenFailed fired, whether Image.Source was set
before or after the call.

SetSourceAsync subscribes to the source, which opens it, then calls
InvalidateSource, which opens it again and cancels the first open's
token. The load is cached in _currentOpenTask and was bound to that
first token, so the second open reused a load whose stream read had
been cancelled. An ImageBrush that subscribes to an SvgImageSource
whose UriSource is still loading re-opens it the same way.

The load now has its own cancellation, cancelled only when the source
itself changes (UnloadImageSourceData), as on master since unoplatform#25166 and
as in WinUI, where only DisconnectImageOperation aborts a decode.
MartinZikmund pushed a commit that referenced this pull request Nov 24, 2026
SetSourceAsync subscribes to the source, which opens it, then calls
InvalidateSource, which opens it again and cancels the first open's
token. #25166 made the SVG load independent of that token, which also
fixed stream loading, but only the URI path has a test.

These load a file stream, whose read is still in flight when the source
is opened again, with Image.Source set before and after the call, and
call SetSourceAsync twice on the same source. Each checks the returned
status and the drawn color; the first also waits for Opened.

The same tests pass on WinUI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants