swc-project/swc · error · Error

FormWhenFormOpen

FormWhenFormOpen

Error message

Saw a "form" start tag, but there was already an active "form" element, nested forms are not allowed

What it means

HTML parse error: a <form> start tag was encountered while the form element pointer is already set (an active open form exists), and nested forms are disallowed. Per spec the error is recorded and the new form element is inserted but the form pointer is left unchanged (except inside template).

Source

Thrown at crates/swc_html_parser/src/parser/mod.rs:2864

                    //
                    // Otherwise:
                    //
                    // If the stack of open elements has a p element in button scope, then close a p
                    // element.
                    //
                    // Insert an HTML element for the token, and, if there is no template element on
                    // the stack of open elements, set the form element pointer to point to the
                    // element created.
                    Token::StartTag {
                        tag_name,
                        is_self_closing,
                        ..
                    } if tag_name == "form" => {
                        if self.form_element_pointer.is_some()
                            && !self.open_elements_stack.contains_template_element()
                        {
                            self.errors
                                .push(Error::new(token_and_info.span, ErrorKind::FormWhenFormOpen));

                            return Ok(());
                        }

                        if self.open_elements_stack.has_in_button_scope("p") {
                            self.close_p_element(token_and_info, false);
                        }

                        let element = self.insert_html_element(token_and_info)?;

                        if !self.open_elements_stack.contains_template_element() {
                            self.form_element_pointer = Some(element);
                        }

                        maybe_allow_self_closing!(is_self_closing, tag_name);
                    }
                    // A start tag whose tag name is "li"
                    //

View on GitHub (pinned to 5176682b65)

Solutions

  1. Close the outer <form> before opening another
  2. Replace nesting with sibling forms or use a different container
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:2864 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/a965af1958592669. Report an issue: GitHub.