diff --git a/core/core.services.yml b/core/core.services.yml
index 872e2ff..f88d856 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -290,8 +290,8 @@ services:
     arguments: ['@database', '@lock']
   router.request_context:
     class: Symfony\Component\Routing\RequestContext
-    calls:
-      - [fromRequest, ['@request']]
+    tags:
+      - { name: persist }
   router.admin_context:
     class: Drupal\Core\Routing\AdminContext
     calls:
@@ -318,7 +318,7 @@ services:
     arguments: ['@router.route_provider', '@path_processor_manager', '@route_processor_manager', '@config.factory', '@settings']
     calls:
       - [setRequest, ['@?request']]
-      - [setContext, ['@?router.request_context']]
+      - [setContext, ['@router.request_context']]
   link_generator:
     class: Drupal\Core\Utility\LinkGenerator
     arguments: ['@url_generator', '@module_handler', '@path.alias_manager.cached']
@@ -468,7 +468,7 @@ services:
     class: Symfony\Component\HttpKernel\EventListener\RouterListener
     tags:
       - { name: event_subscriber }
-    arguments: ['@router']
+    arguments: ['@router', '@router.request_context', NULL, '@request_stack']
   content_negotiation:
     class: Drupal\Core\ContentNegotiation
   view_subscriber:
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 065d4c8..9acf417 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -1144,8 +1144,17 @@ protected function rebuildContainer($environment = 'testing') {
     // DrupalKernel replaces the container in \Drupal::getContainer() with a
     // different object, so we need to replace the instance on this test class.
     $this->container = \Drupal::getContainer();
-    // The current user is set in TestBase::prepareEnvironment().
+
+    // Restore the request.
     $this->container->set('request', $request);
+
+    // The request context is normally set by the router_listener from within
+    // its KernelEvents::REQUEST listener. In the simpletest parent site this
+    // event is not fired, therefore it is necessary to updated the request
+    // context manually here.
+    $this->container->get('router.request_context')->fromRequest($request);
+
+    // The current user is set in TestBase::prepareEnvironment().
     $this->container->set('current_user', \Drupal::currentUser());
   }
 
