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

compile error when reactive statement will never change #8309

Closed
DetachHead opened this issue Feb 22, 2023 · 2 comments
Closed

compile error when reactive statement will never change #8309

DetachHead opened this issue Feb 22, 2023 · 2 comments

Comments

@DetachHead
Copy link

Describe the problem

<script>
	let _value = ''
	$: value = getValue()
	
	const getValue = () => _value
</script>

<input bind: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

@baseballyama
Copy link
Member

Previously, we discussed this point.

#7942 (comment)

@dummdidumm
Copy link
Member

From that comment:

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>
  export const foo = 1;
  export const bar = 1;
  export const baz = 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>

Therefore closing

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants