@@ -3,10 +3,14 @@ type Fallback = 'none' | 'animate' | 'swap';
3
3
4
4
export interface Props {
5
5
fallback? : Fallback ;
6
+ /** @deprecated handleForms is enabled by default in Astro 4.0
7
+ *
8
+ * Set `data-astro-reload` on your form to opt-out of the default behavior.
9
+ */
6
10
handleForms? : boolean ;
7
11
}
8
12
9
- const { fallback = ' animate' , handleForms } = Astro .props ;
13
+ const { fallback = ' animate' } = Astro .props ;
10
14
---
11
15
12
16
<style is:global >
@@ -25,7 +29,6 @@ const { fallback = 'animate', handleForms } = Astro.props;
25
29
</style >
26
30
<meta name =" astro-view-transitions-enabled" content =" true" />
27
31
<meta name =" astro-view-transitions-fallback" content ={ fallback } />
28
- { handleForms ? <meta name = " astro-view-transitions-forms" content = " true" /> : ' ' }
29
32
<script >
30
33
import type { Options } from 'astro:transitions/client';
31
34
import { supportsViewTransitions, navigate } from 'astro:transitions/client';
@@ -89,33 +92,31 @@ const { fallback = 'animate', handleForms } = Astro.props;
89
92
});
90
93
});
91
94
92
- if (document.querySelector('[name="astro-view-transitions-forms"]')) {
93
- document.addEventListener('submit', (ev) => {
94
- let el = ev.target as HTMLElement;
95
- if (el.tagName !== 'FORM' || isReloadEl(el)) {
96
- return;
97
- }
95
+ document.addEventListener('submit', (ev) => {
96
+ let el = ev.target as HTMLElement;
97
+ if (el.tagName !== 'FORM' || isReloadEl(el)) {
98
+ return;
99
+ }
98
100
99
- const form = el as HTMLFormElement;
100
- const submitter = ev.submitter;
101
- const formData = new FormData(form);
102
- // Use the form action, if defined, otherwise fallback to current path.
103
- let action = submitter?.getAttribute('formaction') ?? form.action ?? location.pathname;
104
- const method = submitter?.getAttribute('formmethod') ?? form.method;
101
+ const form = el as HTMLFormElement;
102
+ const submitter = ev.submitter;
103
+ const formData = new FormData(form);
104
+ // Use the form action, if defined, otherwise fallback to current path.
105
+ let action = submitter?.getAttribute('formaction') ?? form.action ?? location.pathname;
106
+ const method = submitter?.getAttribute('formmethod') ?? form.method;
105
107
106
- const options: Options = { sourceElement: submitter ?? form };
107
- if (method === 'get') {
108
- const params = new URLSearchParams(formData as any);
109
- const url = new URL(action);
110
- url.search = params.toString();
111
- action = url.toString();
112
- } else {
113
- options.formData = formData;
114
- }
115
- ev.preventDefault();
116
- navigate(action, options);
117
- });
118
- }
108
+ const options: Options = { sourceElement: submitter ?? form };
109
+ if (method === 'get') {
110
+ const params = new URLSearchParams(formData as any);
111
+ const url = new URL(action);
112
+ url.search = params.toString();
113
+ action = url.toString();
114
+ } else {
115
+ options.formData = formData;
116
+ }
117
+ ev.preventDefault();
118
+ navigate(action, options);
119
+ });
119
120
120
121
// @ts-expect-error injected by vite-plugin-transitions for treeshaking
121
122
if (!__PREFETCH_DISABLED__) {
0 commit comments