fix(transport): replace Tauri listen() to avoid unlisten race crashing on WKWebView

Call plugin:event|listen/unlisten directly and guard the client-side listener
registry cleanup, so unsubscribe always reaches the backend even when the
registration eval has not yet populated window.__TAURI_EVENT_LISTENERS__.
Prevents the intermittent `listeners[eventId].handlerId` TypeError and the
resulting leaked listener.
This commit is contained in:
xintaofei
2026-04-22 11:25:38 +08:00
parent 3f3a325848
commit 5dd1deb986
2 changed files with 45 additions and 12 deletions

View File

@@ -2042,11 +2042,7 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
})
.then((fn) => {
if (cancelled) {
try {
fn()
} catch {
// Tauri listener may not be fully registered yet
}
fn()
} else {
unlisten = fn
listenerReadyRef.current = true
@@ -2066,11 +2062,7 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
clearTimeout(flushTimerRef.current)
flushTimerRef.current = null
}
try {
unlisten?.()
} catch {
// Tauri listener may not be fully registered yet
}
unlisten?.()
}
}, [bufferUnmappedEvent, handleMappedEvent, resolveListenerReadyWaiters])