fix(core): purge Rust event listeners when window/webview is destroyed - #15617
Conversation
|
Please sign your commits and rebase . |
fdbe62e to
5baef04
Compare
|
@Legend-Master rebased on The rebase conflicted with the JS-listener cleanup from #15604 (now on |
Package Changes Through dd47d3aThere are 14 changes which include tauri with minor, tauri-cli with minor, @tauri-apps/cli with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, tauri-bundler with minor, tauri-build with minor, tauri-macos-sign 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 |
Rust-side listeners registered via listen/once on a Window, Webview or WebviewWindow were never removed when that target was destroyed, leaking handlers for the lifetime of the app. Add Listeners::remove_listeners_for_target, wired into on_window_close and on_webview_close, which drops handlers whose target exactly matches the destroyed one. Matching on the full EventTarget (kind + label) instead of the label alone keeps window and webview listeners distinct in multi-webview mode, where a window and its webviews can share a label. App, Any and AnyLabel listeners are preserved. Follows the existing try_lock + Pending convention so it is safe during emit. closes tauri-apps#15613
5baef04 to
7249658
Compare
|
@Legend-Master addressed both, pushed in
Dropped the old |
Closes #15613 (Rust-side follow-up to the listener-leak discussion in #15583).
Rust-side listeners registered via
listen/onceon aWindow,WebvieworWebviewWindowwere never removed when that target was destroyed, so the handlers leaked for the lifetime of the app.Change
Listeners::remove_listeners_for_label, which retains only handlers whoseEventTargetis not bound to the destroyed label. It follows the existingtry_lock+Pendingqueue convention so it stays safe if called mid-emit.AppManager::on_window_close(window label + each child webview label) andon_webview_close.App,AnyandAnyLabellisteners are kept — onlyWindow/Webview/WebviewWindowtargets matching the closed label are dropped.Open question
I left
AnyLabel { label }listeners intact, treating them as explicit cross-target subscriptions rather than something owned by a single window/webview. Happy to also purge those on matching label if you think that fits the intended semantics better.This is scoped to the native (
handlers) map only; the JS-sidejs_event_listenerscleanup is a separate concern.Test
Added
remove_listeners_for_label_drops_only_owned_targetsverifying thatWindow/Webview/WebviewWindowlisteners for the closed label are removed while unrelated-label,App,AnyandAnyLabellisteners survive.