Closed arnauddorgans closed 6 months ago
Hi @arnauddorgans. You are reusing the exact same cancel ID for effects, which are both created and executed in the parent feature using cancelInFlight
. This means that when the second effect is created it will immediately cancel the first.
You can make the cancel IDs unique to fix things:
@Reducer
struct ChildFeature {
…
- enum CancelID {
- case fetch
+ enum CancelID: Hashable {
+ case fetch(UUID)
}
+
+ let id = UUID()
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .fetch:
state.isLoading = true
return .run { send in
…
}
- .cancellable(id: CancelID.fetch, cancelInFlight: true)
+ .cancellable(id: CancelID.fetch(self.id), cancelInFlight: true)
…
}
}
}
But I would strongly suggest moving the onAppear
to the non-optional child features instead of invoking the reducers from the parent.
Because this isn't a bug in the library, I'm going to convert to a discussion.
Description
I have an issue when a parent feature contains two child features with a cancellable effect. The cancellable effect with ID is propagated between the two child features. I made a simple app to reproduce the issue. It may be a feature, but it seems strange that a child feature can impact neighbors.
I expect both children to complete their tasks instead of canceling the other.
Checklist
main
branch of this package.Expected behavior
Both child features are loaded
Actual behavior
One child feature is cancelled
Steps to reproduce
The Composable Architecture version information
1.9.2
Destination operating system
iOS 17
Xcode version information
Xcode 15.2
Swift Compiler version information