mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
fix(ViewTransition): Disables View Transition form handling when the action
property points to an external URL.(#9674) (#9693)
This commit is contained in:
parent
c7dbb9d5c0
commit
d38b2a4fe8
4 changed files with 24 additions and 1 deletions
5
.changeset/poor-cherries-buy.md
Normal file
5
.changeset/poor-cherries-buy.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Disables View Transition form handling when the `action` property points to an external URL
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue