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

Xcode 14 warning on view update #243

Open nrigoni22 opened 1 year ago

nrigoni22 commented 1 year ago

From update to Xcode 14 and 14.1 I have some mornings that points in the ImageManager.swift all says: Publishing changes from within view updates is not allowed, this will cause undefined behavior.

how can be solved?

venkat-epifi commented 1 year ago

Any update on this. I too facing this issue.

ngoan commented 1 year ago

I'm having the same issue.

dreampiggy commented 1 year ago

This can not been fixed, unless I remove iOS 13 support with SwiftUI.StateObject (not that Compatibility.StateObject)

DJBen commented 1 year ago

Do you have an idea what is the root problem? I think we might be able to fork the dependency and temporarily fix them ourselves.

dreampiggy commented 1 year ago

The root of this problem is because the SDWebImage Core's design, when query memory cache, it callback in sync (which means, just like a normal non-async function call), and trigger the ImageManager.image update

The ImageManager.load(url:) API is called inside View.body, and SwiftUI prohibit the changes in sync during View.body call.

abinhho commented 1 year ago

Just add “Dispatch.main.asyn {}” to warning places will fix the issue.

sifuentes0408 commented 1 year ago

Hi, just wondering if this is planned to be fixed any time soon. I use image loader heavily on my app and this causes thousands of warnings.

DJBen commented 1 year ago

Kingfisher also has a similar SwiftUI view called KFImage. In the meantime, we can substitute this framework with Kingfisher.

sifuentes0408 commented 1 year ago

Just noticed AsyncImage is pretty great on SwiftUI, I'm probably using that now.

dreampiggy commented 1 year ago

I have no extra time on iOS 13 backport. I think this is because of the @StateObject.

Drop iOS 13 support, please try with this to see the result:https://github.com/SDWebImage/SDWebImageSwiftUI/pull/250

zhuiyizhiqiu commented 1 year ago

I had the same problem, [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.

coucoseth commented 9 months ago

what is the solution because i have the same problem now

romrell4 commented 8 months ago

Any updates on this one? Seems like the WebImage might just need to be made a main actor, or the ImageManager needs to declare some MainActor usages in it's asynchronous portions?

Update: Doesn't seem to be that simple. Tried that and still have issues