 core/includes/common.inc        | 16 ++++++++++++++++
 core/themes/bartik/bartik.theme |  9 +++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/core/includes/common.inc b/core/includes/common.inc
index e66261e..fcb09bd 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -986,6 +986,22 @@ function drupal_render_children(&$element, $children_keys = NULL) {
 }
 
 /**
+ * Checks if the specified element is empty.
+ *
+ * @param array $elements
+ *   A render array.
+ * @param string $key
+ *   The key of the child element to check the emptiness of.
+ *
+ * @return bool
+ *   Whether the child of the render array with key $key is empty. If no child
+ *   exists at that key, it is also considered empty.
+ */
+function element_is_empty(array $elements, $key) {
+  return !isset($elements[$key]) || Element::isEmpty($elements[$key]);
+}
+
+/**
  * Renders an element.
  *
  * This function renders an element. The top level element is shown with show()
diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme
index 03dc8b4..a1aff15 100644
--- a/core/themes/bartik/bartik.theme
+++ b/core/themes/bartik/bartik.theme
@@ -6,6 +6,7 @@
  */
 
 use Drupal\Component\Utility\Xss;
+use Drupal\Core\Render\Element;
 use Drupal\Core\Template\Attribute;
 
 /**
@@ -15,14 +16,14 @@
  */
 function bartik_preprocess_html(&$variables) {
   // Add information about the number of sidebars.
-  if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
+  if (!element_is_empty($variables['page'], 'sidebar_first') && !element_is_empty($variables['page'], 'sidebar_second')) {
     $variables['attributes']['class'][] = 'layout-two-sidebars';
   }
-  elseif (!empty($variables['page']['sidebar_first'])) {
+  elseif (!element_is_empty($variables['page'], 'sidebar_first')) {
     $variables['attributes']['class'][] = 'layout-one-sidebar';
     $variables['attributes']['class'][] = 'layout-sidebar-first';
   }
-  elseif (!empty($variables['page']['sidebar_second'])) {
+  elseif (!element_is_empty($variables['page'], 'sidebar_second')) {
     $variables['attributes']['class'][] = 'layout-one-sidebar';
     $variables['attributes']['class'][] = 'layout-sidebar-second';
   }
@@ -30,7 +31,7 @@ function bartik_preprocess_html(&$variables) {
     $variables['attributes']['class'][] = 'layout-no-sidebars';
   }
 
-  if (!empty($variables['page']['featured_top'])) {
+  if (!element_is_empty($variables['page'], 'featured_top')) {
     $variables['attributes']['class'][] = 'has-featured-top';
   }
 
