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

Reactive statement's execution depends on order of declaration #7359

Closed
yuliankarapetkov opened this issue Mar 11, 2022 · 1 comment
Closed

Comments

@yuliankarapetkov
Copy link

yuliankarapetkov commented Mar 11, 2022

Describe the bug

Not sure if this is a bug but it is certainly something I didn't expect: reactive statements' execution depend on the order of declaration.

Here's an example which you could try out in the REPL that I provided:

<script>
	let value = 0
	let loading = true
	
	function setValue () {
		value = 5
		loading = false
	}

        //  $: if (loading) setValue() // works here
	$: squared = value ** 2
	$: if (loading) setValue() // doesn't work here

</script>

Desired output: {value ** 2} <!-- 25 -->
<br />
Actual output: {squared} <!-- 0 -->

Here Actual output will be 0 and not 25.

If I move the reactive if statement on top of the squared one, however, Actual output will be 25.

$: if (loading) setValue() // works here
$: squared = value ** 2

Why is that and is this expected behavior?

Reproduction

REPL

Logs

No response

System Info

-

Severity

annoyance

@Conduitry
Copy link
Member

This is intended. See e.g. #5190 and #5848.

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

2 participants