diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
index 3df078a06b..60e45dc347 100644
--- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
+++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Core\Entity;
 
+use Drupal\Component\Utility\SortArray;
 use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
@@ -202,6 +203,14 @@ protected function init() {
         }
       }
     }
+    $weight = 0;
+    // The config as saved keeps the display order, however most of the time
+    // $this->getComponent($name) will be called for each field and then it is
+    // desirable the resulting array to be sortable to same order as the
+    // displays. To facilitate this, every display configuration gets a weight.
+    foreach (array_keys($this->content) as $name) {
+      $this->content[$name]['weight'] = $weight++;
+    }
   }
 
   /**
@@ -251,6 +260,8 @@ public function id() {
    * {@inheritdoc}
    */
   public function preSave(EntityStorageInterface $storage) {
+    // Make sure to keep order by weights if they were changed.
+    uasort($this->content, [SortArray::class, 'sortByWeightElement']);
     // Ensure that a region is set on each component.
     foreach ($this->getComponents() as $name => $component) {
       // @todo Remove this BC layer in Drupal 9.
@@ -265,9 +276,11 @@ public function preSave(EntityStorageInterface $storage) {
         // Directly set the component to bypass other changes in setComponent().
         $this->content[$name]['region'] = $this->getDefaultRegion();
       }
+      // Remove the weights, they are superfluous and cause git conflicts in
+      // config exports.
+      unset($this->content[$name]['weight']);
     }
 
-    ksort($this->content);
     ksort($this->hidden);
     parent::preSave($storage);
   }
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index f8f9e5509d..f034557239 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -15,6 +15,7 @@
 use Drupal\Core\Database\Database;
 use Drupal\Core\DrupalKernel;
 use Drupal\Core\Entity\ContentEntityTypeInterface;
+use Drupal\Core\Entity\Display\EntityDisplayInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
@@ -2848,3 +2849,16 @@ function system_update_8901() {
     }
   }
 }
+
+/**
+ * Re-save all entity displays to sort and remove component weights.
+ */
+function system_update_8902() {
+  foreach (Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) {
+    if ($entity_type->entityClassImplements(EntityDisplayInterface::class)) {
+      foreach (Drupal::entityTypeManager()->getStorage($entity_type_id)->loadMultiple(NULL) as $display) {
+        $display->save();
+      }
+    }
+  }
+}
