From f6714f677cffa2484565f51d5eb55bd34309653b Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:44:48 +0100 Subject: [PATCH] view transition's form handling honors default prevention (#9486) * add missing check to honor prevented default * added changeset * Update .changeset/fresh-games-confess.md Co-authored-by: Florian Lefebvre --------- Co-authored-by: Florian Lefebvre --- .changeset/fresh-games-confess.md | 5 +++++ packages/astro/components/ViewTransitions.astro | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/fresh-games-confess.md diff --git a/.changeset/fresh-games-confess.md b/.changeset/fresh-games-confess.md new file mode 100644 index 000000000000..fa6a0fe97ca0 --- /dev/null +++ b/.changeset/fresh-games-confess.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes View Transition's form submission prevention, allowing `preventDefault` to be used. diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 310f1865a92c..e8e12ce3d3c1 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -94,7 +94,7 @@ const { fallback = 'animate' } = Astro.props; document.addEventListener('submit', (ev) => { let el = ev.target as HTMLElement; - if (el.tagName !== 'FORM' || isReloadEl(el)) { + if (el.tagName !== 'FORM' || ev.defaultPrevented || isReloadEl(el)) { return; } const form = el as HTMLFormElement;