NavigationLink pops out by itself

Originator:azeffin
Number:rdar://FB9109857 Date Originated:18 May 2021
Status:Open Resolved:
Product:SwiftUI Product Version:
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
 
Summary:
Just pushed via NavigationLink view gets popped out.

Steps to reproduce:
1. Create SwiftUI iOS app with following implementation
```
import SwiftUI

@main
struct PopBug1App: App {
    var body: some Scene {
        WindowGroup {
            FirstView()
        }
    }
}

struct FirstView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: SecondView()) {
                Text("Second view")
            }
        }
    }
}

struct SecondView: View {
    @Environment(\.presentationMode) var presentationMode
    @StateObject var viewModel = SecondViewModel()

    var body: some View {
        VStack(spacing: 8) {
            NavigationLink(destination: Text("Details"), isActive: $viewModel.detailsVisible) {
                EmptyView()
            }

            NavigationLink(destination: Text("About")) {
                Text("About")
            }

            Button("Details") {
                viewModel.detailsVisible = true
            }
        }
    }
}

class SecondViewModel: ObservableObject {
    @Published var detailsVisible: Bool = false
}
```
2. Run the app
3. Navigate to second screen by tapping 'Second view' button
4. Tap on 'About' or 'Details' button

Observed behavior:
New screen gets pushed and immediately popped.

Expected behavior:
User stays on pushed screen

Note:
Believe issue was introduced in iOS 14.5, because I can’t reproduce it on previous versions.
Changing view hierarchy by adding another NavigationLink fixes the issue.

Versions:
Xcode 12.5 (12E262)
iOS 14.5.1 (18E212)
macOS 11.2.3 (20D91)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!