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

Invalidating functions cannot be declared as @const #7843

Closed
brunnerh opened this issue Sep 7, 2022 · 1 comment · Fixed by #7858
Closed

Invalidating functions cannot be declared as @const #7843

brunnerh opened this issue Sep 7, 2022 · 1 comment · Fixed by #7858

Comments

@brunnerh
Copy link
Member

brunnerh commented Sep 7, 2022

Describe the bug

If a function is defined via @const that causes invalidation of state, this will throw an error because $$invalidate will not be in scope.

Possibly a known/intended limitation.

Reproduction

<script>
	let items = [
		{ name: 'A', selected: true },
		{ name: 'B', selected: false },
		{ name: 'C', selected: false },
	]
</script>

{#each items as item}
	{@const toggle = () => item.selected = !item.selected}
	<div>
		{item.selected ? '' : ''}
		{item.name}
		<button on:click={toggle}>Toggle</button>
	</div>
{/each}

REPL

Logs

Uncaught ReferenceError: $$invalidate is not defined
    at HTMLButtonElement.constants_0 (eval at handle_message (about:srcdoc:14:8), <anonymous>:389:32)
    at HTMLButtonElement.eval (eval at handle_message (about:srcdoc:14:8), <anonymous>:435:65)

System Info

REPL / Chrome & Firefox

Severity

annoyance

@Conduitry
Copy link
Member

This should be fixed in 3.54.0 - https://svelte.dev/repl/fc201eac554e4ef89256a46e49efdee2?version=3.54.0

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

Successfully merging a pull request may close this issue.

2 participants