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
This commit is contained in:
DreamPiggy 2022-09-23 12:20:56 +08:00
parent 2221b4fde4
commit bf3d86b15d
1 changed files with 3 additions and 3 deletions

View File

@ -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)
}
}