Skip to content

using $inspect() or $effect() causes strange behavior #10567

Closed
@dangelomedinag

Description

@dangelomedinag

Describe the bug

  • if uncomment $effect() or $inpect() counter.count not update
<script>
	let counter = $state({ 
		count: 0,
		increment(){this.count += 1},
	});

	/* Any of the following lines breaks the updates */
	// $effect(() => { console.log(counter) }); 
	// $inspect(counter) 
</script>

<button onclick={counter.increment}>
	clicks: {counter.count}
</button>
  • The following fragment causes a loop when invoking increment
<script>
	let counter = $state({ 
		count: 0,
		increment: () => {
			this.count += 1; /* `this` is undefined obviously */
		},
	});
</script>

<button onclick={counter.increment}>
	clicks: {counter.count}
</button>

clicking causes a loop

Reproduction

link1

link2

Logs

No response

System Info

(Svelte v5.0.0-next.60)

Severity

annoyance

Metadata

Metadata

Assignees

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