store.restored Promise resolves before the state is restored.
See original GitHub issueHere’s the restoreState
function that retrieves some data from Firebase based on localStorage wishlistId
restoreState: async (key, storage) => {
const snapshot = await db
.ref(`wishlist/${storage.wishlistId}`)
.once('value');
const data = snapshot.val();
console.log('restoring', data);
return {
wishlist: {
ids: data.ids || [],
},
};
},
Here’s the beforeEnter
route callback.
beforeEnter: async (to, { params }, next) => {
console.log('before restore');
await store.restored;
console.log('after restore');
// ... sone additional logic
next();
},
I would expect the messages to be logged in the following order:
before restore
restoring
after restore
But the messages are logged in this order:
before restore
after restore
restoring
As a result, the router redirects to a route before the state is restored. I have asyncStorage
set to true
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
How to resolve a Promise only after a state change
You should check to see if promise is created when state changes. Keep in mind you can only invoke one of resolve/reject, and...
Read more >Promise.race() - JavaScript - MDN Web Docs
A Promise that asynchronously settles with the eventual state of the first promise in the iterable to settle. In other words, it fulfills...
Read more >How to repair the operating system and how to restore the ...
The computer restarts, and the system files and settings are returned to the state that they were in at the time that the...
Read more >Why Refurbished - Apple
Read more on the Apple Refurbished promise. ... Shop all Refurbished products ... from Apple experts, so most issues can be resolved in...
Read more >JavaScript Promise Tutorial – How to Resolve or Reject ...
The promise.then() call always returns a promise. This promise will have the state as pending and result as undefined .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having the same problem here as @nwittwer, but without Nuxt -
store.restored
is always undefined. Is there some fix or workaround for this?I had the same problem. It started working with the following setup (in nuxt):
vuex-persist.js
waitForStore.js - this is basically the adaption of the vuex-persist authors recommendation for nuxt
Add both plugins to nuxt.config.js
Hope it helps…