Skip to content

Svelte 5: The $derived rune of type boolean, does not trigger the $effect rune. #9489

@e-is-me-squared

Description

@e-is-me-squared

Describe the bug

When referencing a $derived rune from a class instance in the $effect rune. The effect is not triggered, on change, when that value is a boolean.

Reproduction

<script>
	import {someLogic} from './SomeLogic.svelte';
	function increment() {
		someLogic.trigger();
	}

	let lokalDerived = $derived(someLogic.someValue > 3);

	$effect(() => {
		console.log(someLogic.someValue);
	});
	$effect(() => {
		// Does not trigger
		console.log('class trigger', someLogic.isAboveThree)
	});
	$effect(() => {
		// Does Triggers
		console.log('lokal trigger', lokalDerived)
	});
	
</script>

<button on:click={increment}>
	clicks: {someLogic.someValue}
	
	<!-- Adding this line below, will make the effect above trigger as i should -->
	<!-- has clicked more then 3 times {someLogic.isAboveThree} -->
</button>
class SomeLogic {
	someValue = $state(0);
	isAboveThree = $derived(this.someValue > 3)
	trigger(){
		this.someValue++;
	}
}

export const someLogic = new SomeLogic();

REPL: Tap the clicks button 4 times and have a look at the log.

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions