IdentifiedArrayOf does not work correctly with @ObservableState #79
Replies: 3 comments
-
@alexataman Can you attach a project that reproduces the problem? You've posted code snippets with sections omitted, and the fewer steps we have to take to reproduce the better chance we can look into the issue and address it. |
Beta Was this translation helpful? Give feedback.
-
@stephencelis Sure! Here is the project that reproduces the issue. The project was created on macOS 14.6.1 (23G93) using Xcode Version 16.0 (16A242d) and the main branch of TCA, commit fc5cbeec88114ff987f6c3cad3a7f3a3713fdb56. |
Beta Was this translation helpful? Give feedback.
-
@alexataman You're using an unsafe var body: some Scene {
DocumentGroup(newDocument: CrashDocument()) { configuration in
let documentModel = configuration.document.documentModel!
if let docStore = store.scope(
state: \.document[id: documentModel.id],
action: \.document[id: documentModel.id]
) {
DocumentView(
store: docStore
)
.onDisappear {
store.send(.windowWasClosed(documentModel))
}
} else {
Text("Loading...")
.onAppear {
store.send(.windowWasOpened(documentModel))
}
}
}
} Because this isn't a bug with the library I'm going to convert this issue to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Description
Hi there!
I’m encountering an issue when using IdentifiedArrayOf with @ObservableState. My project maintains an IdentifiedArrayOf to manage the state, and I have two main actions:
Here are the actions:
My State:
DocumentReducer State:
Screenshot:
Can you help identify the root cause of this issue?
Checklist
main
branch of this package.Expected behavior
When removing the state from the IdentifiedArrayOf, it should correctly clean up without causing crashes or referencing deleted state.
Actual behavior
When I add a new state to the array, everything works as expected. However, when I remove the state from the IdentifiedArrayOf, it causes a crash inside the PartialToState enum. It seems that @ObservableState and IdentifiedArrayOf do not work well together when performing deletions.
Steps to reproduce
IdentifiedArrayOf.
Identified Collections version information
No response
Destination operating system
macOS 14.3.1 (23D60)
Xcode version information
Version 15.3
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions