SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.1k stars 216 forks source link

Fix the nil url always returns Error will cause infinity `onAppear` call and image manager to load, which waste CPU #235

Closed dreampiggy closed 1 year ago

dreampiggy commented 1 year ago

closing #234

Background

This is because the fixed-point logic driver by SwiftUI, will recursivelly trigger placeholder's onAppear (because v2.2.0 use UUID as ID for placeholder), and trigger the ImageManager to load and always failed immediately, trigger another else condition in View.body, and another setupPlaceholder && ImageManager load, finally may consuming CPU because it's un-ended.

This fix use the URL as ID, if the nil url is provided, only one onAppear will trigger, so it's end.

Tips

Also, I think the nil URL design is a bad design for SwiftUI, but good design for UIKit.

Although it's introduced from #2 , may removed in the future