-
In converting my code to use @ObservableState (TCA 1.7), I ran into the following runtime warning:
Setting a breakpoint in ComposableArchitecture.RootStore.threadCheck reveals that the store is being accessed from the com.apple.SwiftUI.AsyncRenderer thread. This issue was referenced in the comments for discussion #2694 on this forum, but without a solution. (Sorry if I've missed other references to the problem.) Here's some code that generates the issue. There are two Reducers and two Views. The "SquareBox" view shows a colored square and recognizes tap gestures. The "Gallery" view shows a grid of SquareBox views. Tapping on any of the boxes deletes that box from the gallery. That's it... The runtime warning is triggered when a box is deleted. Note that the tap gesture action is sent with animation. If the action is not animated, the runtime warning is not triggered.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Ah yes, sadly that conversation went over to email and I forgot to update the thread. We should document this somewhere, but the problem is with any kind of lazy view, such as the Someday in the future (once the dust settles on Swift concurrency), stores will be thread safe and this will be fine. But until then you need to eager turn your Array(store.scope(state: \.squareBoxes, action: \.squareBox)) That should fix it. |
Beta Was this translation helpful? Give feedback.
Ah yes, sadly that conversation went over to email and I forgot to update the thread.
We should document this somewhere, but the problem is with any kind of lazy view, such as the
LazyVGrid
you have in your demo. Such views apparently construct view hierarchy on non-main threads, which cause stores to be created on non-main threads (due the laziness of_StoreCollection
).Someday in the future (once the dust settles on Swift concurrency), stores will be thread safe and this will be fine. But until then you need to eager turn your
st…