-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
breaking: remove unstate(), replace with $state.snapshot rune #11180
Conversation
🦋 Changeset detectedLatest commit: 8ff9cce 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 |
sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
Outdated
Show resolved
Hide resolved
Is the name set in stone? So it's not really "cleaning", as much as "maybe-get-raw-value-from-signal"-ing. Or, more succinctly, |
The naming for |
Definitely open to alternative naming. As mentioned Thinking about it further, I wonder if we actually need a shallow version. Where would that be useful? Certainly not in the |
Yeah I can't really imagine a case where you would want a shallow version. If we promise to deeply unwrap it, does this shift the expection to somehow transform classes with state objects on them, too? How would we do that if we are able to? We can't just create a POJO from a class, but we also can't reinstantiate a class. Is there some contract we need to define, i.e. "define this method and we'll call that to get the raw value"? |
I have the same issue with I don't really like Maybe |
I was trying to convey this in this comment, but it didn't seem there was much interest. I was going to comment about this in #10560, in response to this. This is actually a pretty fundamental collection of issues, in my opinion. The whole idea of transferring between the Svelte world and not is really tricky and a bit inconsistent, currently. I think it's really important to get it correct. I think some sort of contract that But I feel like I'm repeating myself and I'm not sure if this is what y'all are interested in. I'm still messing around with the idea, but maybe it's not right for Svelte. |
I renamed to rune to |
Yes, but it does stop too early when there's a POJO at first - this was the concern about not doing the whole thing deeply. |
@dummdidumm That's fine – most state is deep state and so things will just work. I really don't want us to deeply traverse every object, it's slow and a waste of CPU cycles as shown from all the DEV ownership stuff. It's just not a good strategy for something that isn't DEV only. We use this logic in |
...which is why I was advocating for a second optional parameter to deeply traverse the whole object. There's code where you just don't know in advance whether or not you're going to encounter proxied state at some point. sveltejs/kit#12095 is such an example, where we have to traverse the whole history state object to remove any proxy state before handing it to the deserializer |
@dummdidumm I really don't want us to introduce a deep traverse from other objects – even with a second argument. It's very expensive to do and people will just run into performance issues, leading us to revert the change. If we are traversing other objects, it means we will also need to clone them too! Deep cloning this way is terribly expensive, which is why Worst case, if we traverse and clone a really big object to not find state in it, then we've just wasted many CPU cycles. |
We're already doing deep traversal ourselves internally in the code base here, and if we can't find a different solution to the deserialization problem in SvelteKit we'll have it there, too - so in the end we and others just reimplement it themselves where necessary anyway, with the same potentially imperformant outcome. |
We're not also cloning though. Deep cloning is the issue. If we need to have deep cloning, then we need to rearchitect how we proxy state today to not use the symbol property. |
FWIW I think sveltejs/kit#12095 is probably a bad example — I think we're looking at it from the wrong angle. Commented on that thread. |
I'm good with us not recursing into POJOs, as long as we've considered it and we're doing it on a principled basis. I do think we should handle classes-with-state-fields and |
Renamed to |
This PR removes
unstate
and replaces it with a new rune called$state.snapshot
which works identically to how unstate worked. Closes #10421