Open Ynng opened 1 week ago
Maybe you could checkout the plugin tauri-plugin-store
for a workaround?
Most state managers such as jotai
, receive a Storage
interface, like:
export interface AsyncStorage<Value> {
getItem: (key: string, initialValue: Value) => PromiseLike<Value>;
setItem: (key: string, newValue: Value) => PromiseLike<void>;
removeItem: (key: string) => PromiseLike<void>;
subscribe?: Subscribe<Value>;
}
export interface AsyncStringStorage {
getItem: (key: string) => PromiseLike<string | null>;
setItem: (key: string, newValue: string) => PromiseLike<void>;
removeItem: (key: string) => PromiseLike<void>;
subscribe?: StringSubscribe;
}
And tauri-plugin-store
provide a onKeyChange
fn to recevie value changed: https://github.com/tauri-apps/tauri-plugin-store/blob/96185a8aedb7a8658de7281cd8ac0149874de425/guest-js/index.ts#L181-L190
You could wrap it to a Storage
impl to finish the cross platform usage.
Thanks for the suggestion, I'm using tauri store as a work around for now
Describe the bug
localStorage
is synced between multiple webview windows on Windows and macOS but not Linux.On Linux, only 1 window's local storage gets saved when the tauri app exits. The rest of the windows' local storage is out of sync with each other and is disposed of when the tauri app exits.
In the example video below, the 2 windows on the left are running in Fedora 40, their counters are out of sync. The 2 windows on the right are running in Windows 11, their counters are in sync.
https://github.com/user-attachments/assets/d1113ddc-5264-4426-b606-73cbe2e58f1b
Reproduction
The counter example shown in the video: https://github.com/Ynng/tauri-localstorage-sync-test
OR:
Reproduce from scratch:
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install node
corepack enable pnpm
pnpm create tauri-app --rc
with React, TypeScript and pnpmtauri.conf.json
to create 2 windows with different labelsExpected behavior
The localStorage entries should be in sync between the two windows. In the reproduction repo, the counter should stay in sync between the two windows.
Full
tauri info
outputStack trace
No response
Additional context
I get warnings like these sometimes on linux
The problem exists with both Tauri v1 and v2