diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 5c99840..7dad3c1 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -1050,15 +1050,17 @@ protected function initializeSettings(Request $request) {
       }
       if (!empty($loader)) {
         $this->classLoader->unregister();
-        $loader->register();
-        $old_loader = $this->classLoader;
-        $this->classLoader = $loader;
         // The optimized classloader might be persistent and store cache misses.
         // For example, once a cache miss is stored in APCu clearing it on a
         // specific web-head will not clear any other web-heads. Therefore
         // fallback to the composer class loader that only statically caches
         // misses.
-        $old_loader->register();
+        $old_loader = $this->classLoader;
+        $this->classLoader = $loader;
+        // Our class loaders are preprended to ensure they come first like the
+        // class loader they are replacing.
+        $old_loader->register(TRUE);
+        $loader->register(TRUE);
       }
     }
   }
