Skip to content

[store] Absolute vs. relative paths to the same store file are cached separately #984

@ryantaylor

Description

@ryantaylor

Came across an interesting edge case today in the store plugin. If I create a store in JS like this:

const store = new Store(appDataDir() + "config.file")

and I try to access it from Rust like this:

let stores = app.state::<StoreCollection<Wry>>();
let path = PathBuf::from("config.file");

with_store(app_handle, stores, path, |store| store.insert("a".to_string(), json!("b")))

these will load from and save to the same file on the filesystem (thanks to https://github.com/tauri-apps/plugins-workspace/blob/v1/plugins/store/src/store.rs#L179), but they'll be cached separately because with_store just uses the key you give it (which in this case is an absolute path in JS and a relative path in Rust) - the line in question is here: https://github.com/tauri-apps/plugins-workspace/blob/v1/plugins/store/src/lib.rs#L57.

Since these two paths point to the same store file and load from/save to the same file, it feels to me like with_store should key on the absolute path constructed by load and save instead of just whatever the caller gives it.

Happy to throw together a quick PR in this direction if we think it makes sense!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions