Skip to content

Svelte 5 does not call action update method when mutating arrays #10460

Closed
@isaacfink

Description

@isaacfink

Describe the bug

In this component

<script>
	let items = $state([]);

	function registerItem(item) {
		console.log(item);
	}

	export function action(node, items) {
		return {
			update: (items) => {
				console.log('got update');
				for (const item of items) {
					registerItem(item);
				}
			},
			destroy: () => {}
		};
	}

	function addItem() {
		items.push(items.length);
	}
        function addItemOldWay() {
		items = [...items, items.length]
	}
	function removeItem() {
		items.pop();
	}
</script>

<button on:click={addItem}>add item</button>
<button on:click={addItemOldWay}>add item</button>
<button on:click={removeItem}>remove item</button>

{#each items as item}
	<div>{item}</div>
{/each}

<div use:action={items}></div>

I only see logs when using the old way of assignment reactivity, since we can use push now I expected this to work in actions too, it seems like it doesn't

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE41SQW-0IBD9KxO-JtXEuHfrmvTYU489rHugMu6SKhgYN90Y_nsDaHW3TfNBoo_hzbzHwMRa2aFlxWFiivfICvY8DCxjdB38wl6wI2QZs3o0jY-UtjFyoKpWNXVIIAl7C3t4sMQJk8MxrZXfa0fVkNQKDJ6kJTQvhH3i2enk92tqtLK6w7zTpxj3YRez8XPQhuC7CA-_RGmBWZRMYaoVAED8GqTRqCXmxzgITlgsBiuYZePcij-eNM30x3Qt4EerDSSeGw8Kup3Vb4r5-fOYtwy3FnbZigVaMvpaQJLOHrfym5wI3VOt3F2DuRBBdPEUDObDaM9JhB2qE5237b3Pfe3EG7_eVoA9HPI8D3ju-VzpuFTaXnKvL_ibDT0ki3K5W9-OKt9HIq1Aq6LpZPOxn2YvruJCBL1yFznVH-zo_D9zVpeuivg-p1bTP-TNeX413AYQzloKeammsCx3HvvgtPPs0FW_D6PFIr7VfaBaV0Uyy1ivhWwlClaQGdEd3RdyNdiBfQMAAA==

Logs

No response

System Info

repl with runes

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    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