Skip to content

fix: preserve size constraints across maximise/unmaximise cycle#5204

Merged
leaanthony merged 2 commits into
masterfrom
fix/4593-togglemaximize-constraints
May 31, 2026
Merged

fix: preserve size constraints across maximise/unmaximise cycle#5204
leaanthony merged 2 commits into
masterfrom
fix/4593-togglemaximize-constraints

Conversation

@leaanthony

@leaanthony leaanthony commented Apr 21, 2026

Copy link
Copy Markdown
Member

Summary

  • DisableSizeConstraints() was overwriting MinWidth/MinHeight/MaxWidth/MaxHeight options with 0 via the platform impl, so EnableSizeConstraints() could never restore them
  • After calling ToggleMaximise() or UnMaximise(), min/max window constraints were permanently lost
  • Save original values in savedMinWidth/savedMinHeight/savedMaxWidth/savedMaxHeight before zeroing; restore from saved values on re-enable

Test plan

  • TestDisableSizeConstraintsSavesValues verifies values are saved before zeroing
  • TestRestoreAfterZeroingOptions verifies saved values can restore the originals
  • TestDisableSizeConstraintsDoesNotOverwriteSavedValues verifies saved values survive options being zeroed
  • Manual: set min size, maximise, unmaximise, verify min size constraint is still active

Fixes #4593

Summary by CodeRabbit

  • Bug Fixes
    • Window size constraints (minimum and maximum dimensions) are now properly preserved when temporarily disabled during fullscreen or maximize operations, and automatically restored when re-enabled.

DisableSizeConstraints() was overwriting the original MinWidth/MinHeight/
MaxWidth/MaxHeight option values with 0, so EnableSizeConstraints() could
never restore them. This caused ToggleMaximise and UnMaximise to permanently
lose window size constraints.

Save the original constraint values before zeroing and restore from saved
values when re-enabling constraints.

Fixes #4593
@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e9dfed9a-30cb-4a00-879d-b644b0485ec9

📥 Commits

Reviewing files that changed from the base of the PR and between 5df229f and 9e0bac9.

📒 Files selected for processing (2)
  • v3/pkg/application/webview_window.go
  • v3/pkg/application/webview_window_test.go

Walkthrough

WebviewWindow now saves min/max width and height when size constraints are disabled and restores those saved values when constraints are re-enabled, using saved fields and a constraintsSaved flag.

Changes

Size Constraint Persistence

Layer / File(s) Summary
Constraint persistence state and restoration logic
v3/pkg/application/webview_window.go
WebviewWindow adds savedMinWidth, savedMinHeight, savedMaxWidth, savedMaxHeight, and constraintsSaved. DisableSizeConstraints saves current options min/max into saved fields on first disable. EnableSizeConstraints restores from saved fields when present and reapplies constraints via SetMinSize/SetMaxSize.
Constraint persistence test suite
v3/pkg/application/webview_window_test.go
Unit tests with mockWindowImpl: TestDisableSizeConstraintsSavesValues verifies initial save, TestRestoreAfterZeroingOptions verifies restoration after options are zeroed, and TestDisableSizeConstraintsDoesNotOverwriteSavedValues ensures saved values are preserved when already set.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wailsapp/wails#3979: Also touches Webview window min/max constraint behavior and Linux min/max calculation/application.

Suggested labels

Bug, v3, Windows, size:M

Poem

🐰 I hopped around a window wide and tall,
Its bounds would vanish when it lost control.
I tucked the sizes in a tiny nest,
Restored them safe when toggles left their test.
Now constraints remember — no more fall.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4593-togglemaximize-constraints

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leaanthony leaanthony changed the base branch from v3-alpha to master April 29, 2026 13:07
@leaanthony

Copy link
Copy Markdown
Member Author

Tested on Windows 11 Pro 24H2 (Build 26100) — verdict: ✓ pass

  • Commit: 96ae4ba71c
  • Build: 16042ms successful (pkg/application with CGo/WebView2)
  • Unit tests: 3/3 passing
  • Visual smoke: badge example binary (21 MB) built and launched; WebView2 147.0.3912.98 detected at startup; headless PSDirect crash (no desktop session) is unrelated to this PR

Test results:

  • TestDisableSizeConstraintsSavesValues — PASS
  • TestRestoreAfterZeroingOptions — PASS
  • TestDisableSizeConstraintsDoesNotOverwriteSavedValues — PASS

The save/restore logic correctly guards with constraintsSaved so a second DisableSizeConstraints call before EnableSizeConstraints does not overwrite the originally-saved values.


PR test pass on Windows (go1.26.2 / WebView2 147.0.3912.98 / amd64)

@leaanthony

Copy link
Copy Markdown
Member Author

Good bug fix! Losing size constraints after maximise/unmaximise is a real issue for applications that need strict window sizing. The save/restore pattern is correct.

I've dispatched cross-platform test sub-issues:

  • WAI-231 - macOS testing (includes this PR)
  • WAI-232 - Linux testing (includes this PR)
  • WAI-233 - Windows testing (includes this PR)

Once all platforms report back with successful test results, I'll apply the reviewed ✅ label.

CC @leaanthony

@leaanthony

Copy link
Copy Markdown
Member Author

Investigating on Windows 11 Pro (24H2, Build 26100).

Test environment: Go 1.26.2 · WebView2 147.0.3912.86

Unit tests (go test ./pkg/application/... -run TestDisableSizeConstraints -v):

=== RUN   TestDisableSizeConstraintsSavesValues
--- PASS: TestDisableSizeConstraintsSavesValues (0.00s)
=== RUN   TestDisableSizeConstraintsDoesNotOverwriteSavedValues
--- PASS: TestDisableSizeConstraintsDoesNotOverwriteSavedValues (0.00s)
PASS
ok  	github.com/wailsapp/wails/v3/pkg/application	1.188s

Both constraint-save/restore tests pass on Windows. The savedMin*/savedMax*/constraintsSaved fields and DisableSizeConstraints/EnableSizeConstraints logic are correct.

CC @leaanthony

@leaanthony leaanthony added this to the v3.0.0-beta.1 milestone May 20, 2026
@leaanthony leaanthony marked this pull request as ready for review May 31, 2026 07:33
Copilot AI review requested due to automatic review settings May 31, 2026 07:33
@leaanthony leaanthony merged commit a9e6a56 into master May 31, 2026
13 of 15 checks passed
@leaanthony leaanthony deleted the fix/4593-togglemaximize-constraints branch May 31, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wails v3 Unable to restrict the minimum width and height of the window.

2 participants