 .../Core/Cache/Context/SessionExistsCacheContext.php       | 14 ++++++++++----
 core/modules/big_pipe/big_pipe.module                      |  7 ++++++-
 .../src/Tests/Cache/SessionExistsCacheContextTest.php      |  5 +++++
 .../session_exists_cache_context_test.module               |  3 +++
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php
index ecb601f..88d3521 100644
--- a/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php
+++ b/core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php
@@ -15,8 +15,9 @@
  * Defines the SessionExistsCacheContext service, for "session or not" caching.
  *
  * Cache context ID: 'session.exists'.
+ * Calculated cache context ID: 'session.exists:%key'.
  */
-class SessionExistsCacheContext implements CacheContextInterface {
+class SessionExistsCacheContext implements CalculatedCacheContextInterface {
 
   /**
    * The session configuration.
@@ -55,14 +56,19 @@ public static function getLabel() {
   /**
    * {@inheritdoc}
    */
-  public function getContext() {
-    return $this->sessionConfiguration->hasSession($this->requestStack->getCurrentRequest()) ? '1' : '0';
+  public function getContext($key = NULL) {
+    if ($key === NULL) {
+      return $this->sessionConfiguration->hasSession($this->requestStack->getCurrentRequest()) ? '1' : '0';
+    }
+    else {
+      return isset($_SESSION[$key]) ? '1' : '0';
+    }
   }
 
   /**
    * {@inheritdoc}
    */
-  public function getCacheableMetadata() {
+  public function getCacheableMetadata($key = NULL) {
     return new CacheableMetadata();
   }
 
diff --git a/core/modules/big_pipe/big_pipe.module b/core/modules/big_pipe/big_pipe.module
index 1970c27..437b840 100644
--- a/core/modules/big_pipe/big_pipe.module
+++ b/core/modules/big_pipe/big_pipe.module
@@ -44,11 +44,16 @@ function big_pipe_page_attachments(array &$page) {
   // @see \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy.
   $session_exists = \Drupal::service('session_configuration')->hasSession($request);
   $page['#cache']['contexts'][] = 'session.exists';
+  // The batch system uses a <meta> refresh to work without JavaScript, hence
+  // BigPipe's no-JS detection would interfere with that. Therefore simply
+  // disable BigPipe's no-JS detection altogether.
+  $batch_exists = isset($_SESSION['batches']);
+  $page['#cache']['contexts'][] = 'session.exists:batches';
   // Only do the no-JS detection while we don't know if there's no JS support:
   // avoid endless redirect loops.
   $has_big_pipe_nojs_cookie = $request->cookies->has(BigPipeStrategy::NOJS_COOKIE);
   $page['#cache']['contexts'][] = 'cookies:' . BigPipeStrategy::NOJS_COOKIE;
-  if ($session_exists && !$has_big_pipe_nojs_cookie) {
+  if ($session_exists && !$batch_exists && !$has_big_pipe_nojs_cookie) {
     $page['#attached']['html_head'][] = [
       [
         // Redirect through a 'Refresh' meta tag if JavaScript is disabled.
diff --git a/core/modules/system/src/Tests/Cache/SessionExistsCacheContextTest.php b/core/modules/system/src/Tests/Cache/SessionExistsCacheContextTest.php
index 3041dd1..739d169 100644
--- a/core/modules/system/src/Tests/Cache/SessionExistsCacheContextTest.php
+++ b/core/modules/system/src/Tests/Cache/SessionExistsCacheContextTest.php
@@ -36,6 +36,7 @@ public function testCacheContext() {
     $this->assertSessionCookieOnClient(FALSE);
     $this->assertRaw('Session does not exist!');
     $this->assertRaw('[session.exists]=0');
+    $this->assertRaw('[session.exists:session_exists_cache_context_test]=0');
 
     // 2. Session (authenticated).
     $this->assertSessionCookieOnClient(FALSE);
@@ -43,10 +44,12 @@ public function testCacheContext() {
     $this->assertSessionCookieOnClient(TRUE);
     $this->assertRaw('Session exists!');
     $this->assertRaw('[session.exists]=1');
+    $this->assertRaw('[session.exists:session_exists_cache_context_test]=0');
     $this->drupalLogout();
     $this->assertSessionCookieOnClient(FALSE);
     $this->assertRaw('Session does not exist!');
     $this->assertRaw('[session.exists]=0');
+    $this->assertRaw('[session.exists:session_exists_cache_context_test]=0');
 
     // 3. Session (anonymous).
     $this->assertSessionCookieOnClient(FALSE);
@@ -54,10 +57,12 @@ public function testCacheContext() {
     $this->assertSessionCookieOnClient(TRUE);
     $this->assertRaw('Session does not exist!');
     $this->assertRaw('[session.exists]=0');
+    $this->assertRaw('[session.exists:session_exists_cache_context_test]=0');
     $this->drupalGet(Url::fromRoute('<front>'));
     $this->assertSessionCookieOnClient(TRUE);
     $this->assertRaw('Session exists!');
     $this->assertRaw('[session.exists]=1');
+    $this->assertRaw('[session.exists:session_exists_cache_context_test]=1');
   }
 
   /**
diff --git a/core/modules/system/tests/modules/session_exists_cache_context_test/session_exists_cache_context_test.module b/core/modules/system/tests/modules/session_exists_cache_context_test/session_exists_cache_context_test.module
index 60d2452..13aea04 100644
--- a/core/modules/system/tests/modules/session_exists_cache_context_test/session_exists_cache_context_test.module
+++ b/core/modules/system/tests/modules/session_exists_cache_context_test/session_exists_cache_context_test.module
@@ -21,6 +21,9 @@ function session_exists_cache_context_test_page_top(array &$page_top) {
     'cache_context_value' => [
       '#markup' => '<code>[session.exists]=' . \Drupal::service('cache_context.session.exists')->getContext() . '</code>',
     ],
+    'cache_context_value_key' => [
+      '#markup' => '<code>[session.exists:session_exists_cache_context_test]=' . \Drupal::service('cache_context.session.exists')->getContext('session_exists_cache_context_test') . '</code>',
+    ],
   ];
 
   if (\Drupal::request()->query->get('trigger_session')) {
