SDWebImage / SDWebImageSwiftUI

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

Fixed SwiftUI View Update error in Xcode 14.0 #238

Closed ActuallyTaylor closed 1 year ago

ActuallyTaylor commented 2 years ago

After updating to Xcode 14.0 and iOS 16 this package would spit out endless main thread warnings or "purple warnings" with the text: Publishing changes from within view updates is not allowed, this will cause undefined behavior. This request merely moves the offending code into the main thread on an asynchronous execution block.

This was tested in an iOS App running on device and in simulator that had the endless main thread errors. After the changes in this branch, all main thread errors disappeared.

dreampiggy commented 1 year ago

The published change of image and data is already on main queue. Because SDWebImageManager's callback is guranteed on the main queue.

So this fix does not make any sence. Maybe you should try provide your demo for better investigation.

ActuallyTaylor commented 1 year ago

After looking more into it, I am starting to wonder why just moving progress removed the issue. You are right that it does not make any sense why that would fix it. This may be a deeper issue in the codebase of the app and not library.

dreampiggy commented 1 year ago

why just moving progress removed the issue

The progressBlock of SDWebImage is called from global queue. The completionBlock of SDWebImage is called from main queue. These two are different and by design (progress called too frequently) :)