Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Form submission crashes when input has name="attributes" with View Transitions enabled (ClientRouter) #13307

Open
1 task
mauriciabad opened this issue Feb 24, 2025 · 2 comments · May be fixed by #13313
Open
1 task
Labels
- P2: has workaround Bug, but has workaround (priority) feat: view transitions Related to the View Transitions feature (scope)

Comments

@mauriciabad
Copy link

Astro Info

Astro                    v5.3.1
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When a form, using POST, with an input with name="attributes" is submitted, it crashes.

Minimal example:

---
import { ClientRouter } from 'astro:transitions';
---
<html>
  <head>
    <!-- Step 1: Enable ClientRouter -->
    <ClientRouter />
  </head>
  <body>
    <!-- Step 2: Create a form with POST method  -->
    <form method="POST">
      <!-- Step 3: Have an input with name="attributes" inside the form -->
      <input type="text" name="attributes" /> 
      <!-- Step 4: Submit the form -->
      <input type="submit" />
    </form>
  </body>
</html>

This is the error that appears on the browser console:

Uncaught (in promise) TypeError: form?.attributes.getNamedItem is not a function
    at TransitionBeforePreparationEvent.defaultLoader (router.js?v=dc710e4e:255:36)
    at doPreparation (events.js?v=dc710e4e:108:17)
    at transition (router.js?v=dc710e4e:231:27)
    at navigate (router.js?v=dc710e4e:364:9)
    at HTMLDocument.<anonymous> (ClientRouter.astro?v=dc710e4e&astro&type=script&index=0&lang.ts:71:5)

It crashes on this line:

form?.attributes.getNamedItem('enctype')?.value === 'application/x-www-form-urlencoded'

If I add an optional chaining, it works (form?.attributes.?getNamedItem(...).

This type casting is wrong, in this error the type is HTMLInputElement:

? (preparationEvent.sourceElement.form as HTMLFormElement)

What's the expected result?

It should submit the form as normal.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-o2g5gcyc?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 24, 2025
@ematipico ematipico added the feat: view transitions Related to the View Transitions feature (scope) label Feb 25, 2025
@ematipico
Copy link
Member

cc @martrapp and @matthewp for triaging

@martrapp martrapp added - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged labels Feb 25, 2025
@martrapp
Copy link
Member

Hi @mauriciabad 👋 I'm sorry that this one caught you as it is not really obvious what happens on first sight.

The form field attributes shadows the form.attributes property (a NamedNodeMap).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: view transitions Related to the View Transitions feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants