diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php
index 77da924..31128f7 100644
--- a/core/modules/book/src/BookManager.php
+++ b/core/modules/book/src/BookManager.php
@@ -397,7 +397,7 @@ protected function recurseTableOfContents(array $tree, $indent, array &$toc, arr
     foreach ($tree as $data) {
       if ($data['link']['depth'] > $depth_limit) {
         // Don't iterate through any links on this level.
-        break;
+        return;
       }
       if (!in_array($data['link']['nid'], $exclude)) {
         $nids[] = $data['link']['nid'];
@@ -408,7 +408,8 @@ protected function recurseTableOfContents(array $tree, $indent, array &$toc, arr
 
     foreach ($tree as $data) {
       $nid = $data['link']['nid'];
-      if (in_array($nid, $exclude)) {
+      // Check for excluded or missing node.
+      if (empty($nodes[$nid])) {
         continue;
       }
       $toc[$nid] = $indent . ' ' . Unicode::truncate($nodes[$nid]->label(), 30, TRUE, TRUE);
diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php
index 16c7027..8c80fbb 100644
--- a/core/modules/book/src/Tests/BookTest.php
+++ b/core/modules/book/src/Tests/BookTest.php
@@ -444,6 +444,45 @@ function testBookNavigationBlock() {
   }
 
   /**
+   * Tests BookManager::getTableOfContents().
+   */
+  public function testGetTableOfContents() {
+    // Create new book.
+    $nodes = $this->createBook();
+    $book = $this->book;
+
+    $this->drupalLogin($this->bookAuthor);
+
+    /*
+     * Add Node 5 under Node 2.
+     * Add Node 6, 7, 8, 9, 10, 11 under Node 3.
+     * Book
+     *  |- Node 0
+     *   |- Node 1
+     *   |- Node 2
+     *    |- Node 5
+     *  |- Node 3
+     *   |- Node 6
+     *    |- Node 7
+     *     |- Node 8
+     *      |- Node 9
+     *       |- Node 10
+     *        |- Node 11
+     *  |- Node 4
+     */
+    foreach (array(5 => 2, 6 => 3, 7 => 6, 8 => 7, 9 => 8, 10 => 9, 11 => 10) as $child => $parent) {
+      $nodes[$child] = $this->createBookNode($book->id(), $nodes[$parent]->id());
+    }
+    $this->drupalGet($nodes[0]->toUrl('edit-form'));
+    // Snice Node 0 has children 2 levels deep, nodes 10 and 11 should not
+    // appear in the selector.
+    $this->assertNoOption('edit-book-pid', $nodes[10]->id());
+    $this->assertNoOption('edit-book-pid', $nodes[11]->id());
+    // Node 9 should be available as an option.
+    $this->assertOption('edit-book-pid', $nodes[9]->id());
+  }
+
+  /**
    * Tests the book navigation block when an access module is installed.
    */
   function testNavigationBlockOnAccessModuleInstalled() {
