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

After upgrade to v2: invalid args rid for command get: command get missing required key rid #1877

Open
gknapp opened this issue Oct 3, 2024 · 11 comments · May be fixed by #1860
Open

After upgrade to v2: invalid args rid for command get: command get missing required key rid #1877

gknapp opened this issue Oct 3, 2024 · 11 comments · May be fixed by #1860
Labels
bug Something isn't working plugin: store

Comments

@gknapp
Copy link
Contributor

gknapp commented Oct 3, 2024

I'm seeing many of these console errors in the webview2 inspector after updating tauri and tauri-plugin-store from 2.0.0-rc to 2.0.0 final. The error points to the plugin-store, or my call point: store.get("my-key"). No code changed, just Cargo and npm package upgrades to @tauri-apps v2 release.

My code:

import { Store } from "@tauri-apps/plugin-store"

const Setting = {
  editorOpen: "editor-visible",
  windowSplit: "window-split"
}

class WindowSettings {
  #defaults
  #store

  constructor(defaults, store = new Store(".settings.dat")) {
    this.#defaults = defaults
    this.#store = store
  }

  #saveSetting(key, value) {
    this.#store.set(key, value).then(() => this.#store.save())
  }

  /**
   * Return bounded split value in pixels
   * @returns number
   */
  getSplit = () =>
    this.#store.get(Setting.windowSplit).then(split =>
      typeof split !== "number"
        ? this.#defaults.split.min
        : Math.min(
            Math.max(split, this.#defaults.split.min),
            this.#defaults.split.max
          )
    )

  setSplit = px => {
    this.#saveSetting(Setting.windowSplit, px)
  }
}

image

I've tried changing my key names and store file (.dat), neither helped.

@FabianLars
Copy link
Member

Can you post the output of the tauri info command please?

@FabianLars FabianLars added bug Something isn't working plugin: store labels Oct 3, 2024
@mrguiman
Copy link

mrguiman commented Oct 3, 2024

This method of declaring store no longer works: https://v2.tauri.app/plugin/store/.

I've followed the migration but I'm now stuck because the create_store command apparently expects a u64 rather than a boolean

Unhandled Promise Rejection: invalid args `autoSave` for command `create_store`: invalid type: boolean `true`, expected u64

which has already been mentionned here and can be circumvented by using a number instead of a boolean when declaring the autoSave option

Some issues with stable it seems

@Legend-Master Legend-Master linked a pull request Oct 4, 2024 that will close this issue
@gknapp
Copy link
Contributor Author

gknapp commented Oct 4, 2024

Further to yesterday, I'm now seeing this error on Store construction:

invalid args ridfor commandget: invalid type: string ".settings.dat", expected u32

tauri info:

[✔] Environment
    - OS: Windows 10.0.22631 x86_64 (X64)
    ✔ WebView2: 129.0.2792.79
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.10.0
    - npm: 10.2.3

[-] Packages
    - tauri 🦀: 2.0.0
    - tauri-build 🦀: 2.0.0
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.2
    - @tauri-apps/api : 2.0.1
    - @tauri-apps/cli : 2.0.0-rc.18 (outdated, latest: 2.0.1)

[-] Plugins
    - tauri-plugin-http 🦀: 2.0.0
    - @tauri-apps/plugin-http : 2.0.0
    - tauri-plugin-dialog 🦀: 2.0.0
    - @tauri-apps/plugin-dialog : 2.0.0
    - tauri-plugin-fs 🦀: 2.0.0
    - @tauri-apps/plugin-fs : 2.0.0
    - tauri-plugin-store 🦀: 2.0.0
    - @tauri-apps/plugin-store : 2.0.0
    - tauri-plugin-shell 🦀: 2.0.0
    - @tauri-apps/plugin-shell : 2.0.0
    - tauri-plugin-window-state 🦀: 2.0.0
    - @tauri-apps/plugin-window-state : 2.0.0

[-] App
    - build-type: bundle
    - CSP: default-src 'self' data: blob:; script-src 'self' 'unsafe-inline' http://localhost:*; style-src 'self' 'unsafe-inline'; connect-src 'self' ipc: http://ipc.localhost http://localhost:*; img-src 'self' data: http: https:
    - frontendDist: ../dist
    - devUrl: http://localhost:3055/
    - framework: React
    - bundler: Rollup

@antkit
Copy link

antkit commented Oct 5, 2024

I can't load data after upgrading from v2.0.0-rc to v2.0.1 .
The console prints errors as gknapp said.

@will5933
Copy link

will5933 commented Oct 6, 2024

the same problem😭

