tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.67k stars 2.51k forks source link

[bug] using fetch api to upload a large file, main thread were stucked #9173

Closed wvq closed 7 months ago

wvq commented 7 months ago

Describe the bug

By using fetch api to upload a large file (20mb image), main thread were stucked. can't do anything until upload finished.

Reproduction

No response

Expected behavior

No response

Full tauri info output

[⚠] Environment
    - OS: Mac OS 13.6.4 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04) (Homebrew)
    ✔ cargo: 1.76.0
    ⚠ rustup: not installed!
      If you have rust installed some other way, we recommend uninstalling it
      then use rustup instead. Visit https://rustup.rs/
    ⚠ Rust toolchain: couldn't be detected!
      Maybe you don't have rustup installed? if so, Visit https://rustup.rs/
    - node: 18.18.2
    - npm: 9.8.1

[-] Packages
    - tauri [RUST]: 1.5.2
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.4
    - tao [RUST]: 0.16.4
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 1.5.11

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

FabianLars commented 7 months ago

We can't do much in v1 to fix this.

In v2 we've reworked the IPC so it should be much better there.

If the file you want to upload is already on the file system you could use the upload plugin instead which won't have this issue. If it's not on the file system already then it won't help you since the writeFile api will have the same problem.

Also, maybe try using the browser's built-in fetch instead of tauri's http module if the server you're uploading it allows it. This will also not use the IPC and therefore shouldn't block the main thread.

Lastly, try a release build via npm run tauri dev -- --release or npm run tauri build which should be way faster, maybe even fast enough for your use case.