Skip to content

Reassigning an object to a writable store using $-prefix causes its value to become a proxy in runes mode #15281

@tomoam

Description

@tomoam

Describe the bug

related #15280

When writing a Svelte component like the following in runes mode...

<script>
	import { writable } from 'svelte/store';

	let obj = writable({ name: 'foo'});

	const clone1 = structuredClone($obj); // OK
	
	$obj = { name: 'bar' };

	const clone2 = structuredClone($obj); // error
</script>

{ name: 'bar' } becomes proxied in the JS output as shown below:

	let obj = writable({ name: 'foo' });
	const clone1 = structuredClone($obj());

	$.store_set(obj, $.proxy({ name: 'bar' })); // here

	const clone2 = structuredClone($obj());

In the following cases, this issue does not occur:

  • When assigning a primitive value instead of an object
  • When using the writable store’s set method instead of the = operator
  • In non-runes mode

Reproduction

https://svelte.dev/playground/77f58c2f61394b4ca4efc5b62ea63d29?version=5.20.0

Logs

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 1.45 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm
    pnpm: 9.7.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 133.0.6943.54
    Safari: 17.6
    Safari Technology Preview: 18.2

Severity

annoyance

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