@sveltejs/kit 2.5.17 → 2.5.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/runtime/app/forms.js +28 -7
- package/src/utils/filesystem.js +1 -1
- package/src/version.js +1 -1
- package/types/index.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.18",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"svelte": "^4.2.10",
|
|
44
44
|
"svelte-preprocess": "^6.0.0",
|
|
45
45
|
"typescript": "^5.3.3",
|
|
46
|
-
"vite": "^5.2
|
|
46
|
+
"vite": "^5.3.2",
|
|
47
47
|
"vitest": "^1.6.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -56,7 +56,7 @@ function clone(element) {
|
|
|
56
56
|
* If nothing is returned, the fallback will be used.
|
|
57
57
|
*
|
|
58
58
|
* If this function or its return value isn't set, it
|
|
59
|
-
* - falls back to updating the `form` prop with the returned data if the action is
|
|
59
|
+
* - falls back to updating the `form` prop with the returned data if the action is on the same page as the form
|
|
60
60
|
* - updates `$page.status`
|
|
61
61
|
* - resets the `<form>` element and invalidates all data in case of successful submission with no redirect response
|
|
62
62
|
* - redirects in case of a redirect response
|
|
@@ -124,9 +124,13 @@ export function enhance(form_element, submit = () => {}) {
|
|
|
124
124
|
: clone(form_element).action
|
|
125
125
|
);
|
|
126
126
|
|
|
127
|
+
const enctype = event.submitter?.hasAttribute('formenctype')
|
|
128
|
+
? /** @type {HTMLButtonElement | HTMLInputElement} */ (event.submitter).formEnctype
|
|
129
|
+
: clone(form_element).enctype;
|
|
130
|
+
|
|
127
131
|
const form_data = new FormData(form_element);
|
|
128
132
|
|
|
129
|
-
if (DEV &&
|
|
133
|
+
if (DEV && enctype !== 'multipart/form-data') {
|
|
130
134
|
for (const value of form_data.values()) {
|
|
131
135
|
if (value instanceof File) {
|
|
132
136
|
throw new Error(
|
|
@@ -161,14 +165,31 @@ export function enhance(form_element, submit = () => {}) {
|
|
|
161
165
|
let result;
|
|
162
166
|
|
|
163
167
|
try {
|
|
168
|
+
const headers = new Headers({
|
|
169
|
+
accept: 'application/json',
|
|
170
|
+
'x-sveltekit-action': 'true'
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// do not explicitly set the `Content-Type` header when sending `FormData`
|
|
174
|
+
// or else it will interfere with the browser's header setting
|
|
175
|
+
// see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects#sect4
|
|
176
|
+
if (enctype !== 'multipart/form-data') {
|
|
177
|
+
headers.set(
|
|
178
|
+
'Content-Type',
|
|
179
|
+
/^(:?application\/x-www-form-urlencoded|text\/plain)$/.test(enctype)
|
|
180
|
+
? enctype
|
|
181
|
+
: 'application/x-www-form-urlencoded'
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// @ts-expect-error `URLSearchParams(form_data)` is kosher, but typescript doesn't know that
|
|
186
|
+
const body = enctype === 'multipart/form-data' ? form_data : new URLSearchParams(form_data);
|
|
187
|
+
|
|
164
188
|
const response = await fetch(action, {
|
|
165
189
|
method: 'POST',
|
|
166
|
-
headers
|
|
167
|
-
accept: 'application/json',
|
|
168
|
-
'x-sveltekit-action': 'true'
|
|
169
|
-
},
|
|
190
|
+
headers,
|
|
170
191
|
cache: 'no-store',
|
|
171
|
-
body
|
|
192
|
+
body,
|
|
172
193
|
signal: controller.signal
|
|
173
194
|
});
|
|
174
195
|
|
package/src/utils/filesystem.js
CHANGED
|
@@ -181,7 +181,7 @@ export function resolve_entry(entry) {
|
|
|
181
181
|
const base = path.basename(entry);
|
|
182
182
|
const files = fs.readdirSync(dir);
|
|
183
183
|
|
|
184
|
-
const found = files.find((file) => file.replace(/\.
|
|
184
|
+
const found = files.find((file) => file.replace(/\.(js|ts)$/, '') === base);
|
|
185
185
|
|
|
186
186
|
if (found) return path.join(dir, found);
|
|
187
187
|
}
|
package/src/version.js
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1999,7 +1999,7 @@ declare module '$app/forms' {
|
|
|
1999
1999
|
* If nothing is returned, the fallback will be used.
|
|
2000
2000
|
*
|
|
2001
2001
|
* If this function or its return value isn't set, it
|
|
2002
|
-
* - falls back to updating the `form` prop with the returned data if the action is
|
|
2002
|
+
* - falls back to updating the `form` prop with the returned data if the action is on the same page as the form
|
|
2003
2003
|
* - updates `$page.status`
|
|
2004
2004
|
* - resets the `<form>` element and invalidates all data in case of successful submission with no redirect response
|
|
2005
2005
|
* - redirects in case of a redirect response
|