Closed benlings closed 1 year ago
It looks like this can be fixed with the following patch to TCA:
diff --git a/Sources/ComposableArchitecture/SwiftUI/NavigationStackStore.swift b/Sources/ComposableArchitecture/SwiftUI/NavigationStackStore.swift
index c417abedb..2ca2fbe57 100644
--- a/Sources/ComposableArchitecture/SwiftUI/NavigationStackStore.swift
+++ b/Sources/ComposableArchitecture/SwiftUI/NavigationStackStore.swift
@@ -105,9 +105,7 @@ public struct NavigationStackStore<State, Action, Root: View, Destination: View>
self.root
.environment(\.navigationDestinationType, State.self)
.navigationDestination(for: Component<State>.self) { component in
- self.destination(component)
- .environment(\.navigationDestinationType, State.self)
- .id(component.id)
+ NavigationDestinationView(component: component, destination: self.destination)
}
}
}
@@ -144,6 +142,16 @@ public struct _NavigationLinkStoreContent<State, Label: View>: View {
}
}
+private struct NavigationDestinationView<State, Destination: View>: View {
+ let component: Component<State>
+ let destination: (Component<State>) -> Destination
+ var body: some View {
+ self.destination(component)
+ .environment(\.navigationDestinationType, State.self)
+ .id(component.id)
+ }
+}
+
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension NavigationLink where Destination == Never {
/// Creates a navigation link that presents the view corresponding to an element of
This workaround was based on this comment: https://github.com/pointfreeco/swift-composable-architecture/discussions/1842#discussioncomment-4708055
Description
Using
NavigationStackStore
, with a destination view then presenting a third view using.navigationDestination(store:destination)
. When the third view is presented, SwiftUI goes into an infinite loop, consuming 100% CPU and increasing amount of memory.Checklist
main
branch of this package.Expected behavior
The third view is pushed onto the navigation stack
Actual behavior
The app hangs with 100% CPU usage
Steps to reproduce
I've made a sample project that demonstrates the bug, along with demonstrations of the same functionality working correctly in plain SwiftUI. The TCA version is shown below.
In the sample project there are 3 tabs:
NavigationStack
pathNavigationStack
path. Note: I had to extractNavigationDestinationView
to stop this happening in this implementationNavigationStackStore
The Composable Architecture version information
0.55.1
Destination operating system
iOS 16.4
Xcode version information
Version 14.3.1 (14E300c)
Swift Compiler version information