diff --git a/modules/entity_hierarchy_microsite/src/EntityHooks.php b/modules/entity_hierarchy_microsite/src/EntityHooks.php
index 7a54868..7638567 100644
--- a/modules/entity_hierarchy_microsite/src/EntityHooks.php
+++ b/modules/entity_hierarchy_microsite/src/EntityHooks.php
@@ -24,6 +24,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  */
 class EntityHooks implements ContainerInjectionInterface {
 
+  /**
+   * Flag to check if rebuild has been triggered already.
+   *
+   * @var bool
+   */
+  protected static $triggered = FALSE;
+
   /**
    * Menu link tree.
    *
@@ -138,9 +145,16 @@ class EntityHooks implements ContainerInjectionInterface {
   public function onNodeUpdate(NodeInterface $node) {
     $original = $node->original;
     foreach ($this->parentCandidate->getCandidateFields($node) as $field) {
-      if ($node->hasField($field) && ((!$node->get($field)->isEmpty() || !$original->get($field)->isEmpty()) ||
-        ($node->{$field}->target_id !== $original->{$field}->target_id ||
-        $node->{$field}->weight !== $original->{$field}->weight))) {
+      if ($node->hasField($field) &&
+        (
+          // Either the new version or the old version has no parent.
+          $node->get($field)->isEmpty() !== $original->get($field)->isEmpty() ||
+          // Or the parent changed.
+          (int) $node->{$field}->target_id !== (int) $original->{$field}->target_id ||
+          // Or the weight changed.
+          (int) $node->{$field}->weight !== (int) $original->{$field}->weight
+        )
+      ) {
         if ($microsites = $this->childOfMicrositeLookup->findMicrositesForNodeAndField($node, $field)) {
           foreach ($microsites as $microsite) {
             $this->updateMenuForMicrosite($microsite);
@@ -186,7 +200,9 @@ class EntityHooks implements ContainerInjectionInterface {
    *   TRUE if is an update.
    */
   public function onMicrositePostSave(MicrositeInterface $microsite, $isUpdate) {
-    $this->updateMenuForMicrosite($microsite);
+    if ($microsite->shouldGenerateMenu() || ($microsite->original instanceof MicrositeInterface && $microsite->original->shouldGenerateMenu())) {
+      $this->updateMenuForMicrosite($microsite);
+    }
   }
 
   /**
@@ -196,9 +212,22 @@ class EntityHooks implements ContainerInjectionInterface {
    *   Microsite.
    */
   protected function updateMenuForMicrosite(MicrositeInterface $microsite) {
-    $this->menuLinkManager->rebuild();
+    if (!self::$triggered) {
+      drupal_register_shutdown_function([$this, 'onShutdown']);
+      self::$triggered = TRUE;
+    }
+  }
+
+  /**
+   * Perform rebuild on shutdown.
+   */
+  public function onShutdown(): void {
+    if (\Drupal::hasContainer()) {
+      $this->menuLinkManager->rebuild();
+    }
   }
 
+
   /**
    * Post save handler for overrides.
    *
@@ -255,4 +284,24 @@ class EntityHooks implements ContainerInjectionInterface {
     }
   }
 
+  /**
+   * Checks if menu rebuild is required.
+   *
+   * @return bool
+   *   TRUE if rebuild required.
+   */
+  public static function rebuildRequired(): bool {
+    return self::$triggered;
+  }
+
+  /**
+   * Checks if menu rebuild is required.
+   *
+   * @return bool
+   *   TRUE if rebuild required.
+   */
+  public static function resetRebuildRequired(): void {
+    self::$triggered = FALSE;
+  }
+
 }
diff --git a/modules/entity_hierarchy_microsite/tests/modules/entity_hierarchy_microsite_test/entity_hierarchy_microsite_test.module b/modules/entity_hierarchy_microsite/tests/modules/entity_hierarchy_microsite_test/entity_hierarchy_microsite_test.module
index e47ea0f..297c297 100644
--- a/modules/entity_hierarchy_microsite/tests/modules/entity_hierarchy_microsite_test/entity_hierarchy_microsite_test.module
+++ b/modules/entity_hierarchy_microsite/tests/modules/entity_hierarchy_microsite_test/entity_hierarchy_microsite_test.module
@@ -9,6 +9,7 @@ use Drupal\Core\Url;
 use Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverrideInterface;
 use Drupal\entity_hierarchy_microsite\Plugin\Menu\MicrositeMenuItem;
 use Drupal\entity_hierarchy_microsite_test\Entity\CustomMicrosite;
