Skip to content
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

fix(core): harden size state check #3055

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}

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 Expand Up @@ -514,7 +518,7 @@
...rest,
} as RootState
},
[state],

Check warning on line 521 in packages/fiber/src/core/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

React Hook React.useCallback has missing dependencies: 'container', 'events', 'pointer', 'previousRoot', 'raycaster', 'rest', and 'size'. Either include them or remove the dependency array
)

const [usePortalStore] = React.useState(() => {
Expand Down Expand Up @@ -547,11 +551,11 @@
unsub()
usePortalStore.destroy()
}
}, [])

Check warning on line 554 in packages/fiber/src/core/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

React Hook React.useEffect has missing dependencies: 'inject', 'previousRoot', and 'usePortalStore'. Either include them or remove the dependency array

React.useEffect(() => {
usePortalStore.setState((injectState) => inject(previousRoot.getState(), injectState))
}, [inject])

Check warning on line 558 in packages/fiber/src/core/index.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test

React Hook React.useEffect has missing dependencies: 'previousRoot' and 'usePortalStore'. Either include them or remove the dependency array

return (
<>
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