Skip to content

Proxys inside $state don't work #15175

@GuillaumeDerval

Description

@GuillaumeDerval

Describe the bug

Proxys are somehow ignored once they are inside a $state.

This occurs both on Proxies being directly $stated (as shown below) but also on proxies that are deeply nested somewhere inside an object (a more useful usecase :-))

Reproduction

Playground link: https://svelte.dev/playground/78baf2231a9647d09b52743fe53b8437?version=5.19.6.

<script>
	let thing = {
		entry: "one"
	}

	let proxyThing = new Proxy(thing, {
		set(target, prop, value) {
				console.log("set", prop, value);
				return Reflect.set(...arguments);
		}
	})

	proxyThing.entry = "two"
	
	let stateProxyThing = $state(proxyThing)

	stateProxyThing.entry = "three";
</script>

<input type=text bind:value={stateProxyThing.entry}/>

Current behavior:

  • Log (in console) set entry two
  • "three" appears in the input field

Expected:

  • Log (in console) set entry two
  • Log set entry three
  • "three" appears in the input field
  • When the input field is modified set entry X appears in the console, with X the new content of the field

Logs

System Info

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 102.95 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.6.1 - /opt/homebrew/bin/node
    npm: 10.9.2 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 132.0.6834.160
    Safari: 18.2
  npmPackages:
    svelte: ^5.7 => 5.19.6

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions