MitsuhaKitsune / vuex-webextensions

A Vuex plugin to share store through webextensions components
MIT License
83 stars 30 forks source link

state not set to localstorage on first load #28

Closed kinghat closed 3 years ago

kinghat commented 4 years ago

when you first load an extension the state is not set to local storage. when i load an extension for the first time i get this from the background-script:

[Info] Vuex WebExtensions: Persistent states detected on config, reading from localstorage... [Verbose] Vuex WebExtensions: Listening for actions [Debug] Vuex WebExtensions: No data found on localstorage for persistent states

this is from the vuex-webextensions example extension. if you make a mutation from popup/content-script, then localstorage is set:

[Info] Vuex WebExtensions: Persistent states detected on config, reading from localstorage... [Verbose] Vuex WebExtensions: Listening for actions [Verbose] Vuex WebExtensions: Saved persistent states found on localstorage [Debug] Vuex WebExtensions: Hooked mutation (vweReplaceState)

is this by design or should state be set to localstorage on install?

mrboomer commented 4 years ago

Bump.

I see this issue happening, too. I may look into the source code here and see what's going on this week.

s1gmund80 commented 3 years ago

I'm experiencing more or less the same issue. Even if i do not apply any change from the popup, but i use it to trigger a new store read from the background it works. Didi you find anything on it? It could be useful even a callback to be triggered on the background when the extension find the localstorage state to be loaded

MitsuhaKitsune commented 3 years ago

It's by design, I do that logic on purpose for performance, the plugin didn't write anything to localstorage if you didn't proc any mutation, because the default states are always loaded on store initialization from the store files and do a localstorage load/read are redundant, because the store states didn't change.

For now I gona close the issue because isn't it if I didnt missunderstand.

@kinghat , @mrboomer , @s1gmund80 someone of you can provide me more details why the write of default states on initialization are needed?