Open henrykrinkle01 opened 1 month ago
Here is a way that you may be able to work around this issue:
<script lang="ts">
import { superForm } from 'sveltekit-superforms';
const superform = superForm({ foo: `I'm getting logged eventhough I don't change`, bar: 0 });
const { form } = superform;
const myInspectValue = $derived($form.bar)
$effect(() => {
console.log(myInspectValue);
});
</script>
<button onclick={() => ($form.bar += 1)}> Increment </button>
{$form.bar}
That only masks the problem. It doesn't change the fact that $form.foo
also gets reassigned whenever bar
or any other properties change.
It seems like that's how stores work, and as Superforms will keep them for the next major release (as they aren't deprecated, and a rewrite would be too much work), maybe the onChange event could be an alternative.
It seems like that's how stores work, and as Superforms will keep them for the next major release (as they aren't deprecated, and a rewrite would be too much work), maybe the onChange event could be an alternative.
@ciscoheat
Speaking of which, anyone knows if onBlur
event will be added soon?
Just added the proposal/necessity: https://github.com/ciscoheat/sveltekit-superforms/issues/504
I also ran into this while trying to do reactive field updates - this is a known breaking change in svelte 5 per https://github.com/sveltejs/svelte/issues/14306
Description Currently I'm using superforms with Svelte 5 just fine. However, when I use $effect or some reactive code on a field input value, it will trigger on every other field updates. I guess because for Svelte 4 reactivity to work, the whole form store must be reassigned. Svelte 5 reactivity is fine grained so it doesn't trigger unnecessary reactions, so this is kind of unexpected when using Svelte 5. Honestly I don't think this is a bug because it's just the way Svelte 4 works. I also don't think this can be easily fixed without migrating the library from using stores to runes. However, @ciscoheat told me to open an issue so here I am.
If applicable, a MRE https://www.sveltelab.dev/fxpfuy1f7nhvp8t