Repository navigation
fix(polyfill): innerWidth and innerHeight after a window resize on Windows and Linux - #272
Merged
Merged
Conversation
…ndows and Linux Core raises orientationChanged on every window resize on Windows and Linux. The handler wrote the screen size read when the polyfill loaded, before the app window existed: the screen's 1920x1080 defaults, swapped for a landscape window. Through the live metrics' setters that pinned innerWidth and innerHeight at 1080x1920 for good, over the window's size and over whatever the page had assigned. Anything sized from them after a resize (maximize, full screen) was wrong: a game framing its camera from innerHeight zoomed far out. On Windows and Linux the handler now leaves the sizes to the live metrics, which read the window, and only updates the orientation and emits resize. iOS and Android keep the rotation swap.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
ℹ️ Note: npm publishing is disabled for pull requests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Core raises
orientationChangedon every window resize on Windows and Linux. The polyfill's handler (resize.ts) then wrote the screen size it read at load time. At load the app window doesn't exist yet, so that size is the screen's 1920x1080 default, and for a landscape window the handler swaps it. Because the write goes through the live metrics' setters, it pinnedinnerWidth/innerHeightat 1080x1920 for the rest of the session. That overrode both the window's real size and anything the page had assigned.The symptom: after maximizing or entering full screen, anything sized from
innerWidth/innerHeightgoes wrong. In a PixiJS game on Windows (1536x864 DIPs at 125%), the menu camera framed itself frominnerHeight= 1920, so the scene zoomed far out and the character drifted to the top of the stage. It stayed that way after restoring the window.Fix
On Windows and Linux, the handler no longer writes the sizes. The live metrics already read the window (
Screen.mainScreen.widthDIPs/heightDIPs), so the handler only updatesorientationand emitsresize. iOS and Android keep the rotation swap.Tests
packages/canvas-polyfill/__test__/resize.test.mjs(node --test packages/canvas-polyfill/__test__/resize.test.mjs):innerWidth/innerHeightfollow the window after a resize. This fails on master (1080x1920).I verified it on a Windows laptop: with the patched
resize.js,innerWidth/innerHeightmatch the window after F11, after leaving F11, and after maximize, and the camera framing is correct in all three.