Uncaught invalid args `rid` for command `get`: invalid type: string "settings.bin", expected u32
[✔] Environment
    - OS: Windows 10.0.22631 x86_64 (X64)
    ✔ WebView2: 129.0.2792.79
    ✔ MSVC: Visual Studio Community 2022
    ✔ 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-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)

[-] Packages
    - tauri 🦀: 2.0.1
    - tauri-build 🦀: 2.0.1
    - wry 🦀: 0.44.1
    - tao 🦀: 0.30.3
    - tauri-cli 🦀: 2.0.1

[-] Plugins
    - tauri-plugin-store 🦀: 2.0.1
    - tauri-plugin-fs 🦀: 2.0.1
    - tauri-plugin-autostart 🦀: 2.0.1
    - tauri-plugin-dialog 🦀: 2.0.1
    - tauri-plugin-single-instance 🦀: 2.0.1
    - tauri-plugin-shell 🦀: 2.0.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../src

@mrguiman
Copy link

mrguiman commented Oct 7, 2024

@will5933 @antkit @gknapp

You guys need to change the way you declare the store after updating to plugin-store v2 -> https://v2.tauri.app/plugin/store/

@beeb
Copy link

beeb commented Oct 7, 2024

You guys need to change the way you declare the store after updating to plugin-store v2 -> https://v2.tauri.app/plugin/store/

The bug still happens for me with this code snippet

@will5933
Copy link

will5933 commented Oct 7, 2024

Thanks, it works.

from

const clipboardStore = new window.__TAURI_PLUGIN_STORE__.Store('clipboard.bin');

to

const { createStore } = window.__TAURI__.store;
// ...
const clipboardStore = await createStore('clipboard.bin');

@gknapp
Copy link
Contributor Author

gknapp commented Oct 7, 2024

I've updated my code to follow the V2 docs, this generated a new error passing the { autoSave: true } option object:

Uncaught (in promise) invalid args autoSave for command create_store: invalid type: boolean true, expected u64

I omitted that option and just call store.save() after setting a value.
Update: { autoSave: 1 } is accepted, no console errors.

I updated my capabilities for the plugin too (to use store:default) and rewrote the constructor of my class. I no longer construct the store if it's not passed in. I moved store construction to a hook, as createStore() is async.

const Setting = {
  windowSplit: "window:split"
}

class WindowSettings {
  #defaults
  #store

  constructor(defaults, store) {
    this.#defaults = defaults
    this.#store = store
  }

  #saveSetting(key, value) {
    this.#store.set(key, value).then(() => this.#store.save())
  }

  getSplit = () =>
    this.#store.get(Setting.windowSplit).then(split =>
      typeof split !== "number"
        ? this.#defaults.split.min
        : Math.min(
            Math.max(split, this.#defaults.split.min),
            this.#defaults.split.max
          )
    )

  setSplit = px => {
    this.#saveSetting(Setting.windowSplit, px)
  }
   ...
}

I use a hook for store instantiation and updated my app to show a loading component if the store isn't set / ready.

import React from "react"
import { createStore } from "@tauri-apps/plugin-store"
import Settings from "../settings"

function useSettings(defaults, storeFile = "settings.bin") {
  const [settings, setSettings] = React.useState(null)

  React.useEffect(() => {
    const initSettings = async () => {
      const store = await createStore(storeFile)
      setSettings(new Settings(defaults, store))
    }
    initSettings()
  }, [])

  return settings
}

export default useSettings

Conditional render in App:

  ...
  const defaultSettings = React.useMemo(() => {
    return {
      split: {
        max: leftSideMax + resizeBarWidth,
        min: minWidth
      }
    }
  }, [minWidth, leftSideMax, resizeBarWidth])
  const settings = useWindowSettings(defaultSettings)
  ...
  if (!settings) {
    return (<Loading />)
  }
  ...
  // render app UI as usual, settings available

@bpevs
Copy link

bpevs commented Oct 14, 2024

Oh oops I opened #1931 before seeing this. But it seems that createStore is now the blessed api? So we should update the readme here to match that?

But for autoSave, it seems like the rust is using it as a u64 because it's using it to define debounce. But those changes aren't reflected in the JS, and I'm not sure which we should want to do:

a. change types/docs to match this behavior in js (autoSave is now a boolean, describe it to be used for debounce)
b. transform the autoSave boolean in js, and properly pass an int to bridge
c. change the rust to treat them as two different properties

edit:

It looks like more changes are in the pipeline already, and I see this change being reflected in those changes, so probably this will be more clear after this pr.

* Auto save on modification with debounce duration in milliseconds, it's 100ms by default, pass in `false` to disable it
    */
   autoSave?: boolean | number

@imddc
Copy link

imddc commented Oct 14, 2024

I also encountered this issue, should we update this version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin: store
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants