diff --git a/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php b/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php
index e335b87ab8..83f2de8142 100644
--- a/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php
+++ b/core/modules/layout_builder/src/EventSubscriber/PrepareLayout.php
@@ -66,10 +66,10 @@ public function onPrepareLayout(PrepareLayoutEvent $event) {
     $section_storage = $event->getSectionStorage();
 
     // If the layout has pending changes, add a warning.
-    if ($this->layoutTempstoreRepository->has($section_storage)) {
+    if (!empty($section_storage->hasUnsavedChanges)) {
       $this->messenger->addWarning($this->t('You have unsaved changes.'));
     }
-    else {
+    if (!$this->layoutTempstoreRepository->has($section_storage)) {
       // If the layout is an override that has not yet been overridden, copy the
       // sections from the corresponding default.
       if ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) {
diff --git a/core/modules/layout_builder/src/LayoutTempstoreRepository.php b/core/modules/layout_builder/src/LayoutTempstoreRepository.php
index 36b78948b3..fd47c67348 100644
--- a/core/modules/layout_builder/src/LayoutTempstoreRepository.php
+++ b/core/modules/layout_builder/src/LayoutTempstoreRepository.php
@@ -56,6 +56,9 @@ public function has(SectionStorageInterface $section_storage) {
    * {@inheritdoc}
    */
   public function set(SectionStorageInterface $section_storage) {
+    if ($this->has($section_storage)) {
+      $section_storage->hasUnsavedChanges = TRUE;
+    }
     $key = $this->getKey($section_storage);
     $this->getTempstore($section_storage)->set($key, ['section_storage' => $section_storage]);
   }
diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php
index 6523bd6367..550eb4def1 100644
--- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php
@@ -98,6 +98,13 @@ public function testUnsavedChangesMessage() {
     $this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display/default/layout');
     $page->pressButton('Save layout');
     $assert_session->pageTextNotContains('You have unsaved changes.');
+
+    // Go back to layout form.
+    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
+    $assert_session->pageTextNotContains('You have unsaved changes.');
+    // Reload the page.
+    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
+    $assert_session->pageTextNotContains('You have unsaved changes.');
   }
 
   /**
