pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.35k stars 1.44k forks source link

CaseStudies(SwiftUI) crash using the NavigationStackStore in the example app. #2399

Closed kakalamudo closed 1 year ago

kakalamudo commented 1 year ago

Description

Hey team I am in the middle of migrating a TCA app to use the new NavigationStack/NavigationStackStore apis and I took a look at the NavigationDemo (Stack) case study in the case studies app and noticed some weird behaviour and I am attaching video below.

Firstly when "Stack" is tapped on the List we see the NavigationDemo view get pushed and popped off the stack immediately which is unexpected. Also tapping on one of the destinations doesn't actually do the navigation instead we see the destination reflected in the back button title. Finally if you tap on the back button, we should be taken to the RootView instead of the destination we previously tapped and tapping on the back button again results in the following fatal error crash:

Swift/RangeReplaceableCollection.swift:902: Fatal error: Can't remove more items from a collection than it contains 2023-08-22 10:43:46.717655-0700 SwiftUICaseStudies[5421:60315599] Swift/RangeReplaceableCollection.swift:902: Fatal error: Can't remove more items from a collection than it contains Simulator Screen Recording - iPhone 14 Pro - 2023-08-22 at 10.56.51.mp4.zip

Checklist

Expected behavior

Tapping on "Stack" should push the NavigationDemoView onto the stack and not pop it back automatically. Tapping on "Go to Screen A" should push Screen A onto the stack and we should be able to see that view instead of the root view, the back button title should read "Screen A" since we are already there. Tapping on the back button should bring us back to the RootView and a subsequent tap on the back button should bring us back to the CaseStudies list without crashing.

Actual behavior

Firstly when "Stack" is tapped on the List we see the NavigationDemo view get pushed and popped off the stack immediately which is unexpected. Also tapping on one of the destinations doesn't actually do the navigation instead we see the destination reflected in the back button title. Finally if you tap on the back button, we should be taken to the RootView instead of the destination we previously tapped and tapping on the back button again results in the following fatal error crash:

Swift/RangeReplaceableCollection.swift:902: Fatal error: Can't remove more items from a collection than it contains 2023-08-22 10:43:46.717655-0700 SwiftUICaseStudies[5421:60315599] Swift/RangeReplaceableCollection.swift:902: Fatal error: Can't remove more items from a collection than it contains.

Steps to reproduce

  1. Run the CaseStudies(SwiftUI) app
  2. Scroll to the Navigation section.
  3. Tap on "Stack".
  4. Tap on "Go to Screen A"
  5. Tap on the back button "< Screen A"
  6. Tap on the back button "< Case Studies"

The Composable Architecture version information

f62ba37cc0c51acb89f6dd1f552f6a1f9c58027c

Destination operating system

iOS 16.4

Xcode version information

Version 14.3 (14E222b)

Swift Compiler version information

swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
filblue commented 1 year ago

Duplicates https://github.com/pointfreeco/swift-composable-architecture/issues/2396

stephencelis commented 1 year ago

Fixed by #2397 :smile: