From bf3d86b15d8a1f4b10341208ef07e46e240a4d06 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 23 Sep 2022 12:20:56 +0800 Subject: [PATCH] Fix the nil url always returns Error will cause infinity `onAppear` call and image manager to load, which waste CPU Instead, use url as identity to avoid this --- SDWebImageSwiftUI/Classes/WebImage.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 5e8f0bc9..680a4969 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -264,9 +264,9 @@ public struct WebImage : View { } else { result = AnyView(configure(image: .empty)) } - // UUID to avoid SwiftUI engine cache the status, and does not call `onAppear` when placeholder not changed (See `ContentView.swift/ContentView2` case) - // Because we load the image url in `onAppear`, it should be called to sync with state changes :) - return result.id(UUID()) + // Custom ID to avoid SwiftUI engine cache the status, and does not call `onAppear` when placeholder not changed (See `ContentView.swift/ContentView2` case) + // Because we load the image url in placeholder's `onAppear`, it should be called to sync with state changes :) + return result.id(imageModel.url) } }