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);
