Repository navigation
fix(webview): retain instance when destroy fails #2836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RohitKushvaha01
merged 4 commits into
Acode-Foundation:main
from
azamkassim:fix/webview-destroy-failure-upstream
Aug 31, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
de4ef6f
fix(webview): retain instance when destroy fails
azamkassim 853da17
test(webview): cover destroy failure lifecycle
azamkassim 60ebb16
fix(webview): serialize concurrent destruction
azamkassim c299ffc
test(webview): cover concurrent destruction
azamkassim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const { nativeBridge } = vi.hoisted(() => ({ | ||
| nativeBridge: { | ||
| setMessageCallback: vi.fn(), | ||
| create: vi.fn(), | ||
| evaluate: vi.fn(), | ||
| destroy: vi.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("../../src/plugins/webview/www/webview", () => ({ | ||
| default: nativeBridge, | ||
| })); | ||
|
|
||
| import webviewAPI from "lib/webview"; | ||
|
|
||
| describe("WebView lifecycle", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| nativeBridge.create.mockResolvedValue("webview-1"); | ||
| nativeBridge.evaluate.mockResolvedValue("result"); | ||
| nativeBridge.destroy.mockResolvedValue(undefined); | ||
| }); | ||
|
|
||
| it("keeps the instance usable when native destruction fails", async () => { | ||
| const webview = await webviewAPI.create(); | ||
| nativeBridge.destroy.mockRejectedValueOnce(new Error("native failure")); | ||
|
|
||
| await expect(webview.destroy()).rejects.toThrow("native failure"); | ||
| await expect(webview.evaluate("1 + 1")).resolves.toBe("result"); | ||
| expect(nativeBridge.evaluate).toHaveBeenCalledWith("webview-1", "1 + 1"); | ||
|
|
||
| await expect(webview.destroy()).resolves.toBeUndefined(); | ||
| expect(nativeBridge.destroy).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| it("marks the instance destroyed only after native destruction succeeds", async () => { | ||
| const webview = await webviewAPI.create(); | ||
|
|
||
| await webview.destroy(); | ||
|
|
||
| await expect(webview.evaluate("1 + 1")).rejects.toThrow( | ||
| "WebView has been destroyed", | ||
| ); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.