Skip to content

Commit

Permalink
Merge pull request #110 from withastro/main
Browse files Browse the repository at this point in the history
fix(ViewTransition): Disables View Transition form handling when the …
  • Loading branch information
akshit20421 authored Jan 15, 2024
2 parents 5a931f2 + d38b2a4 commit 06c1f30
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/poor-cherries-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Disables View Transition form handling when the `action` property points to an external URL
4 changes: 3 additions & 1 deletion packages/astro/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ const { fallback = 'animate' } = Astro.props;

// the "dialog" method is a special keyword used within <dialog> elements
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method
if (method === 'dialog') {
if (method === 'dialog' || location.origin !== new URL(action, location.href).origin) {
// No page transitions in these cases,
// Let the browser standard action handle this
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
import Layout from '../components/Layout.astro';
---
<Layout>
<form action="https://example.com/" method="POST">
<button id="submit">Submit</button>
</form>
</Layout>
7 changes: 7 additions & 0 deletions packages/astro/e2e/view-transitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,13 @@ test.describe('View Transitions', () => {
).toEqual(1);
});

test('form POST that action for cross-origin is opt-out', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/form-five'));
page.on('request', (request) => expect(request.method()).toBe('POST'));
// Submit the form
await page.click('#submit');
});

test('form GET that redirects to another page is handled', async ({ page, astro }) => {
const loads = [];
page.addListener('load', async (p) => {
Expand Down

0 comments on commit 06c1f30

Please sign in to comment.