-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support store structure changing #30
Comments
Hi @andrey-hohlov, this is something I experienced myself. The only fix right now is to go Application > Local Storage and remove the key of vuex-multi-tab-state in order to force the resync of the state to the local storage. I'm trying to find a solution for this issue. |
@andrey-hohlov What I did to get around this at least for the people using the application was on login
For myself while developing on localhost I just had to manually clear it |
@gabrielmbmb I thought a lot about this problem.
We can modify Works for my example, but unpredictable consequences are possible. But, we can add a new option, hook
The same. So, my conclusion is: There is no way to manage it in a universal way. What do you think? |
Random: I can imagine that for some cases it'd be actually better to store the whole store behind a version. Then by initialization you'd be able to migrate existing data. |
both hooks get the current state passed and if they return a falsy value the operation is canceled this allows to pre-filter/-validate a state once more before it is restored and/or saved see also gabrielmbmb#30
I currently solve that via another // ~/plugins/multiTabState.client.js
import createMultiTabState from 'vuex-multi-tab-state';
import { simpleCloneState } from '~/common/utils'
export default ({ store }) => {
// prevent multiTabState to overwrite store with "old" version
let validState = simpleCloneState(store.state);
store.subscribe((mutation, state) => {
if(!state.storeVersion || state.storeVersion < validState.storeVersion){
store.replaceState(validState)
}else{
validState = simpleCloneState(state);
}
})
createMultiTabState()(store);
}; But I'd rather have that invalid state never land in my store. I hope for the hook-parameters #65 to be worthy of a merge. |
…-and-onBeforeSave Feat #30 add params onBeforeReplace and onBeforeSave
I will release the v1.0.17 which already has the before |
Just a question, wouldn't this also be solved once there is a solution for #63, since this plugin will instead start by taking the new current store and never using what's in the localstorage until after the store has been loaded? |
I am actually not sure if #63 is resolvable. But let's discuss that over there. The State timeoutIt could allow you to have a simple "timeout" functionality, where the cached state is treated as "old" after some idle time State validation based on tokenYou could use a token value in the current store (due to an read-in of a user-session before-multi-tab-state-plugin-init e.g. from a cookie) to compare with the cached-state to make sure an out-dated user session is not accidentally restored with a half-valid UI state based on a closed user session, causing the UI trying to request content from the backend that it has no longer permission to to request, leaving the UI in a broken state. Custom filteringOr you could implement your own filtering functionality to filter for the "to be saved/restored" parts of the state yourself e.g. if you have a complex state where you'd rather use a "blacklist" than the currently available "whitelist" of paths. . |
For example, we have a user vuex-module with this state:
The state is saved in local storage.
But some reasons we change state object to:
And now want to keep in storage only
user.auth
path.Reload page - and it removes the state
auth
key! The app is broken.This error happens in the getter:
And yes, I can fix it:
But maybe It will be better if vuex-multi-tab-state will respect the default state and do not override it if the path does not exist in the local storage. And do not create top-level state properties if they were removed from the default state. What do you think?
The text was updated successfully, but these errors were encountered: