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

#snippet param partially loses reactivity #14982

Closed
errmayank opened this issue Jan 11, 2025 · 3 comments
Closed

#snippet param partially loses reactivity #14982

errmayank opened this issue Jan 11, 2025 · 3 comments

Comments

@errmayank
Copy link

errmayank commented Jan 11, 2025

Describe the bug

If i pass a state (from a store) as a param to a snippet and then go on to pass a value of that param to a component with $bindable prop it loses it's reactivity partially, it still reacts to state updates from outside but not if the state is updated from within the snippet

Is there a way to still keep it reactive? this doesn't happen when i do it inline without using snippet

Here's a screen recording of how the same piece of logic behaves but one uses snippet and the other is inline

402278497-f159926f-5cfe-4fda-b91d-6c6109d4bc19.mov

Reproduction

Here's a reproduction link

Logs

No response

System Info

NA

Severity

annoyance

@errmayank errmayank changed the title Snippet params loses reactivity #snippet param loses reactivity (partially) Jan 11, 2025
@errmayank errmayank changed the title #snippet param loses reactivity (partially) #snippet param partially loses reactivity Jan 11, 2025
@brunnerh
Copy link
Member

There is some compiler magic that associates the task variable with the store it comes from and makes sure to invalidate the store on change, so in the no-snippet case, this setter is generated for the progress binding:

set progress($$value) {
	(
		$.get(task).progress = $$value,
		$.invalidate_store($$stores, "$tasks") // <- invalidation causing updates
	);
}

With the snippet, there currently is no such association; only the task object is handed over. It would probably be possible to add the store association as metadata to snippets but given that rune-based reactivity is recommended over using stores (which does not have this issue), I don't know if this will be fixed...

@errmayank
Copy link
Author

ah i see, thanks for the explanation @brunnerh. i'll just use runes then

@Leonidaz
Copy link

just for posterity, yeah as per @brunnerh the store itself needs to be referenced for binding

repl

{#snippet TaskCard(task, i)}
	<div>
		<span>{task.id}</span>
		<span> - </span>
		<span>{task.title}</span>
		<span> - </span>
		<span>{task.progress.times} / {task.progress.completed}</span>
		<span> - </span>
		<CompleteButton bind:progress={$tasks.today[i].progress} />
	</div>
{/snippet}

key line: <CompleteButton bind:progress={$tasks.today[i].progress} />

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

No branches or pull requests

3 participants