Skip to content

Stale State in Connected Views #18

@danhalliday

Description

@danhalliday

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).

func map(state: AppState, dispatch: @escaping DispatchFunction) -> Props {
    print("Latest screen:", state.diaryState.currentScreen) // Sometimes currentScreen doesn't update

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions