diff --git a/themable_forms.module b/themable_forms.module
index 686710b52fd24f52d9e477644221ca1794289ca0..3fa8993df1e35c1e1dccd8c7de1b0c4fd54438e0 100644
--- a/themable_forms.module
+++ b/themable_forms.module
@@ -58,7 +58,7 @@ function themable_forms_preprocess_form_element(array &$variables) {
 /**
  * Implements hook_form_alter().
  */
-function themable_forms_form_alter(&$form, FormStateInterface $form_state, $form_id) {
+function themable_forms_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
   themable_forms_attach_form_id($form, $form_id);
 }
 
@@ -72,8 +72,8 @@ function themable_forms_form_alter(&$form, FormStateInterface $form_state, $form
  */
 function themable_forms_attach_form_id(array &$form, $form_id) {
   foreach (Element::children($form) as $child) {
-    if (!isset($form[$child]['#form_id'])) {
-      $form[$child]['#form_id'] = $form_id;
+    if (!isset($form[$child]['#attached']['data']['form_id'])) {
+      $form[$child]['#attached']['data']['form_id'] = $form_id;
     }
     themable_forms_attach_form_id($form[$child], $form_id);
   }