-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
Snapshots can be mutated by adding or removing properties #749
Comments
Preventing the addition of new properties should be trivial. We can call diff --git a/src/vanilla.ts b/src/vanilla.ts
index 7844994..1e169a0 100644
--- a/src/vanilla.ts
+++ b/src/vanilla.ts
@@ -146,6 +146,7 @@ const buildProxyFunction = (
}
Object.defineProperty(snap, key, desc)
})
+ Object.preventExtensions(snap)
return snap
}, I tested this locally and found no breaking tests. I can submit a PR if you want. However, preventing deletion would be a bit more involved. It's hard to grok the details, but I believe snapshot properties were made configurable in ba53bf6 (#664) due to performance issues. Would it be too difficult to revert some of the changes? If we want to avoid reverting the above, I suppose we might be able to wrap the snapshot object in its own |
We used to deep-freeze snapshot object. But, there's performance downside, because we had to deep-copy the object in
|
Summary
Adding or removing properties from a snapshot object or array does not throw, even in strict mode.
Although it appears that such invalid operations do not affect the proxy store itself,
silently swallowingallowing these errors is undesirable, since the snapshot (correctly) errors on other types of mutations.Edit: The snapshot can be mutated:
This seems to be a correctness issue.
Link to reproduction
https://codesandbox.io/s/sad-gauss-w364gf
Check List
Please do not ask questions in issues.
Please include a minimal reproduction.
The text was updated successfully, but these errors were encountered: