Skip to content

Commit b1c6b77

Browse files
committed
fix: don't resize the canvas if it has width and height attributes
1 parent 4f5f4fb commit b1c6b77

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/src/hooks/useWebGLCanvas.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const useWebGLCanvas = <U extends Uniforms>(props: Props<U>) => {
113113

114114
const [onCanvasReady, executeCanvasReadyCallbacks] = useHook();
115115

116-
function resizeCanvas(width: number, height: number) {
116+
function resizeCanvas(width: number, height: number, dpr: number) {
117117
setSize({ width: width * dpr, height: height * dpr });
118118
if (!isCanvasResized) {
119119
executeCanvasReadyCallbacks();
@@ -123,13 +123,16 @@ export const useWebGLCanvas = <U extends Uniforms>(props: Props<U>) => {
123123

124124
// resize only if HTMLCanvasElement, because we can't know the size of an OffscreenCanvas
125125
if (canvas instanceof HTMLCanvasElement) {
126+
if (canvas.getAttribute("width") && canvas.getAttribute("height")) {
127+
resizeCanvas(canvas.width, canvas.height, 1);
128+
}
126129
// don't automatically resize if the renderMode is manual, because the call to gl.viewport() will break the canvas
127-
if (renderMode === "auto") {
130+
else if (renderMode === "auto") {
128131
resizeObserver = useResizeObserver(canvas, ({ size }) => {
129-
resizeCanvas(size.width, size.height);
132+
resizeCanvas(size.width, size.height, dpr);
130133
});
131134
} else {
132-
resizeCanvas(canvas.clientWidth, canvas.clientHeight);
135+
resizeCanvas(canvas.clientWidth, canvas.clientHeight, dpr);
133136
}
134137
}
135138

0 commit comments

Comments
 (0)