Skip to content

fix: BrowserWindow add the same BrowserView #48053

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mai-121
Copy link
Contributor

@mai-121 mai-121 commented Aug 12, 2025

Description of Change

Closes #48057

Fixed addBrowserView to prevent unnecessary removal and re-adding of the same BrowserView.

Checklist

Release Notes

Notes: Fixed addBrowserView to prevent unnecessary removal and re-adding of the same BrowserView.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Aug 12, 2025
Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this! Also, could you please open a simple bug report and link it to this PR?

@mai-121
Copy link
Contributor Author

mai-121 commented Aug 12, 2025

Please add a test for this! Also, could you please open a simple bug report and link it to this PR?

OK

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

const ownerWindow = browserView.ownerWindow;
if (ownerWindow && ownerWindow !== this) {
ownerWindow.removeBrowserView(browserView);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, think something might've gotten a little messed up here!

@mai-121 mai-121 force-pushed the fix/add_browser_view branch from 3db2c09 to 21ad54f Compare August 12, 2025 11:04
@mai-121
Copy link
Contributor Author

mai-121 commented Aug 12, 2025

Please add a test for this! Also, could you please open a simple bug report and link it to this PR?
All done.

Comment on lines +202 to +204
if (this._browserViews.includes(browserView)) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a breaking change to the z-order of BrowserViews: Previously, calling addBrowserView would make the view the top-most view.

This is so useful that it's documented for the successor API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addBrowserView did not have this feature originally, so I kept it consistent with the original implementation.
After the BrowserView module was refactored in electron 30, some behaviors changed implicitly, including the 'z-order change' you mentioned.(Refactored implementation)

I think this adjustment should be consistent with the original version. What do you think?

Copy link
Member

@codebytere codebytere Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikwen strictly speaking we broke it in the above linked PR without documenting a change so it's not a breaking change in this case - i'm fine with potentially breaking it but it should go through a cycle then and we've deprecated BrowserView already so there's not really a point imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-pr 🌱 PR opened recently
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: addBrowserView unnecessarily removes and re-adds the same browserView
3 participants