diff --git a/inline_entity_form.module b/inline_entity_form.module
index 983cf6e..02b8455 100644
--- a/inline_entity_form.module
+++ b/inline_entity_form.module
@@ -100,6 +100,7 @@ function inline_entity_form_reference_form($reference_form, &$form_state) {
     ],
   ];
   InlineEntityFormComplex::addSubmitCallbacks($reference_form['actions']['ief_reference_save']);
+  $reference_form['actions']['ief_reference_save']['#submit'][] = ['\Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex', 'closeForm'];
   $reference_form['actions']['ief_reference_cancel'] = [
     '#type' => 'submit',
     '#value' => t('Cancel'),
@@ -268,11 +269,12 @@ function inline_entity_form_close_all_forms($elements, FormStateInterface $form_
     // Close the main form.
     $form_state->set(['inline_entity_form', $ief_id, 'form'], NULL);
     // Close the row forms.
-    $entities = $form_state->get(['inline_entity_form', $ief_id, 'entities']);
-    foreach ($entities as $key => $value) {
-      $entities[$key]['form'] = NULL;
+    if ($entities = $form_state->get(['inline_entity_form', $ief_id, 'entities'])) {
+      foreach ($entities as $key => $value) {
+        $entities[$key]['form'] = NULL;
+      }
+      $form_state->set(['inline_entity_form', $ief_id, 'entities'], $entities);
     }
-    $form_state->set(['inline_entity_form', $ief_id, 'entities'], $entities);
   }
 }
 
diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
index 9162646..e4615a1 100644
--- a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
@@ -626,8 +626,8 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
     // Add submit handlers depending on operation.
     if ($element['#op'] == 'add') {
       static::addSubmitCallbacks($element['actions']['ief_add_save']);
+      $element['actions']['ief_add_save']['#submit'][] = [get_called_class(), 'closeForm'];
       $element['actions']['ief_add_cancel']['#submit'] = [
-        [get_called_class(), 'closeChildForms'],
         [get_called_class(), 'closeForm'],
         'inline_entity_form_cleanup_form_state',
       ];
@@ -637,7 +637,9 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
       $element['actions']['ief_edit_cancel']['#ief_row_delta'] = $element['#ief_row_delta'];
 
       static::addSubmitCallbacks($element['actions']['ief_edit_save']);
+      $element['actions']['ief_edit_save']['#submit'][] = [get_called_class(), 'closeChildForms'];
       $element['actions']['ief_edit_save']['#submit'][] = [get_called_class(), 'submitCloseRow'];
+
       $element['actions']['ief_edit_cancel']['#submit'] = [
         [get_called_class(), 'closeChildForms'],
         [get_called_class(), 'submitCloseRow'],
@@ -876,7 +878,6 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
   public static function addSubmitCallbacks(&$element) {
     $element['#submit'] = [
       ['\Drupal\inline_entity_form\ElementSubmit', 'trigger'],
-      ['\Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex', 'closeForm'],
     ];
     $element['#ief_submit_trigger']  = TRUE;
   }
@@ -893,8 +894,14 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
    *   The form state of the parent form.
    */
   public static function closeChildForms($form, FormStateInterface &$form_state) {
-    $element = inline_entity_form_get_element($form, $form_state);
-    inline_entity_form_close_all_forms($element, $form_state);
+    // Find the closest inline_entity_form element up the tree
+    $triggering_element = $form_state->getTriggeringElement();
+    // Remove the action and the actions container.
+    $array_parents = array_slice($triggering_element['#array_parents'], 0, -2);
+    $inline_entity_form = NestedArray::getValue($form, $array_parents);
+    foreach (Element::children($inline_entity_form) as $key) {
+      inline_entity_form_close_all_forms($inline_entity_form[$key], $form_state);
+    }
   }
 
 }
diff --git a/src/Tests/ComplexSimpleWidgetTest.php b/src/Tests/ComplexSimpleWidgetTest.php
index 115a879..550112f 100644
--- a/src/Tests/ComplexSimpleWidgetTest.php
+++ b/src/Tests/ComplexSimpleWidgetTest.php
@@ -108,4 +108,55 @@ class ComplexSimpleWidgetTest extends InlineEntityFormTestBase {
     }
   }
 
+  /**
+   * Test that the scope of a Cancel button is isolated to the form that it is
+   * associated with.
+   */
+  public function testIsolatedCancel() {
+    // First assertion, two edit forms open, hit Cancel on one, other should
+    // remain open.
+    $this->drupalGet('node/add/ief_complex_simple');
+    // Create two entities.
+    $outer_title_field = 'ief_complex_outer[form][inline_entity_form][title][0][value]';
+    $inner_title_field = 'ief_complex_outer[form][inline_entity_form][single][0][inline_entity_form][title][0][value]';
+    for ($i = 0; $i < 2; $i++) {
+      $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add new node" and @data-drupal-selector="edit-ief-complex-outer-actions-ief-add"]'));
+      $edit[$outer_title_field] = $this->randomMachineName(8);
+      $edit[$inner_title_field] = $this->randomMachineName(8);
+      $create_outer_button_selector = '//input[@type="submit" and @value="Create node" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-actions-ief-add-save"]';
+      $this->drupalPostAjaxForm(NULL, $edit, $this->getButtonName($create_outer_button_selector));
+      // After it's been created, open the form
+      $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Edit" and @data-drupal-selector="edit-ief-complex-outer-entities-' . $i . '-actions-ief-entity-edit"]'));
+    }
+    // At this point, both forms are open for the entities we created. Cancel
+    // the first, we expect the second to remain open.
+    $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-entities-0-form-actions-ief-edit-cancel"]'));
+    $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][entities][1][form][title][0][value]', '', 'Second inline edit form remained open when the first was closed.');
+
+    // Second and third assertion. In both cases, we open an edit form and the
+    // create form. We then try hitting Cancel on the edit and create in turn
+    // making sure the other remains open.
+    $create_clicks = array(TRUE, FALSE);
+    foreach ($create_clicks as $create_click) {
+      $this->drupalGet('node/add/ief_complex_simple');
+      // Create an entity.
+      $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add new node" and @data-drupal-selector="edit-ief-complex-outer-actions-ief-add"]'));
+      $edit[$outer_title_field] = $this->randomMachineName(8);
+      $edit[$inner_title_field] = $this->randomMachineName(8);
+      $create_outer_button_selector = '//input[@type="submit" and @value="Create node" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-actions-ief-add-save"]';
+      $this->drupalPostAjaxForm(NULL, $edit, $this->getButtonName($create_outer_button_selector));
+      // After it's been created, open the form
+      $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Edit" and @data-drupal-selector="edit-ief-complex-outer-entities-0-actions-ief-entity-edit"]'));
+      // Open a Create form.
+      $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add new node" and @data-drupal-selector="edit-ief-complex-outer-actions-ief-add"]'));
+      if ($create_click) {
+        $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-actions-ief-add-cancel"]'));
+        $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][entities][0][form][title][0][value]', '', 'Edit inline entity form remained open when the create inline entity form was closed.');
+      }
+      else {
+        $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Cancel" and @data-drupal-selector="edit-ief-complex-outer-form-inline-entity-form-entities-0-form-actions-ief-edit-cancel"]'));
+        $this->assertFieldByName('ief_complex_outer[form][inline_entity_form][title][0][value]', '', 'Create inline entity form remained open when the edit inline entity form was closed.');
+      }
+    }
+  }
 }
