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

Comms broken since beta.3 #2342

Closed
DBTaylor opened this issue Aug 2, 2021 · 14 comments
Closed

Comms broken since beta.3 #2342

DBTaylor opened this issue Aug 2, 2021 · 14 comments
Assignees

Comments

@DBTaylor
Copy link

DBTaylor commented Aug 2, 2021

Using tauri 1.0.0-beta.3 (or beta.4 or beta.5), invoke is throwing an error, and events triggered in the backend are not being emitted in the frontend. I've had to revert to beta.1 to get everything to work (couldn't seem to get beta.2 to build).

The issue doesn't occur when I run tauri dev, only in the release build.

window.emit is returning Ok(). invoke returns ReferenceError: __TAURI_INVOKE_KEY__ is not defined.

Operating System - Windows, version 10.0.17763 X64
Webview2 - 92.0.902.62

Node.js environment
  Node.js - 14.8.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 6.14.7
  yarn - Not installed

Rust environment
  rustc - 1.54.0
  cargo - 1.54.0

App directory structure
/.git
/.vscode
/node_modules
/src
/src-tauri

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - unset
  distDir - ./dist
  devPath - http://localhost:8081/
  framework - React
  bundler - Webpack
@amrbashir
Copy link
Member

try

  1. remove target folder
  2. run cargo update in src-tauri
  3. build your app

@DBTaylor
Copy link
Author

DBTaylor commented Aug 2, 2021

try

1. remove `target` folder

2. run `cargo update` in `src-tauri`

3. build your app

just tried this, but I still have the issue

@amrbashir
Copy link
Member

can you provide a minimal repro ?

@DBTaylor
Copy link
Author

DBTaylor commented Aug 3, 2021

can you provide a minimal repro ?

Minimalish:
https://github.com/DBTaylor/tauri-comms

@nothingismagick
Copy link
Sponsor Member

Internally invoke now requires the use of the __TAURI_INVOKE_KEY__ which is a random string injected into an IIFE or ESM at runtime. By doing this manually, you are not passing in that private value.

@amrbashir
Copy link
Member

The comms are working fine. I didn't see any errors related to __TAURI_INVOKE_KEY__ and the reason why your front-end shows Ok: undefined is because your test function in src-tauri/src/main.rs doesn't return anything if you change it to something like this, it will work.

#[tauri::command]
fn test(window: Window) -> String {
	println!("test");
 	"test".into()
} 

Note: the repo had a typescript errors due to @tauri-apps/api package (which is fixed in dev and will be available in the next release), so I had to remove the typescript files from node_modules/@tauri-apps/api, and with this your front-end builds fine.

@DBTaylor
Copy link
Author

DBTaylor commented Aug 3, 2021

The comms are working fine. I didn't see any errors related to __TAURI_INVOKE_KEY__ and the reason why your front-end shows Ok: undefined is because your test function in src-tauri/src/main.rs doesn't return anything if you change it to something like this, it will work.

#[tauri::command]
fn test(window: Window) -> String {
	println!("test");
 	"test".into()
} 

Note: the repo had a typescript errors due to @tauri-apps/api package (which is fixed in dev and will be available in the next release), so I had to remove the typescript files from node_modules/@tauri-apps/api, and with this your front-end builds fine.

@amrbashir, did the comms work fine for you in the release build? The "Ok: undefined" is expected, but only shows up for me in dev. In release I get the error.

I also saw the typescript error and fixed it locally. I didn't have an issue building after fixing it.

@DBTaylor
Copy link
Author

DBTaylor commented Aug 3, 2021

Internally invoke now requires the use of the __TAURI_INVOKE_KEY__ which is a random string injected into an IIFE or ESM at runtime. By doing this manually, you are not passing in that private value.

What do you mean by "by doing this manually"? I'm attempting to use the invoke function, and getting this exception in the release build. Is there some other mechanism to send commands?

@nothingismagick
Copy link
Sponsor Member

@lucasfernog - am I mistaken, or is the __TAURI_INVOKE_KEY__ injection not needed when invoke("myFunc") is called?

@lucasfernog
Copy link
Member

The injection is handled by the tauri protocol. I'll check this repo today.

@DBTaylor
Copy link
Author

DBTaylor commented Aug 3, 2021

@nothingismagick I think whatever sets TAURI_INVOKE_KEY is failing in my release build for some reason. The invoke function is attempting to use it, but it doesn't exist.

@amrbashir
Copy link
Member

I can confirm it happens on release.

@amrbashir amrbashir reopened this Aug 3, 2021
@lucasfernog
Copy link
Member

I'll take care of this. Might be some detection issue on the custom protocol resolver.

@lucasfernog lucasfernog self-assigned this Aug 3, 2021
@lucasfernog
Copy link
Member

Found the issue. Our resolver ignores <script></script> tags assuming that it'll use the global tauri API (window.__TAURI__), and handles only scripts with type="module". I'll make a PR changing that so your app will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants