Closed watt closed 7 months ago
Hi @watt, I'm not sure there is going to be much we can do to fix this. Who knows why SwiftUI's bindings are special. We'll try to find some time to investigate more, but in the meantime please do share if you uncover anything.
Sure thing. I've done some experiments while adding SwiftUI support to Workflow, and had success avoiding this by caching bindings. I'll follow up when I can provide a more concrete example of that.
@watt We have a fix for this and will be PR'ing it soon.
Description
It seems that SwiftUI does not consider bindings created from
@Perception.Bindable
to be equivalent across updates in the same way as bindings created from@SwiftUI.Bindable
. Consider this example:This view has a counter that can be incremented, and a toggle bound to a bool. Ideally, updates to
count
andisOn
can be tracked independently. But it seems that whencount
is incremented by tapping the button, the binding toisOn
changes as well, and we see it reported in the log:When replacing
@Perception.Bindable
with@SwiftUI.Bindable
theToggleView
body is no longer evaluated on each button press.Checklist
@Observable
macro or another tool from theObservation
framework, please file it directly with Apple.main
branch of this package.Expected behavior
When tapping "Increment", the
ToggleView
is not re-evaluated.Actual behavior
When tapping "Increment", the
ToggleView
is re-evaluated.Steps to reproduce
Run the example in the description in an app or preview, and tap the "Increment" button.
Perception version information
main
Destination operating system
iOS 17
Xcode version information
Version 15.1 (15C65)
Swift Compiler version information