Persist updates slow
See original GitHub issueHi @ctrlplusb
First of all. Great job on this lib, i love it!
We run into an issue where persist is updating slowly (approx 2 sec delay). Even on simple/small persisted models.
For example i have this simple model
export const mainMenuModel = {
isOpen: true,
toggle: action((state, payload) => {
state.isOpen = !state.isOpen
}),
}
const storeModel = {
mainMenu: persist(mainMenuModel),
}
export const store = createStore(storeModel)
When toggling the menu it takes approx 2 sec to update the local/session storage.
The main issue is where we log out and refresh immediately or refresh 1 second after logging out we got logged back in because it did not update the local-storage on time.
I can get around this by setting the localStorage directly from my model
export const userModel = {
...initialState,
logout: action((state, payload) => {
localStorage.setItem('[StoreKey]@user.isLoggedIn', false)
localStorage.setItem('[StoreKey]@user.token', '')
state.isLoggedIn = false
state.token = ''
}),
}
But this seems not to be a solution in the long run.
Is this a know issue or is this expected behavior?
i’m using version 3.3.0
Thank you
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Why hibernate persist() is slow? It is only slow in my case?
I am trying to populate a database by creating entity objects and calling persist() using Hibernate as JPA provider.
Read more >Windows 10 Cumulative Updates are way too slow to ...
Windows 10 Cumulative Updates are way too slow to download and install. Hi Microsoft, I can no longer tolerate with the Cumulative Updates...
Read more >Appsheet VERY slow to save changes to googlesheet
Google Sheets recomputes that formula on every update. And if that is a long-running formula, then it delays everything.
Read more >Slow background tasks process - Persist issues - SonarQube
Hi,. We're using Sonar 8.2.0 developer edition and have ±1.3M LOC, for some time now we're seeing slowness in processing background tasks ...
Read more >Slow rendering - Android Developers
After looking at the systrace output, there might be methods in your app that you suspect are causing jank. For an example, if...
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 Free
Top 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
Hi @julianklumpers 👋
Glad to hear you are enjoying the lib. 😊
This is a similar problem as is described in #454
There are some API’s which I have both improved and documented within the 3.4.0 alpha, which is available via #459
What is happening is that we debounce the attempts to persist state, currently at an arbitrary 1000ms debounce setting (I plan to make this configurable via a further update in the 3.4.0 release).
So what you need to do prior to refreshing the page is to flush any outstanding calls in the persist layer. You can do so via the API that is attached to your store instance.
For example:
@julianklumpers I’ve just re-read your comment. I think you need to have the same
flush
logic after you login and before you refresh the page. Basically any time you refresh the page or navigate out of the site/app you should run a flush to be absolutely sure your state is persisted. I’ll update the docs accordingly with this information, making it more explicit and with some examples.