diff --git a/src/vis/vishooks/hooks/useCanvas.ts b/src/vis/vishooks/hooks/useCanvas.ts index 84643732c..43c8b71ea 100644 --- a/src/vis/vishooks/hooks/useCanvas.ts +++ b/src/vis/vishooks/hooks/useCanvas.ts @@ -6,6 +6,8 @@ export function useCanvas { const observer = new ResizeObserver((entries) => { - if (entries[0]) { - const newDimensions = entries[0].contentRect; + const entry = entries[0]; + + if (entry) { + const newDimensions = entry.contentRect; + + let pixelContentWidth = 0; + let pixelContentHeight = 0; + + if ('devicePixelContentBoxSize' in entry && entry.devicePixelContentBoxSize?.[0]) { + // Feature is present + const { inlineSize, blockSize } = entry.devicePixelContentBoxSize[0]; + + pixelContentWidth = inlineSize; + pixelContentHeight = blockSize; + } else { + // Feature is not supported, round the canvas pixel buffer to an integer value that most likely snaps to the physical pixels + pixelContentWidth = Math.round(newDimensions.width * scaleFactor); + pixelContentHeight = Math.round(newDimensions.height * scaleFactor); + } setState((previous) => { if (previous.width === newDimensions.width && previous.height === newDimensions.height && previous.context) { @@ -35,6 +54,8 @@ export function useCanvas