electron-store
electron-store copied to clipboard
set intermittently not working
version: 2.0.0
Sometimes store.set
does not work, and the value I set does not get persisted to the store file.
I was noticing odd behavior in my app and found the issue by doing this
store.set(key, 'something');
store.get(key) // undefined
Getting the value after I set it either returned undefined
(if it was the first time it was set) or the previous value.
I also used onDidChange
to further confirm that the value was never set.
I can't find any pattern to this behavior ☹️
That is very strange. Can you consistently reproduce it? What Electron version?
I'm also dealing with this issue. On [email protected]. It is random, although happens >50% of the time.
I am also seeing this behaviour on [email protected], but in my case it is more noticeable with store.get(). It returns the default value set on the Store constructor, even though it was set to something else. I get my values at app startup, but only try to get them after the app "ready" event. I don't know if this changes anything but I am using an encryptionKey. This happens erratically more than 50% of the times, and ONLY on macos in my case, windows works.
I am also seeing this behaviour on [email protected], but in my case it is more noticeable with store.get(). It returns the default value set on the Store constructor, even though it was set to something else. I get my values at app startup, but only try to get them after the app "ready" event. I don't know if this changes anything but I am using an encryptionKey. This happens erratically more than 50% of the times, and ONLY on macos in my case, windows works.
My problem was something else, I was using the data retrieved with store.get to send an ipc to the renderer process, and that would update a BehaviorSubject that my home page was subscribed to. The problem was that I was sending the ipc after the mainWindow webContents dom-ready event, that has always worked for windows, but worked intermittently with macos. Changing it to did-finish-load has fixed it. Now when the IPC arrives my service is already listening to it, and updates the BehaviorSubject and everyone subscribed to it.