Repository navigation
fix(api): return awaitable cleanup from combined event listeners - #16195
Merged
amrbashir merged 1 commit intoOct 7, 2026
Merged
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJ33Jyj1E56xox3bn33PrT
Contributor
Package Changes Through a3f2e49There are 1 changes which include @tauri-apps/api with patch 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
The combined cleanup functions returned by
Webview.onDragDropEvent,Window.onDragDropEventandWindow.onFocusChangedin@tauri-apps/apicalled each inner unlisten function but discarded the promises they return. The cleanup returnedundefined, so a rejecting inner unlisten (e.g. the listener was already removed, or theplugin:event|unlisteninvoke failed) surfaced as an unhandled promise rejection — commonly on React unmount, when cleanup races listener registration or teardown.What is the current behavior?
Callers have nothing to
awaitor.catch(). See #16194.What is the new behavior?
Each combined cleanup is now
asyncand awaits all inner unlistens:Affected APIs:
Webview.onDragDropEvent(packages/api/src/webview.ts) — 4 listenersWindow.onDragDropEvent(packages/api/src/window.ts) — 4 listenersWindow.onFocusChanged(packages/api/src/window.ts) — 2 listenersA grep of
packages/api/srcfor otherreturn () => { unlistenX(); ... }combined cleanups found no other instances.Backwards compatibility
UnlistenFnis typed() => void, so an async function stays assignable and the public type does not change. Callers that ignore the result behave exactly as before; callers thatawaitor.catch()the result can now handle failures. All inner unlistens still start synchronously, same as today.Note:
Promise.allSettledplus rethrowing the first error is an alternative if maintainers prefer that every failure be observed.Separately, a rejected intermediate
await this.listen(...)inside these helpers leaks the listeners registered before it. Flagging that as a possible follow-up; it is not fixed here.Verification
pnpm install --frozen-lockfilepnpm -C packages/api buildpnpm -C packages/api run ts:check/ eslint, and repoprettier --checkon the changed files(all passing — see PR checks / discussion; change file added in
.changes/fix-api-composite-unlisten.md)Closes #16194