Skip to content

Proxy inside $state gets ignored #13915

@bskdany

Description

@bskdany

Describe the bug

Wrapping an existing Proxy with a $state and then modifying the new object doesn't trigger the inner Proxy.
I'm aware that under the hood $state is also a Proxy which might explain lots of things, but from what I've seen nested proxies are possible.

Reproduction

REPL

Code:

<svelte:options runes />

<script>
	const proxyHandler = {
		get(target, key) {
			return target[key];
		},
	
		set(target, key, value) {
			target[key] = "NOT_GETTING_SET";
			return true;
		}
	}

	const reactive = $state(new Proxy({1:"hello",2:"world"}, proxyHandler))		
	const nonReactive = new Proxy({1:"hello",2:"world"}, proxyHandler)

	reactive[1] = "a"
	console.log(reactive[1])

	nonReactive[1] = "a"
	console.log(nonReactive[1])

</script>

Logs

No response

System Info

Context same as repl

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