Skip to content

Commit 28bdd51

Browse files
committed
FIxed tainted issue with the #164 fix.
1 parent ff5b640 commit 28bdd51

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/lib/client/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -423,17 +423,15 @@ export function superForm<
423423
value: Parameters<typeof _formData.set>[0],
424424
options: { taint?: TaintOption<UnwrappedT> } = {}
425425
) => {
426-
// Need to clone the value, so it won't refer
427-
// to $page for example.
428-
const newValue = clone(value);
429-
430426
Tainted_update(
431-
newValue,
427+
value,
432428
Context.taintedFormState,
433429
options.taint ?? true
434430
);
435-
Context.taintedFormState = newValue;
436-
return _formData.set(newValue);
431+
432+
Context_setTaintedFormState(value);
433+
// Need to clone the value, so it won't refer to $page for example.
434+
return _formData.set(clone(value));
437435
},
438436
update: (
439437
updater: Parameters<typeof _formData.update>[0],
@@ -446,7 +444,9 @@ export function superForm<
446444
Context.taintedFormState,
447445
options.taint ?? true
448446
);
449-
Context.taintedFormState = clone(value);
447+
448+
Context_setTaintedFormState(output);
449+
// No cloning here, since it's an update
450450
return output;
451451
});
452452
}
@@ -797,12 +797,6 @@ export function superForm<
797797
page.subscribe(async (pageUpdate) => {
798798
if (!options.applyAction) return;
799799

800-
function error(type: string) {
801-
throw new SuperFormError(
802-
`No form data found in ${type}. Make sure you return { form } in form actions and load functions.`
803-
);
804-
}
805-
806800
const untaint = pageUpdate.status >= 200 && pageUpdate.status < 300;
807801

808802
if (pageUpdate.form && typeof pageUpdate.form === 'object') {

src/routes/nested-validation/+page.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ Superforms validate:
3939
</pre>
4040

4141
<pre style="margin-top:3rem;">
42-
Zod full validation:
43-
{#if validated}{JSON.stringify(validated, null, 2)}{/if}
42+
Zod full validation:
43+
{#if validated}{JSON.stringify(validated, null, 2)}{/if}
4444
</pre>
4545

4646
<pre style="margin-top:3rem;">
47-
Superforms full validation:
48-
{#if validated2}{JSON.stringify(validated2, null, 2)}{/if}
47+
Superforms full validation:
48+
{#if validated2}{JSON.stringify(validated2, null, 2)}{/if}
4949
</pre>
5050

5151
<style>

src/routes/nested-validation/TagForm.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import type { SuperValidated, UnwrapEffects } from '$lib';
2+
import type { SuperValidated } from '$lib';
33
import { page } from '$app/stores';
44
import { superForm } from '$lib/client';
55
import type { FormOptions } from '$lib/client';

0 commit comments

Comments
 (0)