-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stale State in Connected Views #18
Comments
This does in fact seem to be down to SwiftUI’s coalescing of updates. Getting rid of the following async dispatch in the public func dispatch(action: Action) {
// DispatchQueue.main.async {
self.dispatchFunction(action)
// }
} During an action update, I see the Still not exactly sure on the root cause but the fix seems reliable. Also FWIW my view navigation feels snappier after removing the async dispatch. Perhaps previously that was causing SwiftUI’s change coalescing mechanism or its animation system to thrash? |
@Dimillian was the rationale behind the Flagging the public func dispatch(action: Action) {
DispatchQueue.main.async {
self.objectWillChange.send()
self.dispatchFunction(action)
}
} |
I have the same problem but cannot figure out exactly why. |
I’m seeing stale states sometimes in connected views. Can’t figure it out — have removed all middleware. It looks like after an action is processed and the state is updated,
map(state:dispatch:)
is called with the old state. But only sometimes (perhaps 20% of the time).I would happily dig into this or submit a PR but I’m stumped. The
Store
implementation looks straightforward. I can’t produce a reduced test case but at the same time there’s nothing unusual about the project I’m seeing the issue in.Adding in an additional
DispatchQueue.main.async {}
into a new middleware fixes it most of the time but not always. I guess it has to be something to do with how SwiftUI is coalescing updates to the@Published public var state: StoreState
store property.The text was updated successfully, but these errors were encountered: