You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<script>
let _value ='' $: value =getValue()constgetValue= () => _value
</script>
<inputbind:value={_value}>
<p>value: {value}</p>
here, the $: is being used incorrectly as it will not be re-run when _value changes, because there are no variables that will change being referenced
when learning svelte, i ran into issues like this several times, so i think there should be a compiler error/warning when reactive statements are used incorrectly like this
Describe the proposed solution
a compiler error/warning if all of the variables referenced in a reactive statement are immutable
Alternatives considered
eslint-plugin-svelte rule, but i think this would be better handled by the svelte compiler because it's first party
Importance
would make my life easier
The text was updated successfully, but these errors were encountered:
We discussed with maintainers and concution is that we should not implement warnings because the compiler might analyse that it's unnecessary, but the user might have this deliberately:
e.g.
<script>
exportconstfoo=1;exportconstbar=1;exportconstbaz=1;// For now, all dependencies are static, but maybe in the future, one or more variables will be dynamic.// So intentionally, people could use `$:` here to prevent a bug later $: qux = foo + bar + baz;
</script>
Describe the problem
here, the
$:
is being used incorrectly as it will not be re-run when_value
changes, because there are no variables that will change being referencedwhen learning svelte, i ran into issues like this several times, so i think there should be a compiler error/warning when reactive statements are used incorrectly like this
Describe the proposed solution
a compiler error/warning if all of the variables referenced in a reactive statement are immutable
Alternatives considered
eslint-plugin-svelte
rule, but i think this would be better handled by the svelte compiler because it's first partyImportance
would make my life easier
The text was updated successfully, but these errors were encountered: