Skip to content
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

Dev mode protection against this.set(<string>) doesn't work #990

Closed
tivac opened this issue Dec 8, 2017 · 1 comment · Fixed by #1000
Closed

Dev mode protection against this.set(<string>) doesn't work #990

tivac opened this issue Dec 8, 2017 · 1 comment · Fixed by #1000
Labels

Comments

@tivac
Copy link
Contributor

tivac commented Dec 8, 2017

In dev mode, svelte wraps set calls in _setDev which checks to ensure that the first arg is an object, to protect against this.set("foo", 1). Which is great.

Except it doesn't currently work due to a quirk of the set() implementation.

set(newState) uses this._set(assign({}, newState)), which is calling out to the assign() function. So far so good.

Except that when the newState value is a string, assign() doesn't handle it very well.

So _setDev() ends up getting passed a nonsense object, which bypasses the check for a string value and the error is never shown.

<h1>{{key}}</h1>
<script>
export default {
   data() {
        return { key : false };
    },
    oncreate() {
        this.set("key", true);
    }
}
</script>

Will end up invoking _setDev() with an arg like { 0 : "k", 1 : "e", 2 : "y" }, which passes the typeof check and then does nothing useful.

@Rich-Harris
Copy link
Member

fixed in 1.46.1, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants