rubystarashe / nuxt-vuex-localstorage

MIT License
161 stars 18 forks source link

Two errors ocuring in runtime #2

Closed maziarz closed 5 years ago

maziarz commented 5 years ago

I have installed this module in a SPA, but i am receiving two errors in runtime. Here is the implementation for the sake of sanity:

nuxt.config.js

  modules: [
    ['nuxt-vuex-localstorage', {
      localStorage: ['teamCreation']
    }],
   ]

store/teamCreation.js

export const state = () => ({
  current_step: 0,
})

The errors:

TypeError: Cannot read property 'expire' of null Uncaught (in promise) TypeError: Cannot read property 'version' of undefined

guan commented 5 years ago

@maziarz i have same issue

rubystarashe commented 5 years ago

Thank you! This issue is fixed now

maziarz commented 5 years ago

Thanks! While the second error has been eliminated i still receive this one:

Cannot read property 'expire' of null

rubystarashe commented 5 years ago

https://github.com/rubystarashe/nuxt-vuex-localstorage-example

try this example

maziarz commented 5 years ago

I tried to add copy[key] !== null in the conditional code, but obviously it does not feel right, but it gets the job done. I have used your example and replicated it into my project, i have similar approach.

if (copy[key] !== null && typeof copy[key].expire === 'number')

rubystarashe commented 5 years ago

expire create event is only run when store has changed. so in right case, copy[key] is always has value. it seems the store watcher event run when before module init

can i check your whole example repo? i think i have to test more in detail

maziarz commented 5 years ago

expire create event is only run when store has changed. so in right case, copy[key] is always has value. it seems the store watcher event run when before module init

can i check your whole example repo? i think i have to test more in detail

I have several store modules, but i only utilise your plugin for one of the store modules. I have a some legacy code which is running vue-localstorage in a store module, but i do not expect that this should collide with your plugin. I just added some printout in the code, and it is indeed null for some values, which is causing the error. Not sure if i am able to build a minimum example of this code as it is a pretty big project. But i will see what i can do.

maziarz commented 5 years ago

I found the problem, i initialise one of my states with null: selected_category: null. That causes the error.

rubystarashe commented 5 years ago

In that case, there may be a few props can has null value.

try use this code

if (copy[key] !== null && typeof copy[key].expire === 'number') or if (typeof (copy[key] || {}).expire === 'number')

maziarz commented 5 years ago

Works perfectly! 👍

rubystarashe commented 5 years ago

xD You found it while I was writing down my answers.

I will update that after check logical errors.

Thank you!

maziarz commented 5 years ago

Your welcome, thank you for an excellent module! 🎉