DPR goes stale when devicePixelRatio changes (moving to another display, browser zoom)

Author: tonyblu331Created Sep 25, 2026Updated Sep 26, 2026
Labelsbugcorev10v9

<Canvas> resolves dpr against window.devicePixelRatio only when it configures. Moving the window to a display with a different ratio, or zooming the page, changes the ratio without always resizing the canvas. Nothing re-configures, so the drawing buffer keeps the old ratio.

Repro

  1. <Canvas> with the default dpr={[1, 2]} on a 2× laptop screen.
  2. Drag the window to a 1× external monitor, keeping the same CSS size.
  3. useThree((s) => s.viewport.dpr) and gl.getPixelRatio() still report 2.

Moving the other way (1× → 2×) stays at 1 and renders blurry. Reproduced on 9.8.1 in Chromium: 960×640 for a 480×320 box after 2× → 1.25×, which is 2.56× the pixels the screen shows, at 2.56× the GPU time.

#3945 keeps the ratio resolving on every configure precisely so a Canvas follows zoom and display moves. But when nothing resizes, nothing configures. On v10, zooming a 1× desktop to 150% also stays at 1: the canvas resizes, but configure only re-applies dpr when the prop changes (#3099), so the ratio is never read again.

Why it matters

calculateDpr clamps the display ratio into the prop's range, and the drawing buffer is the CSS size times that value on each axis:

dpr    = min(max(min, devicePixelRatio), max)     // [min, max] = [1, 2] by default
buffer = cssWidth·dpr × cssHeight·dpr             // pixels grow with dpr²

A stale 2 on a 1× screen shades four times the pixels the screen can show. A stale 1 on a 2× screen shows a quarter of them, upscaled.

Expected

Re-resolve the same dpr prop when the ratio changes, under the same ownership rules configure already has:

  • v9: the prop is re-applied, as it is on every re-render.
  • v10: a setDpr() value is kept, as it is across re-configures.

No API change is needed. A matchMedia('(resolution: Xdppx)') listener per root does it. Fix and v10 port to follow.

Source: pmndrs/react-three-fiber