electron-store icon indicating copy to clipboard operation
electron-store copied to clipboard

set intermittently not working

Open tylermassey opened this issue 5 years ago • 4 comments

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 ☹️

tylermassey avatar Mar 13 '19 19:03 tylermassey

That is very strange. Can you consistently reproduce it? What Electron version?

sindresorhus avatar May 01 '19 15:05 sindresorhus

I'm also dealing with this issue. On [email protected]. It is random, although happens >50% of the time.

decider avatar Jun 12 '19 22:06 decider

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.

paulovitorjp avatar Jun 25 '19 01:06 paulovitorjp

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.

paulovitorjp avatar Jun 29 '19 21:06 paulovitorjp