Skip to content

Commit

Permalink
fix(core): harden size state check (#3055)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett authored Oct 22, 2023
1 parent d83ae44 commit b038c4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/fiber/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,21 @@ export type ReconcilerRoot<TCanvas extends Canvas> = {
}

function computeInitialSize(canvas: Canvas, defaultSize?: Size): Size {
if (defaultSize) return defaultSize
const defaultStyle = typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement

if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
if (defaultSize) {
const { width, height, top, left, updateStyle = defaultStyle } = defaultSize
return { width, height, top, left, updateStyle }
} else if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
const { width, height, top, left } = canvas.parentElement.getBoundingClientRect()
return { width, height, top, left }
return { width, height, top, left, updateStyle: defaultStyle }
} else if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {
return {
width: canvas.width,
height: canvas.height,
top: 0,
left: 0,
updateStyle: defaultStyle,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/fiber/src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const createStore = (
const { camera, size, viewport, gl, set } = rootState.getState()

// Resize camera and renderer on changes to size and pixelratio
if (size !== oldSize || viewport.dpr !== oldDpr) {
if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
oldSize = size
oldDpr = viewport.dpr
// Update camera & renderer
Expand Down

0 comments on commit b038c4e

Please sign in to comment.