Skip to content

DismissEffect not working in combination with NavigationStack and await store.send(...).finish() in stack's root view #3527

@chwo

Description

@chwo

Description

In the provided sample project, the app's root view's task action, the RootFeature, appends a feature state (DetailFeature) to the navigation path on the app's NavigationStack. When pressing the DetailFeature's close button, it calls the DismissEffect. The detail view, however, doesn't get dismissed. I figured out this is because the NavigationStack's root view (HomeView) awaits the send action to finish in the task view modifier.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

The view pushed onto the NavigationStack should pop when calling dismiss.

Actual behavior

The view is not getting removed from the stack.

Reproducing project

Sample project: dismiss.zip

The dismiss is not working when using .task { await store.send(.task).finish() } in HomeView (which is the NavigationStack root view):

received action:
  RootFeature.Action.navigation(
    .path(
      .element(
        id: #0,
        action: .detail(.closeButtonTapped)
      )
    )
  )
  (No state changes)

The dismiss only works when just using .task { store.send(.task) } in HomeView.

received action:
  RootFeature.Action.navigation(
    .path(
      .element(
        id: #0,
        action: .detail(.closeButtonTapped)
      )
    )
  )
  (No state changes)

received action:
  RootFeature.Action.navigation(
    .path(
      .popFrom(id: #0)
    )
  )
  RootFeature.State(
    _navigation: NavigationFeature.State(
      _root: .home(…),
      _path: [
-       #0: .detail(
-         DetailFeature.State(
-         )
-       )
      ]
    )
  )

received action:
  RootFeature.Action.navigation(
    .root(
      .home(.task)
    )
  )
  (No state changes)

The Composable Architecture version information

1.17.0

Destination operating system

iOS 18

Xcode version information

Xcode version 16.0 (16A242d)

Swift Compiler version information

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working due to a bug in the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions