fix(core): purge JS event listeners when source webview is destroyed (fix #15583)#15604
fix(core): purge JS event listeners when source webview is destroyed (fix #15583)#15604tenderdeve wants to merge 4 commits into
Conversation
…ix tauri-apps#15583) JS event listeners registered from a webview are stored in the backend Listeners::js_event_listeners map keyed by the source webview label. When the webview was destroyed the manager removed its handle but left the listener entries behind. Their JS runtime no longer exists, so the callbacks can never be delivered and the metadata leaked until app exit, forcing apps to manually unlisten() before closing a window. Add Listeners::remove_webview_events and call it from on_webview_close and on_window_close so a destroyed webview's listeners are dropped with it.
Package Changes Through 0947c2fThere are 14 changes which include tauri-bundler with minor, tauri-cli with minor, @tauri-apps/cli with minor, tauri-utils with minor, tauri with minor, tauri-build with minor, tauri-macos-sign with minor, tauri-runtime-wry with minor, tauri-runtime with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor, @tauri-apps/api with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
Legend-Master
left a comment
There was a problem hiding this comment.
Looks good otherwise
…teners Clarify that this only purges JS-side listeners, matching the js_event_listeners map it operates on. Addresses @Legend-Master's review feedback.
|
@Legend-Master updated in fdf05c0 — renamed |
|
Can this RP be merged? |
Legend-Master
left a comment
There was a problem hiding this comment.
Thanks.
You'll need to run cargo fmt and sign your commits for me to merge this
|
@Legend-Master the approval got dismissed when i pushed a small rustfmt fixup (the rename pushed one call site over the line limit, fmt just split it - 0947c2f). ci's green again, mind re-approving when you get a sec? @wyhaya should be good to merge once it's re-approved 👍 |
Just so you know there's 2 requests here from the last review |
Closes #15583.
JS event listeners registered from a webview are stored in
Listeners::js_event_listeners, keyed by the source webview label. When the webview is destroyed the manager removes its handle from the store but leaves the listener entries behind. Since the webview's JavaScript runtime is gone, those callbacks can never be delivered — the entries just leak until the app exits, and apps are forced to callunlisten()fromonCloseRequestedbefore closing a window just to keep the backend map clean.Add
Listeners::remove_webview_events(label)and call it fromon_webview_closeandon_window_close(for each webview of the closing window), so a destroyed webview's JS listeners are dropped alongside its handle.Added a unit test (
js_listeners_removed_on_webview_close) covering register → close → gone.Note: @Legend-Master pointed out the Rust-side
handlersmap may leak similarly. That one is keyed byEventTargetrather than the owning webview, so purging it correctly has to account forWindowvsWebviewtargets and multi-webview windows. Left out of this PR to keep it focused on the reported JS-listener leak — happy to follow up if you'd like it handled here.Tested:
cargo test -p tauri --lib event::listener(5 passing), fmt + clippy clean.