@sveltejs/kit 2.46.2 → 2.46.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.46.2",
3
+ "version": "2.46.3",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -142,9 +142,12 @@ export function form(validate_or_fn, maybe_fn) {
142
142
  }
143
143
  }
144
144
 
145
- /** @type {{ input?: Record<string, any>, issues?: Record<string, InternalRemoteFormIssue[]>, result: Output }} */
145
+ /** @type {{ submission: true, input?: Record<string, any>, issues?: Record<string, InternalRemoteFormIssue[]>, result: Output }} */
146
146
  const output = {};
147
147
 
148
+ // make it possible to differentiate between user submission and programmatic `field.set(...)` updates
149
+ output.submission = true;
150
+
148
151
  const { event, state } = get_request_store();
149
152
  const validated = await schema?.['~standard'].validate(data);
150
153
 
@@ -211,14 +214,15 @@ export function form(validate_or_fn, maybe_fn) {
211
214
  () => data?.input ?? {},
212
215
  () => {},
213
216
  (path, value) => {
214
- if (data) {
217
+ if (data?.submission) {
215
218
  // don't override a submission
216
219
  return;
217
220
  }
218
221
 
219
- const input = path.length === 0 ? value : deep_set({}, path.map(String), value);
222
+ const input =
223
+ path.length === 0 ? value : deep_set(data?.input ?? {}, path.map(String), value);
220
224
 
221
- get_cache(__)[''] ??= { input };
225
+ (get_cache(__)[''] ??= {}).input = input;
222
226
  },
223
227
  () => data?.issues ?? {}
224
228
  );
@@ -71,6 +71,12 @@ export function form(id) {
71
71
  */
72
72
  const versions = $state({});
73
73
 
74
+ /**
75
+ * This ensures that `{field.value()}` is updated even if the version hasn't been initialized
76
+ * @type {Set<string>}
77
+ */
78
+ const version_reads = new Set();
79
+
74
80
  /** @type {Record<string, InternalRemoteFormIssue[]>} */
75
81
  let issues = $state.raw({});
76
82
 
@@ -91,6 +97,16 @@ export function form(id) {
91
97
 
92
98
  let submitted = false;
93
99
 
100
+ function update_all_versions() {
101
+ for (const path of version_reads) {
102
+ versions[path] ??= 0;
103
+ }
104
+
105
+ for (const key of Object.keys(versions)) {
106
+ versions[key] += 1;
107
+ }
108
+ }
109
+
94
110
  /**
95
111
  * @param {FormData} form_data
96
112
  * @returns {Record<string, any>}
@@ -219,14 +235,7 @@ export function form(id) {
219
235
  if (issues.$) {
220
236
  release_overrides(updates);
221
237
  } else {
222
- input = {};
223
-
224
- for (const [key, value] of Object.entries(versions)) {
225
- if (value !== undefined) {
226
- versions[key] ??= 0;
227
- versions[key] += 1;
228
- }
229
- }
238
+ update_all_versions();
230
239
 
231
240
  if (form_result.refreshes) {
232
241
  refresh_queries(form_result.refreshes, updates);
@@ -407,6 +416,8 @@ export function form(id) {
407
416
  );
408
417
  }
409
418
 
419
+ name = name.replace(/^[nb]:/, '');
420
+
410
421
  versions[name] ??= 0;
411
422
  versions[name] += 1;
412
423
 
@@ -420,6 +431,15 @@ export function form(id) {
420
431
  }
421
432
  });
422
433
 
434
+ form.addEventListener('reset', async () => {
435
+ // need to wait a moment, because the `reset` event occurs before
436
+ // the inputs are actually updated (so that it can be cancelled)
437
+ await tick();
438
+
439
+ input = convert_formdata(new FormData(form));
440
+ update_all_versions();
441
+ });
442
+
423
443
  return () => {
424
444
  element = null;
425
445
  preflight_schema = undefined;
@@ -510,7 +530,10 @@ export function form(id) {
510
530
  create_field_proxy(
511
531
  {},
512
532
  () => input,
513
- (path) => versions[path],
533
+ (path) => {
534
+ version_reads.add(path);
535
+ versions[path];
536
+ },
514
537
  (path, value) => {
515
538
  if (path.length === 0) {
516
539
  input = value;
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.46.2';
4
+ export const VERSION = '2.46.3';