Skip to content

Commit 4bdbfcf

Browse files
authored
Fix cached page rendering when nested in <NavigationStack> (#1198)
1 parent bd985be commit 4bdbfcf

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Sources/LiveViewNative/Coordinators/LiveSessionState.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,15 @@ public enum LiveSessionState {
1818
// todo: disconnected state?
1919
/// The coordinator failed to connect and produced the given error.
2020
case connectionFailed(Error)
21+
22+
/// Either `notConnected` or `connecting`
23+
var isPending: Bool {
24+
switch self {
25+
case .notConnected,
26+
.connecting:
27+
return true
28+
default:
29+
return false
30+
}
31+
}
2132
}

Sources/LiveViewNative/NavStackEntryView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ struct NavStackEntryView<R: RootRegistry>: View {
4040
.transition(coordinator.session.configuration.transition ?? .identity)
4141
default:
4242
SwiftUI.Group {
43-
if case .notConnected = coordinator.state,
43+
if coordinator.state.isPending,
4444
let document = coordinator.document
4545
{
46-
coordinator.builder.fromNodes(document[document.root()].children(), coordinator: coordinator, url: coordinator.url)
46+
coordinator.builder.fromNodes(document[document.root()].children(), coordinator: coordinator, url: coordinator.url)
4747
.environment(\.coordinatorEnvironment, CoordinatorEnvironment(coordinator, document: document))
4848
.disabled(true)
4949
} else if R.LoadingView.self == Never.self {

Sources/LiveViewNative/Views/Navigation/NavigationStack.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ struct NavigationStack<R: RootRegistry>: View {
2020
session.navigationPath[1...] = value
2121
}) {
2222
SwiftUI.VStack {
23-
if session.navigationPath.count == 1 {
24-
context.buildChildren(of: element)
25-
}
23+
context.buildChildren(of: element)
2624
}
2725
.navigationDestination(for: LiveNavigationEntry<R>.self) { destination in
2826
NavStackEntryView(destination)

0 commit comments

Comments
 (0)