SDWebImageSwiftUI
SDWebImageSwiftUI copied to clipboard
Xcode 14 - SwiftUI warning
If you try to run the sample app on Xcode 14 beta 5 you get the following warnings.

Getting this too :)
I'm getting identical warnings as well. Will you be able to fix them?
+1 At the same time our logs are spammed with [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.
Also seeing this - this is a genuine bug within the library because it is triggering a method from within the view body that has side effects, one of which is mutating some published state:
Specifically, WebImage
does this:
public var body: some View {
// This solve the case when WebImage created with new URL, but `onAppear` not been called, for example, some transaction indeterminate state, SwiftUI :)
if imageManager.isFirstLoad {
imageManager.load()
}
...snip...
}
I have no context as to why this change was added but it is fundamentally wrong. Side effects should not be performed from within a SwiftUI's view body - this body method can potentially called many times (every time the view's state changes). In this case, calling .load()
not only triggers a side effect, but it causes the @Published isLoading
to be mutated in the middle of the view update cycle.
+1
also having the same issue, with the bug affecting my navigationStack and moves me back to previous page, needs a fix asap, at least a workaround for now...
I noticed that the picture flickered a bit in iOS16 beta 5 🥲
I encountered a similar message in my environment.
+1
Any chance this gets fixed before iOS 16's release?
Hi.
This current repo's code, need a refactory to make it works with latest SwiftUI. And drop the usage of that ObservedObject
using StateObject
.
If someone has expert coding experience, PR is welcomed.
Currently I'm working on LLVM/Swift toolchain in this year, so may not have enough time to maintain this changes. But I'll try to back to this repo once I have some extra time.
+1
Following @lukeredpath's hint, I made some changes that seem to fix things on iOS 16.
https://github.com/SDWebImage/SDWebImageSwiftUI/compare/master...garrettrayj:ios16-undefined-behavior
I haven't tested AppKit and I bet backwards compatibility is messed up, but the changes appear mainly to be removing old workarounds that are no longer needed. Story of my life with SwiftUI, so I'm feeling confident enough to roll with 'em for the sake of getting iOS 16 updates out the door.
If you don't need backwards compatibility another option would be to see if the built in AsyncImage does what you need and have one less third party dependency in your codebase. That's my plan.
@garrettrayj - Great work - Will you make a PR? Then it can be reviewed.
I had the same error with iOS16 RC version.
This warning appears with the latest SwiftUI update but the issue impacts all SwiftUI versions. For instance, I have observed that screens that have a SDWebImage as first element are not correctly rendered in a navigation animation (i.e. when they swipe in from right to left).
Please have a try with v2.1.0
Seems to work perfectly now. Thank you!!