Skip to content

[flutter_svg] Evict failed pending loads and avoid unhandled cache errors - #13613

Open
deandreamatias wants to merge 1 commit into
flutter:mainfrom
deandreamatias:fix/flutter-svg-pending-cache-error
Open

deandreamatias wants to merge 1 commit into
flutter:mainfrom
deandreamatias:fix/flutter-svg-pending-cache-error

Conversation

@deandreamatias

Copy link
Copy Markdown

Fixes flutter/flutter#196285

A transient network failure in SvgPicture.network (for example, an http.ClientException) can escape from a derived future in Cache.putIfAbsent and reach PlatformDispatcher.onError. The widget's errorBuilder runs, but it does not expose the escaped future, so applications cannot catch it and Crashlytics may record it as a fatal error.

Handle errors on the derived future and evict the failed pending entry, allowing later calls for the same key to retry. The error handler does not swallow the caller's error: the future returned by putIfAbsent still completes with the original error.

Add a regression test that verifies the original error reaches the caller and a subsequent load for the same key is retried.

Related: dnfield/flutter_svg#881
Related PR: dnfield/flutter_svg#1104

Validation

  • dart format lib test
  • flutter analyze (no issues)
  • flutter test test/cache_test.dart (all tests passed)

@github-actions github-actions Bot added p: flutter_svg triage-engine Should be looked at in engine triage labels Nov 10, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request modifies the Cache class in flutter_svg to handle loader failures by adding an onError handler to the pending loader future. This ensures that a failed loader is evicted from the pending map, allowing subsequent retries, and verifies that the pending loader is identical to the current pending result before removal. A unit test has been added to verify this behavior. There are no review comments, and I have no feedback to provide.

auto-submit Bot pushed a commit that referenced this pull request Nov 11, 2026
…3595)

Rebased on current main (`8041ccab1`), preserving the failed-load fix and its regression test from #13604. This PR adds invalidation of pending loads on `Cache.clear` and `Cache.evict`: an obsolete completion cannot repopulate the cache or remove a replacement request, even when loaders reuse the same Future.

Documents pending-load invalidation on both methods. The cache lifecycle tests live in `cache_test.dart`. The shared-Future regression checks that an evicted request does not populate the cache before the replacement's completion callback runs. Preserves synchronous cache hits, coalescing and entry-count LRU. Bumps the package to 2.3.4 with a changelog entry.

Related: flutter/flutter#182486 (failed-load cleanup is already on main via #13604).

Validation on Windows: `flutter analyze` clean; full `flutter test` suite: 77 passed, 1 existing skip; formatting and `git diff --check` passed. No golden files changed.

Overlapping proposals: #13613 also concerns failed pending loads; main already includes #13604. This PR retains that fix and focuses on clear/evict invalidation. #13596 is stacked on this branch and was rebased with it.

## Pre-Review Checklist

This draft was prepared with AI assistance and remains pending the contributor's human review and confirmation of the unchecked checklist items.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: flutter_svg triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_svg] Failed pending cache loads escape as unhandled errors and prevent retries

1 participant