diff options
author | 2025-02-26 11:55:01 +0100 | |
---|---|---|
committer | 2025-02-26 10:55:01 +0000 | |
commit | 9e7c71d19c89407d9b27ded85d8c0fde238ce16c (patch) | |
tree | 54a211c285b8029b7a8b4e98e6209b8a51f43cba | |
parent | 2cdeaea64c847fb927f4c93ae62271057236a55d (diff) | |
download | astro-9e7c71d19c89407d9b27ded85d8c0fde238ce16c.tar.gz astro-9e7c71d19c89407d9b27ded85d8c0fde238ce16c.tar.zst astro-9e7c71d19c89407d9b27ded85d8c0fde238ce16c.zip |
fixes property shadowing for form.attributes (#13313)
Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com>
-rw-r--r-- | .changeset/purple-jokes-pay.md | 5 | ||||
-rw-r--r-- | packages/astro/e2e/fixtures/view-transitions/src/pages/form-one.astro | 1 | ||||
-rw-r--r-- | packages/astro/src/transitions/router.ts | 3 |
3 files changed, 7 insertions, 2 deletions
diff --git a/.changeset/purple-jokes-pay.md b/.changeset/purple-jokes-pay.md new file mode 100644 index 000000000..ddb641371 --- /dev/null +++ b/.changeset/purple-jokes-pay.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where a form field named "attributes" shadows the form.attributes property. diff --git a/packages/astro/e2e/fixtures/view-transitions/src/pages/form-one.astro b/packages/astro/e2e/fixtures/view-transitions/src/pages/form-one.astro index ca5e4cb82..21ac979ff 100644 --- a/packages/astro/e2e/fixtures/view-transitions/src/pages/form-one.astro +++ b/packages/astro/e2e/fixtures/view-transitions/src/pages/form-one.astro @@ -12,5 +12,6 @@ export const prerender = false; <input type="hidden" name="name" value="Testing" /> {postShowThrow ? <input type="hidden" name="throw" value="true" /> : ''} <input type="submit" value="Submit" id="submit" /> + <input type="text" name="attributes" /> </form> </Layout> diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index 925aab0a6..5dc327cf4 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -397,8 +397,7 @@ async function transition( // // Note: getNamedItem can return null in real life, even if TypeScript doesn't think so, hence // the ?. - init.body = - form?.attributes.getNamedItem('enctype')?.value === 'application/x-www-form-urlencoded' + init.body = (from !== undefined && Reflect.get(HTMLFormElement.prototype, "attributes", form).getNamedItem('enctype')?.value === 'application/x-www-form-urlencoded') ? new URLSearchParams(preparationEvent.formData as any) : preparationEvent.formData; } |