Skip to content

Load inline SVG sources asynchronously#504

Merged
wieslawsoltes merged 4 commits into
masterfrom
fix-issue-439-async-source
May 11, 2026
Merged

Load inline SVG sources asynchronously#504
wieslawsoltes merged 4 commits into
masterfrom
fix-issue-439-async-source

Conversation

@wieslawsoltes
Copy link
Copy Markdown
Owner

PR Summary: Async Inline SVG Source Loading

Overview

This change addresses issue #439, where assigning a large inline SVG string to
Avalonia.Svg.Skia.Svg.Source could block the UI thread while the SVG was
encoded, parsed, and converted into an SvgSource.

The issue reproduction uses a large Verovio-generated SVG. The same SVG renders
successfully through the command-line converter, which indicates that the file is
valid and that the visible problem in the Avalonia control is caused by
synchronous inline source loading on the UI thread rather than unsupported SVG
content.

Changes

  • Inline Source values are now loaded asynchronously.
  • Source parsing work is moved off the UI thread with Task.Run.
  • The UI thread only applies the completed SvgSource after parsing finishes.
  • Stale inline loads are ignored when a newer source or path load supersedes
    them.
  • Stale successfully parsed sources are disposed when they are no longer current.
  • Path-based loads now cancel any pending inline source load before replacing
    the current source.
  • Render option application was centralized so cached, path-based, and inline
    sources use the same Wireframe and DisableFilters behavior.
  • Async inline source completion applies the control's current render options,
    so changes made while a large source is still parsing are preserved.

Tests

New control tests cover:

  • Loading an inline SVG source asynchronously.
  • Ensuring the most recent inline SVG wins when Source is assigned repeatedly.
  • Applying current render options when an async inline source load completes.

Validation

The issue attachment was downloaded and rendered through
Svg.Skia.Converter, producing a PNG successfully in about five seconds. This
confirmed that the attached SVG content can be parsed and rendered by the
library.

Commands run locally:

  • dotnet format Svg.Skia.slnx --no-restore
  • dotnet format tests/Svg.Controls.Skia.Avalonia.UnitTests/Svg.Controls.Skia.Avalonia.UnitTests.csproj --no-restore
  • git diff --check
  • dotnet build src/Svg.Controls.Skia.Avalonia/Svg.Controls.Skia.Avalonia.csproj -c Release --no-restore
  • dotnet test tests/Svg.Controls.Skia.Avalonia.UnitTests/Svg.Controls.Skia.Avalonia.UnitTests.csproj -c Release --no-restore --filter FullyQualifiedName~SvgControlTests
  • dotnet test tests/Svg.Controls.Skia.Avalonia.UnitTests/Svg.Controls.Skia.Avalonia.UnitTests.csproj -c Release --no-restore

Notes

The full solution build and full solution test suite were not rerun after the
final small render-options adjustment. The touched control project and its test
project were built and tested successfully.

@wieslawsoltes wieslawsoltes marked this pull request as ready for review May 10, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant