Skip to content

Commit 730438e

Browse files
committed
fix(core): preserve legacy falsy canvas sizing
1 parent a4a5736 commit 730438e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

modules/core/src/adapter/canvas-surface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ export abstract class CanvasSurface {
303303
pixelRatio === undefined ? 'exact' : 'css-dpr'
304304
);
305305
} else if ('useDevicePixels' in props && this._usesLegacyDrawingBufferSizing) {
306-
this.props.useDevicePixels = props.useDevicePixels ?? false;
306+
// Preserve the legacy setter's falsy-value normalization (notably numeric `0`).
307+
this.props.useDevicePixels = props.useDevicePixels || false;
307308
const drawingBufferSizeProps = normalizeLegacyDrawingBufferSizeProps(this.props);
308309
this._setDrawingBufferSizeProps(
309310
drawingBufferSizeProps.drawingBufferSizeTracking,

modules/core/test/adapter/canvas-context.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,18 @@ test('CanvasContext#new drawing buffer sizing props override and validate legacy
691691
'legacy autoResize false normalizes to no tracking'
692692
);
693693

694+
legacyNumericCanvasContext.setProps({useDevicePixels: 0});
695+
t.equal(
696+
legacyNumericCanvasContext.props.useDevicePixels,
697+
false,
698+
'legacy setProps preserves falsy numeric normalization'
699+
);
700+
t.equal(
701+
legacyNumericCanvasContext.props.pixelRatio,
702+
1,
703+
'legacy setProps treats a falsy numeric ratio as non-device-pixel sizing'
704+
);
705+
694706
const newCanvasContext = new TestCanvasContext(
695707
{
696708
drawingBufferSizeTracking: 'canvas',

0 commit comments

Comments
 (0)