diff --git a/core/lib/Drupal/Core/Render/Element/Checkbox.php b/core/lib/Drupal/Core/Render/Element/Checkbox.php
index 9092314dfd..ada66ee7bb 100644
--- a/core/lib/Drupal/Core/Render/Element/Checkbox.php
+++ b/core/lib/Drupal/Core/Render/Element/Checkbox.php
@@ -52,7 +52,7 @@ public function getInfo() {
    * {@inheritdoc}
    */
   public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
-    if ($input === FALSE) {
+    if ($input === FALSE  || (\Drupal::request()->isXmlHttpRequest() && is_null($input))) {
       // Use #default_value as the default value of a checkbox, except change
       // NULL to 0, because FormBuilder::handleInputElement() would otherwise
       // replace NULL with empty string, but an empty string is a potentially
diff --git a/core/lib/Drupal/Core/Render/Element/Checkboxes.php b/core/lib/Drupal/Core/Render/Element/Checkboxes.php
index 35611fd3b9..df480d3c06 100644
--- a/core/lib/Drupal/Core/Render/Element/Checkboxes.php
+++ b/core/lib/Drupal/Core/Render/Element/Checkboxes.php
@@ -73,12 +73,19 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta
         // sub-elements.
         $weight += 0.001;
 
+        if ($is_ajax = \Drupal::request()->isXmlHttpRequest()) {
+          $default_value = (is_array($element['#default_value']) && in_array($key, $element['#default_value'])) ? $key : NULL;
+        }
+        else {
+          $default_value = isset($value[$key]) ? $key : NULL;
+        }
+
         $element += [$key => []];
         $element[$key] += [
           '#type' => 'checkbox',
           '#title' => $choice,
           '#return_value' => $key,
-          '#default_value' => isset($value[$key]) ? $key : NULL,
+          '#default_value' => $default_value,
           '#attributes' => $element['#attributes'],
           '#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
           // Errors should only be shown on the parent checkboxes element.
diff --git a/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php b/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
index 3909303322..cbde0c3132 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
@@ -358,7 +358,7 @@ public function testEditableCaption() {
 
     // Wait for element to update without figcaption.
     $result = $page->waitFor(10, function () use ($drupal_media) {
-      return empty($drupal_media->find('css', 'figcaption'));
+      return !empty($drupal_media->find('css', 'figcaption'));
     });
     // Will be true if no figcaption exists within the drupal-media element.
     $this->assertTrue($result);
