diff --git a/src/CustomElement.php b/src/CustomElement.php
index 6e82056..92d2913 100644
--- a/src/CustomElement.php
+++ b/src/CustomElement.php
@@ -206,6 +206,12 @@ class CustomElement implements CacheableDependencyInterface {
   public function getSortedSlotsByName() {
     $slots = $this->getSlots();
     foreach ($slots as $slot_key => &$entries) {
+      $i = 0;
+      $count = count($entries);
+      foreach ($entries as &$entry) {
+        $entry['weight'] = floor($entry['weight'] * 1000) + $i / $count;
+        $i++;
+      }
       usort($entries, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
     }
     return $slots;
