Skip to content

Update of $state variable overwrites it instead of update #13306

Open
@ronny-rentner

Description

@ronny-rentner

Describe the bug

Update of $state variable overwrites it instead of update when the state variable was returned by a function.

As you can see in the 2nd log line, count2 is not a state proxy anymore.

<script>
//App.svelte
	import { createStore } from './Stores.svelte.js';

	let count = $state({});
	let count2 = createStore();

	console.log('stores', count, count2);

	count = { some: 'value' };
	count2 = { some: 'value' };

	console.log('stores after', count, count2);

</script>
//Stores.svelte.js
export function createStore() {
  let store = $state({});
	return store;
}

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAA3WRTWrDMBCFrzKIghwINnhpp4WcIcu6C1cZFwVZMtIobRG6e-UfEps0aCFmnt684VNgnVToWPUemG57ZBU7DgPbM_odxsJdURGm2hlvxdg5OGHlQG-NTodkPxhLEEBYbAlPZCxChM6aHnheTLXL5yn5xfF6tikkEMZrgld4cZScWYi7eiOVSVtNzXaLVxjtjMJcma-MuymA72fLcpX3p3NEAGd6rIBfW-WRQ6xvavlM_j8J2o7QPssrihMifFrz7dDCYm_0oVgxSyx7c5adxDOryHqM-xv6Da77J1zc-gPwZ0LeeS1IGr1lBKHRACPDad9HvBbJWz2rqREf1_mIf_bmXW4VAgAA

Logs

- stores Proxy(Object) {} Proxy(Object) {}
- stores after Proxy(Object) {some: 'value'} {some: 'value'}

System Info

Svelte 5.0.0-next.251

Severity

blocking an upgrade

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