Skip to content

fix(webview): retain instance when destroy fails - #2836

Merged
RohitKushvaha01 merged 4 commits into
Acode-Foundation:mainfrom
azamkassim:fix/webview-destroy-failure-upstream
Aug 31, 2026
Merged

fix(webview): retain instance when destroy fails#2836
RohitKushvaha01 merged 4 commits into
Acode-Foundation:mainfrom
azamkassim:fix/webview-destroy-failure-upstream

Conversation

@azamkassim

Copy link
Copy Markdown
Contributor

Summary

  • Mark a WebView instance destroyed only after native destruction succeeds.
  • Keep the JavaScript instance usable when native destruction fails.
  • Add focused tests for failed, retried, and successful destruction.

Why

The WebView API currently sets "_destroyed" before awaiting the native bridge. If native destruction fails, the native WebView may still exist, but its JavaScript wrapper permanently rejects further operations—including another destruction attempt.

This change moves the state transition until after successful native destruction.

Testing

  • "npm test" — 49 test files and 331 tests passed
  • "npm run typecheck"
  • Biome check passed
  • "git diff --check" passed

Related work

Follow-up to the WebView Plugin API introduced in #2525.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR preserves a WebView wrapper when native destruction fails while serializing concurrent destruction attempts through a shared promise.

  • Marks the wrapper destroyed and clears listeners only after successful native teardown.
  • Clears the failed destruction promise so callers can retry.
  • Adds lifecycle tests covering failure, retry, success, and concurrent callers.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/lib/webview.js Serializes concurrent teardown, delays destroyed-state mutation until native success, and permits retry after failure.
tests/unit/webview.test.js Adds focused coverage for failed, retried, successful, and concurrent WebView destruction.

Sequence Diagram

sequenceDiagram
    participant A as First caller
    participant B as Concurrent caller
    participant W as WebView wrapper
    participant N as Native bridge
    A->>W: destroy()
    W->>N: destroy(id)
    B->>W: destroy()
    W-->>B: await shared promise
    alt Native destruction succeeds
        N-->>W: resolve
        W->>W: mark destroyed and clear callbacks
        W-->>A: resolve
        W-->>B: resolve
    else Native destruction fails
        N-->>W: reject
        W->>W: clear shared promise
        W-->>A: reject
        W-->>B: reject
    end
Loading

Reviews (2): Last reviewed commit: "test(webview): cover concurrent destruct..." | Re-trigger Greptile

Comment thread src/lib/webview.js Outdated
@azamkassim azamkassim changed the title fix/webview-destroy-failure-upstream fix(webview): retain instance when destroy fails Aug 30, 2026
@bajrangCoder

This comment was marked as outdated.

@RohitKushvaha01
RohitKushvaha01 added this pull request to the merge queue Aug 31, 2026
Merged via the queue into Acode-Foundation:main with commit d31a864 Aug 31, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants