Replies: 1 comment
-
This behavior is to be expected, since reducers pass the entire value as Also, please note that we recommend using
This appears to be a vanilla bug. I can swap out the store for a model and reproduce just fine: @Observable class Model {
var text = ""
func send() {
text = text
}
}
struct InfiniteBugView: View {
let model = Model()
var body: some View {
ZStack {
Text("foo: \(model.text)")
}
.fullScreenCover(isPresented: .constant(true)) {
NavigationStack {
Form {
Text("foo: \(model.text)")
.sheet(isPresented: Binding(
get: { true },
set: { _ in }
)) {
NavigationStack {
ZStack {
Form {
Text(":: \(model.text)")
}
.sheet(isPresented: .constant(true)) {
Text("Leaf")
.onAppear {
print("onAppear", Date())
model.send()
}
}
}
}
}
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
When Scoping to a property annotated with @shared, every action sent to the store triggers a re-render of SwiftUI-views.
The symptoms of this bug are similar to #3163 but the underlying problems seem separate.
Checklist
main
branch of this package.Expected behavior
When sending an action to a store that does not update the state, a SwiftUI-view should not be re-rendered.
Actual behavior
The SwiftUI-view is re-rendered for every action.
Steps to reproduce
Consider the following feature and view:
Every press on the Button triggers a view update.
This is what I found debugging this issue
If a store is scoped to a shared-property, then it is passed as inout-parameter to the reducer closure. This necessarily triggers the setter of the Shared-struct, no matter whether the state was actually changed. This in turn triggers the setter of the underlying ValueReference which calls
willSet
anddidSet
of the perception registrar.Bonus
In the following code, this bug actually triggers an infinite rerender-loop in SwiftUI:
The Composable Architecture version information
1.11.1
Destination operating system
iOS 17.5
Xcode version information
Version 15.4 (15F31d)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions