tauri: [bug] Lots of internal_on_mousemove IPC calls causing lag and cursor flashing in 2.0.0-beta.0
Describe the bug
After migrating from Tauri V1 to V2 beta, when I move my mouse cursor over a button, the pointer “hand” symbol flashes between a normal cursor and the hand. A lot of traffic is observed in the Network tab of the devtools directed at this endpoint (http://ipc.localhost/plugin%3Awindow|internal_on_mousemove). Removing “window:default” in “/src-tauri/capabilities/mycapabilities.json” stops the flashing but then a lot of errors are logged in the console. I attempted to make a project from scratch and noted the same issue.
Attempted Fixes:
- Remove “window:default”
- Update Node, pnpm, Rust, Windows, package.json, cargo.toml
Cursor flash on hover/move with “window:default” enabled
https://github.com/tauri-apps/tauri/assets/25918877/41396a0f-0f11-44b4-b1dc-e10c02fd148e
Console errors with “window:default” disabled
https://github.com/tauri-apps/tauri/assets/25918877/5104c801-75a6-45cb-bc9b-9834899ec31c
Reproduction
- Run
pnpm create tauri-app --alpha- Use any project name
- Select Typescript/Javascript
- Select any package manager
- Select any UI template
- Select yes or no for setting project up for mobile
- Run
npm installin project directory - Run
npm run tauri dev - Once application has started, move mouse around in application window and hover over a button, open inspector and make note of console logs and/or network.
Expected behavior
- Cursor should not flash between normal cursor and hand pointer when hovering over buttons
- Excess events for mouse movement should not be fired, if possible (or be able to opt into this)
Full tauri info output
[✔] Environment
- OS: Windows 10.0.22000 X64
✔ WebView2: 121.0.2277.98
✔ MSVC: Visual Studio Build Tools 2022
✔ rustc: 1.75.0 (82e1608df 2023-12-21)
✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
- node: 20.11.0
- pnpm: 8.15.1
- npm: 10.4.0
[-] Packages
- tauri [RUST]: 2.0.0-beta.2
- tauri-build [RUST]: 2.0.0-beta.1
- wry [RUST]: 0.35.2
- tao [RUST]: 0.25.0
- @tauri-apps/api [NPM]: 2.0.0-beta.0
- @tauri-apps/cli [NPM]: 2.0.0-beta.0
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- framework: SolidJS
- bundler: Vite
Stack trace
POST http://ipc.localhost/plugin%3Awindow%7Cinternal_on_mousemove 400 (Bad Request)
value @ VM10:70
(anonymous) @ VM12:130
action @ VM12:269
(anonymous) @ VM12:278
value @ VM12:252
(anonymous) @ VM12:400
VM12:263
Uncaught (in promise) "window.internal_on_mousemove not allowed. Permissions associated with this command: window:allow-internal-on-mousemove, window:default"
(anonymous) @ VM12:263
value @ VM12:227
(anonymous) @ VM10:96
Promise.then (async)
value @ VM10:94
(anonymous) @ VM12:130
action @ VM12:269
(anonymous) @ VM12:278
value @ VM12:252
(anonymous) @ VM12:400
VM10:70
Additional context
- Just upgraded from Tauri V1 to V2 beta
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 7
- Comments: 17 (6 by maintainers)
Commits related to this issue
- fix: At least it works bug: https://github.com/tauri-apps/tauri/issues/8770 bug: src-tauri/src/utils/server.rs#L56-L80 — committed to Cyenoch/clash-verge-rev by Cyenoch 4 months ago
Here is a close up of the flashing cursor I noticed (I am not clicking or anything, just moving the mouse around over the button)
https://github.com/tauri-apps/tauri/assets/25918877/0fba563c-42d2-4f2d-80ec-2970286fe041
I ran into this issue as well and it basically made tauri unusable for me. I wrote up a quick workaround for the odd mouse behavior using the isolation pattern.
When my app starts (svelte in this case) I get the window size and wait for the iframe
__tauri_isolation__to load. Once loaded I send it the initial size and then subscribe to tauri://resize event and send it the updated size onwards.This is what I do in the isolation app:
It still spams ipc calls which isn’t ideal and I’m waiting for a fix but this fixes the stuttering issue and be sure to make a tauri command that doesn’t do anything so that the console isn’t spammed with errors about the endpoint not existing.
Edit: I don’t see why this behavior is needed if the app is decorated so in the code i sent above you can use
win.isDecorated()and override the event(s) related to window resizingThe reason why I didn’t go with this solution before, is that reloading the webview will make it lose the stored state or get out of sync. Maybe a mix of IPC and stored state could work.
Did test this idea before and it worked pretty well, however we need to use weird class names so as to not conflict with user (i.e.
__TAURI_INTERNAL_CLASS_nw-resize__)I don’t agree with this idea at all, since it will interfere with the user DOM hierarchy and could lead to hidden behaviors that they can’t explain.
This will prevent the cursor from changing when on the window edge and users won’t know if they are on a resizable edge or not.
taodoes support resizing undecorated windows natively, however when adding awrywebview, which is basically WebView2 on Windows, it is not a simple widget that is added to thetaowindow, it creates a new child HWND that fills thetaowindow and so any events related to mouse clicks will be on their HWND and won’t reach to the underlyingtaowindow.The implementation of this is quite hevavy for just to change the cursor style and check able to resize. MouseMove trigger very frequently. maybe need a debounce
Amr created a PR that is awaiting approval that fixes these issues. The OS check and permissions issue has been resolved. The OS check is now performed in Rust and checks for Windows alone, no script is attached for non-Windows platforms. And the permissions issue is avoided by using a custom invoke system (
window.ipc.postMessage) based on postMessage/eval that avoids the permissions & runtime authority.Nice catch, I will fix that as well in the PR
For transparency, the solution in #8537 was already used before in wry so the performance should be the same and because webview2 doesn’t provide anyway to hit test the webview from native side, however on Linux, we used to use raw GTK APIs and hit test on the native side, I will see if I can bring that back.
Probably should have included the error in https://github.com/tauri-apps/tauri/issues/8750 lol. but yes, we agree that it’s too hard on the ipc and will look into it. (that said, i don’t see the cursor flashing)
Edit: I closed my own issue cause yours is better, for visibility here’s my comment from the other issue: