content icon indicating copy to clipboard operation
content copied to clipboard

Form submission causes playground iframe to lose runner state and become unusable.

Open lightning4747 opened this issue 5 months ago • 3 comments

Summary

While investigating mdn/content#44347, I noticed that the behavior appears to originate from the playground infrastructure rather than any specific example.

If a playground example contains a submittable <form>, submitting the form causes the iframe to navigate away from the rendered example. The navigation replaces the playground's required query parameters with form data, resulting in an error page and leaving the example unusable.

Related

  • mdn/content#44347

The following examples mentioned in that issue exhibit this behavior:

  • https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#updating_border_style
  • https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#examples

Reproduction

  1. Open an MDN page containing a playground example with a submittable <form>.
  2. Interact with the example and enter data into one of its form fields.
  3. Submit the form (for example, by pressing Enter while focused on a text input).
  4. Observe that the playground iframe navigates away from the rendered example and displays an error page.

Observed behavior

Before form submission, the playground iframe is loaded from a URL similar to:

.../runner.html?uuid=<uuid>&state=<state>

After form submission, the iframe navigates to:

.../runner.html?name=<value>

The original playground parameters (uuid and state) are replaced by the submitted form data.

As a result, the playground can no longer render the example:

  • Production returns 400 Bad Request.
  • Local development returns 404 Not Found.

Although the responses differ, the result is the same: the rendered example disappears and can no longer be interacted with.

Expected behavior

Submitting a form within a playground example should either prevent the default frame navigation entirely, or preserve the required uuid and state query parameters so the runner doesn't crash.

Actual behavior

Submitting a form causes the playground iframe to navigate away from its original runner.html URL. During navigation, the required playground query parameters (uuid and state) are replaced by the submitted form data. The resulting request can no longer render the example, causing the iframe to display an error page (400 Bad Request in production, 404 Not Found locally) and the rendered example disappears.

Device

Laptop

Browser

Firefox

Browser version

Stable

Operating system

Windows

Screenshot

Image

Additional notes

The examples identified in mdn/content#44347 expose this behavior, but the issue appears to affect any playground example containing a submittable form. Since the problem occurs when the playground iframe navigates away from its original runner.html URL and loses the required playground state parameters, future examples containing valid HTML forms may encounter the same issue even if current content is updated.

Validations

lightning4747 avatar Jun 04 '26 13:06 lightning4747

As the reporter of the content issue, I'll just say that:

  1. It would be nice if this were magically made a non-issue by the playground code itself. sure. (I'm still trying to work out whether I think that's actually possible, in any sort of clean way.)
  2. But at the same time, I don't think a general "don't create submittable forms in live examples" guideline for MDN content would be unduly onerous or burdensome. It feels like a workable-enough approach.

ferdnyc avatar Jun 04 '26 14:06 ferdnyc

This isn't viable to fix in playground - the web doesn't give us high-level controls around restricting form posts. While it would be possible to modify playgrounds to prevent this, this is likely to have unwanted side-effects and ideally the playground should honour the user's demands with minimal to no intervention - in other words, modifying user-provided code would be surprising.

This should be fixed in content - moving.

globau avatar Jun 08 '26 09:06 globau

Closing because it seems like a duplicate of https://github.com/mdn/content/issues/44347 if it's on content side

Josh-Cena avatar Aug 14 '26 18:08 Josh-Cena