-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Reactivity in lists only in the updated element #8
Comments
Also if the items of the list are web components they are losing the state (disconnecting and connecting) when the list is updated |
According to Ryan Carniato there is no choice but to use reconciliation to solve this. So this means reuse https://github.com/aralroca/diff-dom-streaming ? It would be great to find an alternative to add this code, right now it loads in a lazy way for server actions... Adding it when loading the page would go from occupying 3kb to occupy 5kb... The benefit that then it would not be necessary to load it in a lazy way, but it is already 2kb approx to solve the lists... Let's see if we find a better way. |
Good news, this should solve the problem with lists and signals: https://twitter.com/aralroca/status/1790730464640033008 The bad part is that you have to wait for browsers to support it, but it looks good. Code example: https://github.com/bigskysoftware/chrome-movebefore-demo More demos: |
Array signals: https://github.com/proposal-signals/signal-utils?tab=readme-ov-file#array |
Example of moveBefore: const moveOrInsertNode = (container, node, ref_node = null) => {
const canMove = (container.isConnected && node.isConnected && (!ref_node || ref_node.parentNode === container);
return canMove ? container.moveBefore(node, ref_node) : container.insertBefore(node, ref_node);
} |
We can also investigate how Svelte 5 is rendering lists with fine grained reactivity with array.push() https://svelte.dev/docs/svelte/$state#Deep-state |
It looks like Svelte is using a proxy. Using a proxy is another solution, not the best for performance but another one |
I think there is not a huge performance difference otherwise Svelte/Vue teams have not opted for it. I will go for proxy for much better DX then what we currently have list.value = [...list.value, formData.get('item') as string] VS let todos = $state([
{
done: false,
text: 'add more todos'
}
]);
todos[0].done = !todos[0].done;
todos.push({
done: false,
text: 'eat lunch'
}); |
This issue happens in a web component with a list with a signal, whenever the list is updated, instead of affecting only the modified field, the whole list is updated. It goes well anyway, but it would be an optimization to do.
Example of Component to reproduce it:
The text was updated successfully, but these errors were encountered: