-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
breaking: avoid mutations to underlying proxied object with $state #12847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: e52d2f4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Added some unit tests, so that we can have some proper guarantees about the thornier edge cases. One of the tests is for I suspect we might have to store descriptors for every property on the |
I was going to say that we could also prevent setting a descriptor that isn't Alternatively, we put descriptors on the metadata sources. Then when retrieving value and setting value we use that descriptor. Update: I went for the first option, which we can always go back on but the performance of doing two was quite substantially worse than I originally expected. Every time we change the value, we have to create a new descriptor object for the signal, or we have two Maps of sources for the value and descriptor, but in either case I'm seeing 30-50% slower performance when using a large array and pushing in lots of values and then reading them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made one small suggestion but LGTM
One final thought before we merge this: whither <script>
let object = { count: 0 };
let proxy = $state(object);
proxy.count += 1;
</script>
<p>{object.count}</p>
<p>{proxy.count}</p>
<p>{$state.is(proxy, object)}</p> I think it might be. In a world with |
Yep let’s get rid of it |
We should probably still keep the dev time checks for |
Should we do this separately from this PR? |
I think we probably need to couple the two things, because this PR arguably breaks |
Removed |
We should have a compiler error that says that A couple of other points that just popped up: given this change, we should probably get rid of the 're-use proxy if it exists' logic, and a) stop adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rescinding approval so we don't accidentally merge until we've resolved the outstanding questions
This PR does two things:
$state.is
$state
proxies are no longer applied to the object provided to state