pointfreeco/swift-composable-architecture

Nesting a Cased reducer > Tabbed reducer > Navigation Stack > `navigationDestination(item:destination:)` breaks navigating to the same item twice.

autoreleasefool opened this issue · 2 comments

Description

Currently following the 1.7 Migration Guide and having an issue with navigationDestination(item:destination:).

My app supports iOS 16, and so I'm using the Perception tools. This happens on iOS 17.

My app's set up is that the root reducer uses a switch / case to switch between the onboarding and the tab view, there are a number of tabs, each with a navigation stack, etc.

Within this hierarchy, the reducer within the tab presents a leaf state on a button press through navigationDestinationWrapper(item:destination:) (using the wrapper suggested in the migration)

Tapping the button once navigates, then pressing back and navigating again does not navigate forward.

If you remove the Switching reducer or the Tabbed reducer/view from the hierarchy, it works as expected

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

Pushing and popping the view should always work.

In my example, tapping First Child, dismissing, then First Child again, the view will not navigate the second time.

Actual behavior

The view is pushed on the first attempt, and won't get pushed again on subsequent attempts.

In my example, if you tap First Child, dismissing, then Second Child, dismissing, then First Child again, everything works as expected,

Steps to reproduce

A basic repro

The Composable Architecture version information

1.7.2

Destination operating system

iOS 17

Xcode version information

Xcode 15.2

Swift Compiler version information

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Hi @autoreleasefool, thanks for the report. It seems to be a problem with doing if #available in the body of navigationDestinationWrapper. That introduces an AnyView, and somehow that causes the problem when deploying to iOS 16 and running on an iOS 17 device. No idea how!

But we do have a fix for it, so just update your navigationDestinationWrapper as described here #2765.

@mbrandonw Thanks for the quick fix! This did indeed resolve the issue I was having!