Fix device constructor crash when canvas lacks getBoundingClientRect#9000
Merged
Conversation
Build size reportThis PR changes the size of the minified bundles.
|
mvaligursky
added a commit
that referenced
this pull request
Jul 2, 2026
…9000) Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
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.
Fixes #8999
Since v2.20.0 (#8950), the base
GraphicsDeviceconstructor callsupdateClientRect(), which unconditionally callsthis.canvas.getBoundingClientRect()outside of Web Workers. This broke the documented headless path — constructing aNullGraphicsDevicewith a mock canvas (e.g.{ id: 'mock' }, as@playcanvas/reactdoes for SSR) now throws, which broke static site generation on developer.playcanvas.com.Changes:
GraphicsDevice#updateClientRectnow uses a capability check (typeof this.canvas.getBoundingClientRect === 'function') instead of theplatform.workerenvironment check. When the method is missing (OffscreenCanvas in workers, mock canvases in headless environments), it falls back tothis.canvas.width ?? 0/height ?? 0, so a bare mock object yieldsclientRect = { width: 0, height: 0 }rather than throwing or producing NaN.getBoundingClientRecteither), and real DOM canvases still get a validclientRectat construction time, preserving the intent of Fix camera.screenToWorld returning NaN when called in initialize #8950.getBoundingClientRect, a mock withwidth/height, and a DOM canvas usinggetBoundingClientRect.