Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No fine-grained reactivity #490

Open
henrykrinkle01 opened this issue Oct 23, 2024 · 5 comments
Open

No fine-grained reactivity #490

henrykrinkle01 opened this issue Oct 23, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation svelte-5 Related to Svelte 5

Comments

@henrykrinkle01
Copy link

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

@henrykrinkle01 henrykrinkle01 added the bug Something isn't working label Oct 23, 2024
@s-petey
Copy link

s-petey commented Oct 30, 2024

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}

@henrykrinkle01
Copy link
Author

That only masks the problem. It doesn't change the fact that $form.foo also gets reassigned whenever bar or any other properties change.

@ciscoheat
Copy link
Owner

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 ciscoheat added documentation Improvements or additions to documentation svelte-5 Related to Svelte 5 and removed bug Something isn't working labels Nov 1, 2024
@holdmybeer30
Copy link

holdmybeer30 commented Nov 5, 2024

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: #504

@fnimick
Copy link

fnimick commented Nov 15, 2024

I also ran into this while trying to do reactive field updates - this is a known breaking change in svelte 5 per sveltejs/svelte#14306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation svelte-5 Related to Svelte 5
Projects
None yet
Development

No branches or pull requests

5 participants