diff --git a/core/modules/edit/edit.module b/core/modules/edit/edit.module
index 3eaabcc..f96eb80 100644
--- a/core/modules/edit/edit.module
+++ b/core/modules/edit/edit.module
@@ -13,6 +13,7 @@
 
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
+use Drupal\block\BlockPluginInterface;
 
 /**
  * Implements hook_permission().
@@ -186,6 +187,23 @@ function edit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisp
 }
 
 /**
+ * Implements hook_block_view_alter().
+ */
+function edit_block_view_alter(array &$build, BlockPluginInterface $block) {
+  // For in-place editing to integrate with contextual links, the
+  // 'data-edit-entity-id' attribute must be on the same DOM element as the
+  // contextual links information. Since _block_get_renderable_region() moves
+  // the contextual links information from the 'content' child (built by a
+  // specific block type, such as CustomBlock) to the top-level block element
+  // (built by BlockViewBuilder for all blocks), do the same for
+  // 'data-edit-entity-id'.
+  if (isset($build['content']['#attributes']['data-edit-entity-id'])) {
+    $build['#attributes']['data-edit-entity-id'] = $build['content']['#attributes']['data-edit-entity-id'];
+    unset($build['content']['#attributes']['data-edit-entity-id']);
+  }
+}
+
+/**
  * Retrieves the admin theme's Edit stylesheets.
  *
  * Admin themes may specify CSS files to make the front-end administration
