-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix Chrome window.innerWidth priority for correct canvas resizing #8122
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
base: main
Are you sure you want to change the base?
Fix Chrome window.innerWidth priority for correct canvas resizing #8122
Conversation
🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors! Thank You! |
@ayushman1210 Thanks! I think |
Hi @eyaler , Thanks for the feedback! I’ve updated the code so that window.innerWidth and window.innerHeight are checked first, before document.body.clientWidth and document.documentElement.clientWidth/Height. This ensures the viewport dimensions are captured correctly and also handles scrollbars properly in Chrome. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what's the reason behind removing all the docs? I think you need to fix the PR with the minimal changes whatever needed.
@ayushman1210 i don't get it. this was the state of things before with the issue that innerWidth may be wrong, no? my suggestion was that document.documentElement.clientWidth will be used first (but i think we need more feedback before making this change) |
@eyaler
About your suggestion (use [document.documentElement.clientWidth] first )
The tradeoffs:
Because timing of which value updates when can vary across browsers, I left the resize handler deferred to rAF so whichever source we pick will be read after layout has updated. Proposed conservative change (what I can implement now) Use the following order in [getWindowWidth()] / [getWindowHeight()] : Questions / next steps Is that ordering acceptable to you (visualViewport -> documentElement -> innerWidth -> body)? Thanks |
thanks @ayushman1210
I coundn't find the added requestAnimationFrame in your PR, and in my own testing requestAnimationFrame did not solve the issue. Can you point me to the commit/line?
In my testing visualViewport does not include scrollbars just as documentElement.clientWidth, and also is wrong when rotating back just as innerWidth. I did find viewport.segments[0].width that seems to both include scrollbars and be correct after orientation change but that is still experimental and has partial support (and i don't have a good enough understanding of it)
On the contrary, I actully think scrollbar should be included if possible |
…able Prefer experimental visualViewport.segments[0] and visualViewport before window.inner* so measurements include scrollbars and handle orientation changes when available. Guard experimental access and fall back to documentElement.client* for compatibility.
@eyaler Hi maintainer !! Thanks |
@ayushman1210 sorry but i am not a maintainer... btw, i still couldn't find where you used |
@eyaler Updated implementation:
The segments API is only used when explicitly available (for foldable devices), then we fall back directly to Regarding
These functions are NOT called in the animation loop, so there's no per-frame performance impact. Thanks |
Hi @perminder-17 |
Resolves #8121
Changes:
getWindowWidth()
andgetWindowHeight()
functions inenvironment.js
to prioritizedocument.documentElement.clientWidth
anddocument.documentElement.clientHeight
overwindow.innerWidth
andwindow.innerHeight
.windowWidth
andwindowHeight
values do not update correctly when the device is rotated between portrait and landscape orientation.PR Checklist
npm run lint
passes