#54089: fix: removing a loaded <webview> threw "Invalid guestInstanceId"
Description of Change
Before: removing a <webview> whose guest had loaded threw Uncaught Error: Invalid guestInstanceId: N out of the element's disconnectedCallback, and because the throw skipped the element reset, re-inserting that <webview> never created a new guest.
After: the element is removed (and can be re-inserted) with no error, as it was before #53684.
Removing the element tears down its internal iframe first, which destroys the guest and drops it from guestInstances; disconnectedCallback then sends GUEST_VIEW_MANAGER_DETACH_GUEST for an id that is already gone. #53684 put getGuestForFrame() in front of detachGuest(), and it throws for an unknown id.
How: the detach handler returns early when the id is no longer in guestInstances — the no-op detachGuest() always did for that case — and keeps the sender-frame check for live guests.
Fixes #53989.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
- tests are changed or added
Release Notes
Notes: Fixed an "Invalid guestInstanceId" error when removing a loaded <webview> from the DOM.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron