Skip to content

Svelte 5: Values within a function inside a $effect don't trigger an effect re-run #10475

@Xeronic

Description

@Xeronic

Describe the bug

When using a setTimeout with a function containing a signal inside an effect to create a debounce effect, the timeout is not re-run when the signal is updated. Not sure if this is a bug or feature since the signal is within a function and not directly under the effects scope.

Reproduction

https://preview.vercel.app/#H4sIAAAAAAAAE1WPMWvEMAyF_4oRNyQ0cAfdQhIodO7Q3lZ18CUKNSSya8sHxfi_Fzdtc10E-t6TnpRgNgsFaF8TsF4JWnhwDhqQT1eacKVFCBoINvqxkC6M3jgZkFEWEhVI-_H9TH5VvToE0UIVAkK9G1getehb-clufLMxyhx5FGO50OmZPiIFqWqVioZSat6MB5pnGqWq6n74UQPJ2axk4z9a-F8wwguxKAR1d3PwZszN_en0fW2ukbvj_h93hl0UdTE8tVe9ROrTPp3VcUDuLn5ALttblX4TMzI0sNrJzIYmaMVHym_5C1gQArJtAQAA

<script>
	let searchTerm = $state("")
	let sentData = $state("Not sent")

	function sendRequest() {
		
	}

	$effect(()=>{
		setTimeout(()=>{
			sentData = "Sent " + searchTerm
		},300)
	})
</script>

<input bind:value={searchTerm} />
<br>
Sent: {sentData}

Logs

No response

System Info

repl is enough

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions