Skip to content

fix: enforce size constraints on window creation on Windows and Linux#49906

Merged
jkleinsc merged 9 commits into
electron:mainfrom
mitchchn:mitch/enforce-size-constraints-on-init
Apr 6, 2026
Merged

fix: enforce size constraints on window creation on Windows and Linux#49906
jkleinsc merged 9 commits into
electron:mainfrom
mitchchn:mitch/enforce-size-constraints-on-init

Conversation

@mitchchn
Copy link
Copy Markdown
Member

@mitchchn mitchchn commented Feb 21, 2026

Description of Change

I noticed that size constraints were not enforced properly on window creation on Linux and Windows:

new BrowserWindow({
  width: 200,
  minWidth: 500,
});

In some environments, this simply creates a window that is too small. In others, the conflict is resolved by the window manager on show, but not before the window gets centered in the wrong position (and initially reports the wrong size).

This PR applies all size constraints on init and moves centering/positioning so it happens after the final window size has been determined.

Checklist

Release Notes

Notes: BrowserWindow now enforces min/max size constraints on window creation, even if they conflict with the requested width and height.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Feb 21, 2026
@codebytere codebytere self-requested a review February 23, 2026 13:05
Copy link
Copy Markdown
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

These CI failures eg. here seem related to the PR:

Failure in test: "BrowserWindow module sizing BrowserWindow.setMinimum/MaximumSize(width, height) creates window at max size when a larger size is requested"
AssertionError: expected 184 to equal 200

Same test failure on windows-arm64, windows-x86, and windows-x64

@mitchchn
Copy link
Copy Markdown
Member Author

These CI failures eg. here seem related to the PR:

Failure in test: "BrowserWindow module sizing BrowserWindow.setMinimum/MaximumSize(width, height) creates window at max size when a larger size is requested"
AssertionError: expected 184 to equal 200

Same test failure on windows-arm64, windows-x86, and windows-x64

Fixed!

@mitchchn mitchchn requested a review from ckerr February 25, 2026 03:25
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Feb 28, 2026
@ckerr
Copy link
Copy Markdown
Member

ckerr commented Mar 5, 2026

@mitchchn the bots want target/* labels. Which branches need this fix?

@ckerr ckerr added platform/windows platform/linux semver/patch backwards-compatible bug fixes labels Mar 5, 2026
@mitchchn
Copy link
Copy Markdown
Member Author

mitchchn commented Mar 5, 2026

@mitchchn the bots want target/* labels. Which branches need this fix?

Only 41 and up.

Copy link
Copy Markdown
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

Looks like mac arm64 tests are failing. Can you rebase this PR to see if that resolves those failing tests?

@mitchchn mitchchn requested a review from jkleinsc March 26, 2026 00:29
Copy link
Copy Markdown
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

Looks like this change is causing mac arm64 mas tests to fail. I'm not sure why its failing but it does look like the removed code would have executed on mac so maybe its needed there.

@mitchchn
Copy link
Copy Markdown
Member Author

mitchchn commented Mar 28, 2026

@jkleinsc yup, that test caught a subtle bug and I did need to put back a condition I removed. (Not sure why it only failed on ARM64/MAS...)

@mitchchn mitchchn requested a review from jkleinsc March 30, 2026 18:20
@ckerr ckerr added target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 2, 2026
@ckerr
Copy link
Copy Markdown
Member

ckerr commented Apr 2, 2026

Needs rereview from @jkleinsc

@jkleinsc jkleinsc merged commit 4d05010 into electron:main Apr 6, 2026
122 of 123 checks passed
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented Apr 6, 2026

Release Notes Persisted

BrowserWindow now enforces min/max size constraints on window creation, even if they conflict with the requested width and height.

trop Bot added a commit that referenced this pull request Apr 6, 2026
…#49906)

* enforce size constraints on window creation

* set constraints after resizing on init

* restore conditional centering

Co-authored-by: Mitchell Cohen <mitch.cohen@me.com>
trop Bot added a commit that referenced this pull request Apr 6, 2026
…#49906)

* enforce size constraints on window creation

* set constraints after resizing on init

* restore conditional centering

Co-authored-by: Mitchell Cohen <mitch.cohen@me.com>
@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Apr 6, 2026

I have automatically backported this PR to "41-x-y", please check out #50753

@trop trop Bot added the in-flight/41-x-y label Apr 6, 2026
@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Apr 6, 2026

I have automatically backported this PR to "42-x-y", please check out #50754

@trop trop Bot added in-flight/42-x-y and removed target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 6, 2026
ckerr pushed a commit that referenced this pull request Apr 6, 2026
…#50754)

fix: enforce size constraints on window creation on Windows and Linux (#49906)

* enforce size constraints on window creation

* set constraints after resizing on init

* restore conditional centering

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Mitchell Cohen <mitch.cohen@me.com>
@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. and removed in-flight/42-x-y labels Apr 6, 2026
ckerr pushed a commit that referenced this pull request Apr 6, 2026
…#50753)

fix: enforce size constraints on window creation on Windows and Linux (#49906)

* enforce size constraints on window creation

* set constraints after resizing on init

* restore conditional centering

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Mitchell Cohen <mitch.cohen@me.com>
@trop trop Bot added merged/41-x-y PR was merged to the "41-x-y" branch. and removed in-flight/41-x-y labels Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. platform/linux platform/windows semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants