SDWebImageSwiftUI icon indicating copy to clipboard operation
SDWebImageSwiftUI copied to clipboard

Xcode 14 - SwiftUI warning

Open guidev opened this issue 2 years ago • 1 comments

If you try to run the sample app on Xcode 14 beta 5 you get the following warnings. Screenshot 2022-08-09 at 18 38 52

guidev avatar Aug 09 '22 16:08 guidev

Screenshot 2022-08-09 at 18 45 56

guidev avatar Aug 09 '22 16:08 guidev

Getting this too :)

Alex-Coetzee avatar Aug 15 '22 14:08 Alex-Coetzee

I'm getting identical warnings as well. Will you be able to fix them?

ivankodrnja avatar Aug 15 '22 17:08 ivankodrnja

+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.

Teglgaard avatar Aug 19 '22 08:08 Teglgaard

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.

lukeredpath avatar Aug 19 '22 12:08 lukeredpath

+1

BugMonkey avatar Aug 29 '22 09:08 BugMonkey

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...

RMehdid avatar Aug 30 '22 13:08 RMehdid

I noticed that the picture flickered a bit in iOS16 beta 5 🥲

BugMonkey avatar Aug 31 '22 02:08 BugMonkey

I encountered a similar message in my environment. image

tichise avatar Aug 31 '22 02:08 tichise

+1

yoshirozay avatar Sep 01 '22 18:09 yoshirozay

Any chance this gets fixed before iOS 16's release?

frlefebvre avatar Sep 02 '22 22:09 frlefebvre

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.

dreampiggy avatar Sep 05 '22 03:09 dreampiggy

+1

Sri2611 avatar Sep 05 '22 07:09 Sri2611

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.

garrettrayj avatar Sep 05 '22 11:09 garrettrayj

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.

lukeredpath avatar Sep 05 '22 12:09 lukeredpath

@garrettrayj - Great work - Will you make a PR? Then it can be reviewed.

Teglgaard avatar Sep 05 '22 12:09 Teglgaard

I had the same error with iOS16 RC version.

tichise avatar Sep 08 '22 06:09 tichise

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).

Jeyhey avatar Sep 15 '22 10:09 Jeyhey

Please have a try with v2.1.0

dreampiggy avatar Sep 15 '22 13:09 dreampiggy

Seems to work perfectly now. Thank you!!

Jeyhey avatar Sep 15 '22 21:09 Jeyhey