Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] localStorage not syncing between multiple webview windows on Linux #10981

Closed
Ynng opened this issue Sep 12, 2024 · 2 comments · Fixed by #11043
Closed

[bug] localStorage not syncing between multiple webview windows on Linux #10981

Ynng opened this issue Sep 12, 2024 · 2 comments · Fixed by #11043
Labels
platform: Linux status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@Ynng
Copy link

Ynng commented Sep 12, 2024

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.

Screencast.from.2024-09-12.19-29-11.mp4

Reproduction

The counter example shown in the video: https://github.com/Ynng/tauri-localstorage-sync-test

OR:

Reproduce from scratch:

  • Create a new Ubuntu LTS 24 virtual machine
  • Install "Debian" dependencies from the Tauri v2 setup guide
  • Install Rust curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
  • Install nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
  • Install node nvm install node
  • Enable pnpm corepack enable pnpm
  • Create a new Tauri app pnpm create tauri-app --rc with React, TypeScript and pnpm
  • Modify tauri.conf.json to create 2 windows with different labels
  • Start the dev server
  • Open devtools in both window, locater the "local storage" section
  • Add a new key in one window's location storage, observe the local storage entries in the other window

Expected 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 output

[✔] Environment
    - OS: Ubuntu 24.4.0 x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.44.3
    ✔ rsvg2: 2.58.0
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)
    - node: 22.8.0
    - pnpm: 9.10.0
    - npm: 10.8.2

[-] Packages
    - tauri 🦀: 2.0.0-rc.11
    - tauri-build 🦀: 2.0.0-rc.10
    - wry 🦀: 0.43.1
    - tao 🦀: 0.30.0
    - tauri-cli 🦀: 2.0.0-rc.12
    - @tauri-apps/api : 2.0.0-rc.4
    - @tauri-apps/cli : 2.0.0-rc.13

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-shell : 2.0.0-rc.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

I get warnings like these sometimes on linux

(process:1737224): libsoup-WARNING **: 19:55:42.244: Failed to execute query: database is locked

(process:1737224): libsoup-WARNING **: 19:55:42.244: Failed to execute query: no such table: soup_hsts_policies
Failed to create hard link from /home/wenqi/.cache/tauri-app/WebKitCache/Version 16/Blobs/3DE2C89C97AF2523D1A566F90E64D1EB6FED08A2 to /home/wenqi/.cache/tauri-app/WebKitCache/Version 16/Records/2D857AF3C0D6CD0AE5639C83ED0E05BB5A00AEED/Resource/D36F616E0D261016A1484FD7FF748035207E4BBE-blob

The problem exists with both Tauri v1 and v2

@Ynng Ynng added status: needs triage This issue needs to triage, applied to new issues type: bug labels Sep 12, 2024
@Ynng Ynng changed the title [bug] [bug] localStorage not syncing between multiple webview windows on Linux Sep 12, 2024
@greenhat616
Copy link

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.

@Ynng
Copy link
Author

Ynng commented Sep 17, 2024

Thanks for the suggestion, I'm using tauri store as a work around for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Linux status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants