diff --git a/Sources/ComposableArchitecture/Observation/NavigationStack+Observation.swift b/Sources/ComposableArchitecture/Observation/NavigationStack+Observation.swift index 76e9287de8c0..a445d018e106 100644 --- a/Sources/ComposableArchitecture/Observation/NavigationStack+Observation.swift +++ b/Sources/ComposableArchitecture/Observation/NavigationStack+Observation.swift @@ -202,14 +202,22 @@ public struct _NavigationDestinationViewModifier< content .environment(\.navigationDestinationType, State.self) .navigationDestination(for: StackState.Component.self) { component in - navigationDestination(component: component) + destination(store.scope(component: component, fileID: fileID, filePath: filePath, line: line, column: column)) .environment(\.navigationDestinationType, State.self) } } +} - @MainActor - private func navigationDestination(component: StackState.Component) -> Destination { - let id = store.id( +@_spi(Internals) +public extension Store { + func scope( + component: StackState.Component, + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column + ) -> Store where State == StackState, Action == StackAction { + let id = self.id( state: \.[ id: component.id, @@ -222,8 +230,8 @@ public struct _NavigationDestinationViewModifier< ) @MainActor func open( - _ core: some Core, StackAction> - ) -> any Core { + _ core: some Core, StackAction> + ) -> any Core { IfLetCore( base: core, cachedState: component.element, @@ -238,7 +246,7 @@ public struct _NavigationDestinationViewModifier< actionKeyPath: \.[id: component.id] ) } - return destination(store.scope(id: id, childCore: open(store.core))) + return self.scope(id: id, childCore: open(self.core)) } }