diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
index 8c31371..b55e10e 100644
--- a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
@@ -10,6 +10,7 @@
 use Drupal\Component\Plugin\Exception\ContextException;
 use Drupal\Core\Cache\CacheableDependencyInterface;
 use Drupal\Core\Plugin\ContextAwarePluginInterface;
+use Drupal\Core\TypedData\TypedDataManagerInterface;
 
 /**
  * Provides methods to handle sets of contexts.
@@ -17,6 +18,15 @@
 class ContextHandler implements ContextHandlerInterface {
 
   /**
+   * @var \Drupal\Core\TypedData\TypedDataManagerInterface
+   */
+  protected $typedDataManager;
+
+  public function __construct(TypedDataManagerInterface $typed_data_manager) {
+    $this->typedDataManager = $typed_data_manager;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function filterPluginDefinitionsByContexts(array $contexts, array $definitions) {
@@ -56,11 +66,28 @@ public function getMatchingContexts(array $contexts, ContextDefinitionInterface
         return FALSE;
       }
 
-      // If any constraint does not match, this context is invalid.
-      foreach ($definition->getConstraints() as $constraint_name => $constraint) {
-        if ($context_definition->getConstraint($constraint_name) != $constraint) {
-          return FALSE;
+      if ($definition->getConstraints()) {
+        $constraints = [];
+        foreach ($definition->getConstraints() as $constraint_name => $constraint_settings) {
+          $constraints[] = $this->typedDataManager->getValidationConstraintManager()->create($constraint_name, $constraint_settings);
+        }
+        if ($context->hasContextValue()) {
+          $typed_data_definition = $this->typedDataManager->create($context_definition->getDataDefinition(), $context->getContextValue());
+          foreach ($context_definition->getDataDefinition()->getConstraints() as $constraint => $constraint_settings) {
+            $typed_data_definition->getDataDefinition()->addConstraint($constraint, $constraint_settings);
+          }
+        }
+        else {
+          $typed_data_data_definition = $this->typedDataManager->createDataDefinition('data_type_wrapper');
+          foreach ($context_definition->getDataDefinition()->getConstraints() as $constraint => $constraint_settings) {
+            $typed_data_data_definition->addConstraint($constraint, $constraint_settings);
+          }
+          $typed_data_definition = $this->typedDataManager->create($typed_data_data_definition);
         }
+        $validator = $this->typedDataManager->getValidator();
+        $violations = $validator->validate($typed_data_definition, $constraints);
+        // All contexts with matching data type and contexts are valid.
+        return !$violations->count();
       }
 
       // All contexts with matching data type and contexts are valid.
