Skip to content

Commit d38b2a4

Browse files
authoredJan 15, 2024
fix(ViewTransition): Disables View Transition form handling when the action property points to an external URL.(#9674) (#9693)
1 parent c7dbb9d commit d38b2a4

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed
 

‎.changeset/poor-cherries-buy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Disables View Transition form handling when the `action` property points to an external URL

‎packages/astro/components/ViewTransitions.astro

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ const { fallback = 'animate' } = Astro.props;
109109

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
import Layout from '../components/Layout.astro';
3+
4+
---
5+
<Layout>
6+
<form action="https://example.com/" method="POST">
7+
<button id="submit">Submit</button>
8+
</form>
9+
</Layout>

‎packages/astro/e2e/view-transitions.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,13 @@ test.describe('View Transitions', () => {
932932
).toEqual(1);
933933
});
934934

935+
test('form POST that action for cross-origin is opt-out', async ({ page, astro }) => {
936+
await page.goto(astro.resolveUrl('/form-five'));
937+
page.on('request', (request) => expect(request.method()).toBe('POST'));
938+
// Submit the form
939+
await page.click('#submit');
940+
});
941+
935942
test('form GET that redirects to another page is handled', async ({ page, astro }) => {
936943
const loads = [];
937944
page.addListener('load', async (p) => {

0 commit comments

Comments
 (0)
Please sign in to comment.