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] Event payload sent between frontends does not get parsed into an object #5482

Closed
ghost opened this issue Oct 25, 2022 · 1 comment
Closed
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@ghost
Copy link

ghost commented Oct 25, 2022

Describe the bug

I have two Tauri windows communicating with each other via events on the frontend. I would like to send an object from one window to another. From my understanding, the serialized JSON should be parsed automatically on the receiving end, but instead I'm getting the string representation. This does not seem to be intended behavior.

Possibly related: #2929

Reproduction

In the main window:

type Message = { message: string };

const secondWindow = new WebviewWindow("secondWindow", { /* ... */ });

secondWindow.listen<Message>("message-sent", (e) => console.log(e.payload.message)); // ERROR: `e.payload` is a string

In the secondary window:

const mainWindow = WebviewWindow.getByLabel("main");

mainWindow?.emit("message-sent", { message: "Hello from other window!" });

Expected behavior

e.payload should be an object instead of a string.

Platform and versions

Environment
  › OS: Windows 10.0.22621 X64
  › Webview2: 106.0.1370.52
  › MSVC: 
      - Visual Studio Build Tools 2022
  › Node.js: 16.17.1
  › npm: 8.15.0
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.25.1
  › rustc: 1.64.0
  › cargo: 1.64.0
  › Rust toolchain: stable-x86_64-pc-windows-msvc 

Packages
  › @tauri-apps/cli [NPM]: 1.1.1
  › @tauri-apps/api [NPM]: 1.1.0
  › tauri [RUST]: 1.1.1,
  › tauri-build [RUST]: 1.1.1,
  › tao [RUST]: 0.14.0,
  › wry [RUST]: 0.21.1,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../build
  › devPath: http://localhost:5173/
  › framework: Svelte

App directory structure
  ├─ .git
  ├─ .svelte-kit
  ├─ build
  ├─ node_modules
  ├─ src
  ├─ src-tauri
  └─ static

Stack trace

No response

Additional context

No response

@ghost ghost added status: needs triage This issue needs to triage, applied to new issues type: bug labels Oct 25, 2022
@amrbashir
Copy link
Member

I did some investigations and the situation is bad. In JS -> JS/Rust events, payload is serialized to string and then dispatched as string to both JS and Rust listeners but Rust -> JS/Rust will be dispatched to JS as object and as String to Rust. cc @lucasfernog

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

No branches or pull requests

1 participant