+use Drupal\Tests\entity_hierarchy_microsite\Kernel\MicrositeMenuItemsTest;
 
 /**
  * Implements hook_entity_hierarchy_microsite_links_alter().
@@ -35,3 +36,10 @@ function entity_hierarchy_microsite_test_entity_bundle_info_alter(&$bundles) {
     $bundles['entity_hierarchy_microsite']['entity_hierarchy_microsite']['class'] = CustomMicrosite::class;
   }
 }
+
+/**
+ * Implements hook_menu_links_discovered().
+ */
+function entity_hierarchy_microsite_test_menu_links_discovered_alter(&$data): void {
+  \Drupal::state()->set(MicrositeMenuItemsTest::STATE_KEY, \Drupal::state()->get(MicrositeMenuItemsTest::STATE_KEY, 0) + 1);
+}
diff --git a/modules/entity_hierarchy_microsite/tests/src/Kernel/MicrositeMenuItemsTest.php b/modules/entity_hierarchy_microsite/tests/src/Kernel/MicrositeMenuItemsTest.php
index 2653561..1b90baf 100644
--- a/modules/entity_hierarchy_microsite/tests/src/Kernel/MicrositeMenuItemsTest.php
+++ b/modules/entity_hierarchy_microsite/tests/src/Kernel/MicrositeMenuItemsTest.php
@@ -12,6 +12,8 @@ use Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverride;
  */
 class MicrositeMenuItemsTest extends EntityHierarchyMicrositeKernelTestBase {
 
+  const STATE_KEY = 'entity_hierarchy_microsite_test_rebuild_count';
+
   /**
    * Tests the microsite menu link integration.
    */
@@ -40,13 +42,32 @@ class MicrositeMenuItemsTest extends EntityHierarchyMicrositeKernelTestBase {
 
     // Set the generate menu flag.
     $microsite->set('generate_menu', TRUE)->save();
+    _drupal_shutdown_function();
+
     // hook_entity_hierarchy_microsite_links_alter() should now be fired.
     $this->assertEquals('success', \Drupal::state()->get('entity_hierarchy_microsite_test_entity_hierarchy_microsite_links_alter', NULL));
+    $this->assertEquals(1, \Drupal::state()->get(self::STATE_KEY));
+
+    // Resave an item in the menu without changing the parent/weight
+    $last_second_child->save();
+    // We shouldn't have regenerated the menu as nothing changed.
+    $this->assertEquals(1, \Drupal::state()->get(self::STATE_KEY));
+
+    // Change the weight of the last_second item.
+    $last_second_child->{self::FIELD_NAME}->weight = $last_second_child->{self::FIELD_NAME}->weight + 1;
+    $last_second_child->save();
+    _drupal_shutdown_function();
+
+    // We should have regenerated the menu as the weight changed.
+    $this->assertEquals(2, \Drupal::state()->get(self::STATE_KEY));
+
     /** @var \Drupal\Core\Menu\MenuLinkTreeInterface $tree */
     $tree = \Drupal::service('menu.link_tree');
     $params = $tree->getCurrentRouteMenuTreeParameters('entity-hierarchy-microsite');
     $params->setMaxDepth(9);
     $items = $tree->load('entity-hierarchy-microsite', $params);
+    // A rebuild is triggered here from the route builder.
+    $this->assertEquals(3, \Drupal::state()->get(self::STATE_KEY));
     $this->assertCount(1, $items);
     $plugin_id = 'entity_hierarchy_microsite:' . $this->parent->uuid();
     $this->assertArrayHasKey($plugin_id, $items);
@@ -75,6 +96,10 @@ class MicrositeMenuItemsTest extends EntityHierarchyMicrositeKernelTestBase {
     array_push($first_children, $last);
     $last->{self::FIELD_NAME} = $first;
     $last->save();
+    _drupal_shutdown_function();
+
+    // Should have caused another rebuild.
+    $this->assertEquals(4, \Drupal::state()->get(self::STATE_KEY));
     $items = $tree->load('entity-hierarchy-microsite', $params);
     $child_plugin_id = 'entity_hierarchy_microsite:' . $first->uuid();
     $this->assertCount(6, $items[$plugin_id]->subtree[$child_plugin_id]->subtree);
@@ -92,7 +117,14 @@ class MicrositeMenuItemsTest extends EntityHierarchyMicrositeKernelTestBase {
     $last->{self::FIELD_NAME} = NULL;
     $last->setNewRevision(TRUE);
     $last->save();
+    _drupal_shutdown_function();
+
+    $this->assertEquals(5, \Drupal::state()->get(self::STATE_KEY));
+
     $last->delete();
+    _drupal_shutdown_function();
+
+    $this->assertEquals(6, \Drupal::state()->get(self::STATE_KEY));
     $items = $tree->load('entity-hierarchy-microsite', $params);
     $this->assertCount(2, $items[$plugin_id]->subtree[$child_plugin_id]->subtree);
     foreach ($second_children as $child_entity) {
@@ -103,7 +135,11 @@ class MicrositeMenuItemsTest extends EntityHierarchyMicrositeKernelTestBase {
     $items = $tree->load('entity-hierarchy-microsite', $params);
     $this->assertCount(5, $items[$plugin_id]->subtree);
     $first->set('title', 'Updated first title')->setNewRevision();
+
     $first->save();
+    _drupal_shutdown_function();
+
+    $this->assertEquals(7, \Drupal::state()->get(self::STATE_KEY));
     $items = $tree->load('entity-hierarchy-microsite', $params);
     $this->assertCount(5, $items[$plugin_id]->subtree);
 
