Replies: 1 comment 2 replies
-
Hi @ysmaliak, your code is problematic because you are creating a store directly in a view's body: @main
struct ComposableArchitectureSharingTestApp: App {
var body: some Scene {
WindowGroup {
AppView(store: Store(initialState: AppFeature.State(), reducer: { AppFeature() }))
}
}
} You should never do this because if the view ever recomputes its body it will recreate the store, thus recreating state from scratch and discarding any in flight effects. It is better to create the store one single time for the app: @main
struct ComposableArchitectureSharingTestApp: App {
static let store = Store(initialState: AppFeature.State(), reducer: { AppFeature() })
var body: some Scene {
WindowGroup {
AppView(store: Self.store)
}
}
} The reason this behavior may have slightly changed in 1.16 vs 1.17 is that 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
Updating the file storage shared property results in unexpected state changes. The issue was introduced in
1.17.0
and did not occur in1.16.1
.Checklist
main
branch of this package.Expected behavior
Changes to shared property should not affect other state properties.
There are 2 arrays of data:
dummies
andstrings
, which are presented as lists. Ondummies
update, thestrings
should not be affected.Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-12-15.at.19.47.03.mp4
Actual behavior
Changes to shared property affect other state properties.
String generation continues, but it's no longer published to view. The
strings
list on the view is reset to an empty state.Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-12-15.at.19.48.30.mp4
Reproducing project
https://github.com/ysmaliak/ComposableArchitectureSharingTest
There are 4 branches:
main
(uses themain
branch of theswift-composable-architecture
, issue reproducible)composable-architecture-1.17.0
(uses version1.17.0
of theswift-composable-architecture
, issue reproducible)composable-architecture-1.16.1
(uses version1.16.1
of theswift-composable-architecture
, issue not reproducible)pure-swiftui
(uses version1.1.0
of theswift-sharing
withoutswift-composable-architecture
, issue not reproducible)The Composable Architecture version information
1.17.0
Destination operating system
iOS 18.1
Xcode version information
16.1
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions