{"action":"created","issue":{"url":"https://api.github.com/repos/championswimmer/vuex-persist/issues/33","repository_url":"https://api.github.com/repos/championswimmer/vuex-persist","labels_url":"https://api.github.com/repos/championswimmer/vuex-persist/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/championswimmer/vuex-persist/issues/33/comments","events_url":"https://api.github.com/repos/championswimmer/vuex-persist/issues/33/events","html_url":"https://github.com/championswimmer/vuex-persist/issues/33","id":297822777,"number":33,"title":"Date object not being restored from local storage","user":{"login":"Y0hy0h","id":11377826,"avatar_url":"https://avatars0.githubusercontent.com/u/11377826?v=4","gravatar_id":"","url":"https://api.github.com/users/Y0hy0h","html_url":"https://github.com/Y0hy0h","followers_url":"https://api.github.com/users/Y0hy0h/followers","following_url":"https://api.github.com/users/Y0hy0h/following{/other_user}","gists_url":"https://api.github.com/users/Y0hy0h/gists{/gist_id}","starred_url":"https://api.github.com/users/Y0hy0h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Y0hy0h/subscriptions","organizations_url":"https://api.github.com/users/Y0hy0h/orgs","repos_url":"https://api.github.com/users/Y0hy0h/repos","events_url":"https://api.github.com/users/Y0hy0h/events{/privacy}","received_events_url":"https://api.github.com/users/Y0hy0h/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-16T15:30:20Z","updated_at":"2018-02-18T07:33:44Z","closed_at":null,"author_association":"NONE","body":"When a `Date` object is in the state, it is saved to local storage serialized as a string. Upon reload of the page, the date remains a string.\r\n\r\n```js\r\n// excerpt from main.js\r\n\r\nconst vuexLocal = new VuexPersistence({\r\n  storage: window.localStorage,\r\n})\r\n\r\nconst store = new Vuex.Store({\r\n  state: {\r\n    allDates: [\r\n      new Date(),\r\n    ]\r\n  },\r\n  mutations: {\r\n    'add-date': state => {\r\n      state.allDates.push(new Date())\r\n    }\r\n  },\r\n  plugins: [\r\n    vuexLocal.plugin,\r\n  ]\r\n})\r\n```\r\n```js\r\n// excerpt from App.js\r\n\r\n<template>\r\n    <div id=\"app\">\r\n        <button @click=\"$store.commit('add-date')\">+</button>\r\n        <ul>\r\n            <li v-for=\"date in $store.state.allDates\">\r\n                {{date.toLocaleDateString()}}\r\n            </li>\r\n        </ul>\r\n    </div>\r\n</template>\r\n```\r\nExcerpt from error in browser console after using the button to add a date and refreshing the page:  \r\n`TypeError: date.toLocaleDateString is not a function`\r\n\r\n## Reproduction\r\nYou can checkout [my reproduction repo](https://github.com/Y0hy0h/vuex-persist-object-bug). It is a minimal Vue app generated with the default vue-cli (v3) scaffold.\r\n\r\nTo reproduce the bug, follow these steps:\r\n- Launch the server using `yarn serve`.\r\n- On the page, hit the \"+\" button to add a date.\r\n- Refresh the page.\r\n- Observe that the page is empty and the console is filled with an error message.\r\n\r\n### Notes\r\nIf you do not hit the \"+\" button, it works, even though there is a date already initialized from the default state. So if you refresh the page with an empty local storage, everything works as expected. I assume that vuex-persist does not save the state to local storage yet, since nothing has triggered a change.\r\n\r\nIn the production app I found this in, I use TypeScript. The bug is the same there."},"comment":{"url":"https://api.github.com/repos/championswimmer/vuex-persist/issues/comments/366497964","html_url":"https://github.com/championswimmer/vuex-persist/issues/33#issuecomment-366497964","issue_url":"https://api.github.com/repos/championswimmer/vuex-persist/issues/33","id":366497964,"user":{"login":"Y0hy0h","id":11377826,"avatar_url":"https://avatars0.githubusercontent.com/u/11377826?v=4","gravatar_id":"","url":"https://api.github.com/users/Y0hy0h","html_url":"https://github.com/Y0hy0h","followers_url":"https://api.github.com/users/Y0hy0h/followers","following_url":"https://api.github.com/users/Y0hy0h/following{/other_user}","gists_url":"https://api.github.com/users/Y0hy0h/gists{/gist_id}","starred_url":"https://api.github.com/users/Y0hy0h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Y0hy0h/subscriptions","organizations_url":"https://api.github.com/users/Y0hy0h/orgs","repos_url":"https://api.github.com/users/Y0hy0h/repos","events_url":"https://api.github.com/users/Y0hy0h/events{/privacy}","received_events_url":"https://api.github.com/users/Y0hy0h/received_events","type":"User","site_admin":false},"created_at":"2018-02-18T07:33:44Z","updated_at":"2018-02-18T07:33:44Z","author_association":"NONE","body":"I'm fine with manually overwriting the deserialization. How do I do that?"}}
{"actor":{"display_login":"Y0hy0h"}}