Try to refactor the ImageManager trigger published value, avoiding the View will refreshing when deallocing
This may solve #176
The callstack trace shows that UIHostingView's dealloc method will trigger the View's onDisappear method. And it use the unownded but not weak for the internal storage. If we trigger another body refreshing call from the Publisher (in the #176 is because of the ImageManager.isLoading property), this will cause the crash because the internal storage already been destroyed.
Instead, I try to avoid setting isLoading inside cancel. Tthis property is previouslly used to supports the delayPlaceholder feature.
delayPlaceholder in SDWebImage means:
- If the loading has never started, only show the indicator (if available) but not placeholder.
- If first loading failed, show the placeholder and disappear the indicator (if available)
So, instead I use the error to check whether there are loading failure. This can keep this function as well.
Try using the demo code, function works as expected.

Codecov Report
Merging #180 (d175c0d) into master (cd8625b) will increase coverage by
0.20%. The diff coverage is50.00%.
@@ Coverage Diff @@
## master #180 +/- ##
==========================================
+ Coverage 74.81% 75.02% +0.20%
==========================================
Files 11 11
Lines 969 965 -4
==========================================
- Hits 725 724 -1
+ Misses 244 241 -3
| Flag | Coverage Δ | |
|---|---|---|
| ios | 71.11% <50.00%> (+0.20%) |
:arrow_up: |
| macos | 75.77% <50.00%> (+0.23%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| SDWebImageSwiftUI/Classes/WebImage.swift | 87.97% <20.00%> (-1.47%) |
:arrow_down: |
| SDWebImageSwiftUI/Classes/ImageManager.swift | 84.00% <100.00%> (+8.56%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update cd8625b...d175c0d. Read the comment docs.