-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
fix: ensure $state.snapshot
never errors
#12445
Conversation
Snapshotting can error on un-cloneable objects. It's not practical to error in this case; often there's no way out of this for users, so it makes sense to return the original value in that case, and warn in dev mode about it. closes #12438
🦋 Changeset detectedLatest commit: faf89f7 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 |
I'm not sure we want to return the original value. If I snapshot something and then pass that on to somewhere with the expectation that it's a snapshot of the original, I would be horrified if it somehow wasn't. If anything, we should throw an error explaining that the snapshot failed due to a specific reason. The problem is that this API then becomes less useful, hmm. However, I don't think we should be using structuredClone for $inspect at all. That seems wrong. |
If you error on |
@dummdidumm You'd still error, as the snapshot would just return the original value in the case it errors, meaning the |
|
I think this is probably a pragmatic thing to do. Though the text of the warning is arguably a little confusing — to me it suggests that the const value = {
a: () => {},
b: () => {},
c: () => {}
}; ...you get three separate warnings. It's not necessarily obvious which properties were uncloneable. So even though it's probably a bit more work, I wonder if we should track those properties and issue a single warning per
Of course if the argument itself can't be cloned, we probably want something more like this:
|
Snapshotting can error on un-cloneable objects. It's not practical to error in this case; often there's no way out of this for users, so it makes sense to return the original value in that case, and warn in dev mode about it.
closes #12438
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint