Skip to content

Commit b1d4580

Browse files
authored
fix: merge field.set(...) calls (#14651)
1 parent f3ebfec commit b1d4580

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.changeset/fresh-peaches-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: merge `field.set(...)` calls

packages/kit/src/runtime/app/server/remote/form.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ export function form(validate_or_fn, maybe_fn) {
142142
}
143143
}
144144

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 }} */
146146
const output = {};
147147

148+
// make it possible to differentiate between user submission and programmatic `field.set(...)` updates
149+
output.submission = true;
150+
148151
const { event, state } = get_request_store();
149152
const validated = await schema?.['~standard'].validate(data);
150153

@@ -211,14 +214,15 @@ export function form(validate_or_fn, maybe_fn) {
211214
() => data?.input ?? {},
212215
() => {},
213216
(path, value) => {
214-
if (data) {
217+
if (data?.submission) {
215218
// don't override a submission
216219
return;
217220
}
218221

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);
220224

221-
get_cache(__)[''] ??= { input };
225+
(get_cache(__)[''] ??= {}).input = input;
222226
},
223227
() => data?.issues ?? {}
224228
);

0 commit comments

Comments
 (0)