title: SwiftUI's NavigationLink `tag` and `selection` in NavigationView stops working if not all NavigationLinks are displayed
body: <p>I have a list of items in a <code>Form</code> in a <code>NavigationView</code>, each having a detail-view that can be reached with <code>NavigationLink</code>.
  When I add a new element to the list, I want to show its detail-view. For that I use a <code>@State var currentSelection</code> that the <code>NavigationLink</code> receives as <code>selection</code>, and each element has functions as the <code>tag</code>:</p>
  <pre class="lang-swift prettyprint-override"><code>NavigationLink(
    destination: DetailView(entry: entry),
    tag: entry,
    selection: $currentSelection,
    label: { Text(&quot;The number \(entry)&quot;) })
  </code></pre>
  <p>This works, and it follows the <a href="https://developer.apple.com/documentation/swiftui/navigationlink" rel="noreferrer">Apple docs</a> and the <a href="https://www.hackingwithswift.com/articles/216/complete-guide-to-navigationview-in-swiftui" rel="noreferrer">best practises</a>.</p>
  <p>The surprise is, that it <strong>stops</strong> working when the list has more elements than fit on screen (plus ~2). Question: Why? And how can I work around it?</p>
  <hr />
  <p>I made a minimal example to replicate the behaviour:</p>
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct ContentView: View {
      @State var entries = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
      @State var currentSelection: Int? = nil
  
      var body: some View {
          NavigationView {
              Form {
                  ForEach(entries.sorted(), id: \.self) { entry in
                      NavigationLink(
                          destination: DetailView(entry: entry),
                          tag: entry,
                          selection: $currentSelection,
                          label: { Text(&quot;The number \(entry)&quot;) })
                  }
              }
              .toolbar {
                  ToolbarItem(placement: ToolbarItemPlacement.navigationBarLeading) { Button(&quot;Add low&quot;) {
                      let newEntry = (entries.min() ?? 1) - 1
                      entries.insert(newEntry, at: 1)
                      currentSelection = newEntry
                  } }
                  ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) { Button(&quot;Add high&quot;) {
                      let newEntry = (entries.max() ?? 50) + 1
                      entries.append(newEntry)
                      currentSelection = newEntry
                  } }
                  ToolbarItem(placement: ToolbarItemPlacement.bottomBar) {
                      Text(&quot;The current selection is \(String(describing: currentSelection))&quot;)
                  }
              }
          }
      }
  }
  
  struct DetailView: View {
      let entry: Int
      var body: some View {
          Text(&quot;It's a \(entry)!&quot;)
      }
  }
  </code></pre>
  <p>(I ruled out that the <em>number</em> of elements is the core problem by reducing the list to 5 items and setting a padding on the label: <code>label: { Text(&quot;The number \(entry).padding(30)&quot;) })</code>)</p>
  <p>As you can see in the screen-recordings, after reaching the critical number of elements (either by prepending or appending to the list), the bottom sheet still shows that the <code>currentSelection</code> is being updated, but no navigation is happening.</p>
  <p>I used iOS 14.7.1, Xcode 12.5.1 and Swift 5.</p>
  <p><a href="https://i.stack.imgur.com/I9kKJ.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/I9kKJ.gif" alt="adding to the start of the list" /></a>
  <a href="https://i.stack.imgur.com/NFEU6.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/NFEU6.gif" alt="adding to the end of the list" /></a></p>