diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php
index 878967b..919e1a3 100644
--- a/core/lib/Drupal/Core/Form/FormBuilder.php
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -379,6 +379,16 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
       $form_state->setCached();
     }
 
+    // \Drupal\Component\Utility\Html::getUniqueId() maintains a cache of
+    // element IDs it has seen, so it can prevent duplicates. We want to be
+    // sure we reset that cache when a form is processed, so scenarios that
+    // result in the form being built behind the scenes and again for the
+    // browser don't increment all the element IDs needlessly.
+    if (!FormState::hasAnyErrors()) {
+      // In case of errors, do not break HTML IDs of other forms.
+      Html::resetSeenIds();
+    }
+
     // If only parts of the form will be returned to the browser (e.g., Ajax or
     // RIA clients), or if the form already had a new build ID regenerated when
     // it was retrieved from the form cache, reuse the existing #build_id.
@@ -570,16 +580,6 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
       }
       $this->formValidator->validateForm($form_id, $form, $form_state);
 
-      // \Drupal\Component\Utility\Html::getUniqueId() maintains a cache of
-      // element IDs it has seen, so it can prevent duplicates. We want to be
-      // sure we reset that cache when a form is processed, so scenarios that
-      // result in the form being built behind the scenes and again for the
-      // browser don't increment all the element IDs needlessly.
-      if (!FormState::hasAnyErrors()) {
-        // In case of errors, do not break HTML IDs of other forms.
-        Html::resetSeenIds();
-      }
-
       // If there are no errors and the form is not rebuilding, submit the form.
       if (!$form_state->isRebuilding() && !FormState::hasAnyErrors()) {
         $submit_response = $this->formSubmitter->doSubmitForm($form, $form_state);
diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
index dfbf843..69f56a0 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
@@ -501,6 +501,38 @@ public function testUniqueHtmlId() {
   }
 
   /**
+   * Tests that HTML IDs are unique when building 2 forms with the same element.
+   */
+  public function testUniqueElementHtmlId() {
+    $form_id_1 = 'test_form_id';
+    $form_id_2 = 'test_form_id_2';
+    $expected_form = $form_id_1();
+
+    // Mock 2 form objects that will be built once each.
+    $form_arg_1 = $this->getMock('Drupal\Core\Form\FormInterface');
+    $form_arg_1->expects($this->exactly(1))
+      ->method('getFormId')
+      ->will($this->returnValue($form_id_1));
+    $form_arg_1->expects($this->exactly(1))
+      ->method('buildForm')
+      ->will($this->returnValue($expected_form));
+    $form_arg_2 = $this->getMock('Drupal\Core\Form\FormInterface');
+    $form_arg_2->expects($this->exactly(1))
+      ->method('getFormId')
+      ->will($this->returnValue($form_id_2));
+    $form_arg_2->expects($this->exactly(1))
+      ->method('buildForm')
+      ->will($this->returnValue($expected_form));
+
+    $form_state = new FormState();
+    $form_1 = $this->simulateFormSubmission($form_id_1, $form_arg_1, $form_state);
+    $form_state = new FormState();
+    $form_2 = $this->simulateFormSubmission($form_id_2, $form_arg_2, $form_state);
+
+    $this->assertNotSame($form_1['actions']["#id"], $form_2['actions']["#id"]);
+  }
+
+  /**
    * Tests that a cached form is deleted after submit.
    */
   public function testFormCacheDeletionCached() {
