Effect is not correctly cancelled when calling a child action from the parent reducer #3375
Replies: 1 comment 1 reply
-
Hi @b1ackturtle, this is actually working as expected, though admittedly it's not ideal. The operators that handle all the effect cancellation logic is return Child().reduce(into: &state.childs[0], action: .refresh)
.map { [id = state.childs[0].id] in
Action.childs(.element(id: id, action: $0))
} So it shouldn't be surprising that effect cancellation isn't working correctly. Instead you could do something like this, though it is a bit ugly: return EmptyReducer()
.forEach(\.childs, action: \.childs) {
Child()
}
.reduce(into: &state.childs, action: .childs(.element(id: …, action: .refresh) Although we do largely recommend from sending actions via Also, we do have some planned updates to how reducers work that will improve these kinds of things, but what the final shape will look like is not yet known. Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there! |
Beta Was this translation helpful? Give feedback.
-
Description
When embedding child reducers in a parent reducer using
forEach
, and calling a child action from the parent reducer by invoking the child reducer directly (without using thesend
effect), the test case for the parent reducer fails because the effect in the child reducer is still running.Checklist
main
branch of this package.Expected behavior
We expect the test case in the following reproducing project to pass.
Actual behavior
The following error occurs, and the test does not pass.
Reproducing project
The implementation and test code for reproduction are as follows:
If the method of calling a child action is changed from invoking the child reducer directly to using the
send
effect, the effect in the child reducer is correctly canceled in the test case.The Composable Architecture version information
1.14.0
Destination operating system
iOS 17.5
Xcode version information
Xcode 15.4
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions