Skip to content

Changes on mirror value doesn't trigger reactivity #7730

@aguspdana

Description

@aguspdana

Describe the bug

When a mirrored value changes through a reactivity to another value, it doesn't trigger further reactivity on blocks that depend on it or components that indirectly depend on it.

Reproduction

<script>
	let source = 0;
	let mirror = 0;
	$: isMirrorZero = mirror === 0;

	// Changes on mirror doesn't trigger this block when it's changed by syncMirror.
	$: {
		const id = Math.floor(Math.random() * 100);
		console.log(`${id}. source: ${source}; mirror: ${mirror}`)
		setTimeout(() => {console.log(`${id}. mirror later: ${mirror}`)}, 1)
	}
	
	$: syncMirror(source);
	
	function syncMirror(s) {
		if (mirror !== s) {
			mirror = s;
		}
	}

	function handleClick() {
		source++
	}
</script>

<button on:click={handleClick}>
	Source: {source}
</button>
<p>
	Mirror: {mirror}
</p>

{#if isMirrorZero}
	<p>
		This should not appear when mirror is not zero
	</p>
{/if}

Logs

No response

System Info

Repl

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions