plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

(store) store|reload command has unexpected side-effect (self.cache.extend)

Open theinfinit opened this issue 5 months ago • 1 comments

https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/guest-js/index.ts#L395-L397

As the description of reload function suggests, it should load the on-disk state into memory. But what is actually happening is a merge operation (or, using Rust's vocabulary, extending HashMap that is already in memory).

Example

After changing JSON externally as follows:

 {
   "one": {
     "someKey": "someValue"
   },
-  "two": {
+  "three": {
     "someKey": "someValue"
   }
 }

Instead of getting cache like this...

{
  "one": {
    "someKey": "someValue"
  },
  "three": {
    "someKey": "someValue"
  }
}

...calling reload function will result in the following:

{
  "one": {
    "someKey": "someValue"
  },
  "two": {
    "someKey": "someValue"
  },
  "three": {
    "someKey": "someValue"
  }
}

Current implementation

When it comes to store|load function, using cache.extend is probably fine, but for store|reload, given the current description, it makes the current behavior quite confusing.

await invoke('plugin:store|reload', { rid: this.rid })

https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/src/lib.rs#L212-L215

https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/src/store.rs#L502-L504

https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/src/store.rs#L287-L294

Solutions

Depending on why the current implementation is using cache.extend, and assuming that my understanding is correct, I would like to ask, to update the description of store|reload and warn about the side-effect (as changing the current implementation doesn't seem wise).

Question

In the meantime, I have a question. Is there some obvious way I'm missing, to actually update the cache to reflect the on-disk state?

theinfinit avatar Jul 04 '25 15:07 theinfinit

Honestly, I have no idea why it even works like that, it makes no sense to me for it to be additive

Let's document this for now and maybe change the behavior in v3

Legend-Master avatar Jul 06 '25 16:07 Legend-Master