diff --git a/lib/core/Canvas.js b/lib/core/Canvas.js index 7a0f9c96d..f5adcc1da 100644 --- a/lib/core/Canvas.js +++ b/lib/core/Canvas.js @@ -1153,7 +1153,7 @@ Canvas.prototype._viewboxChanged = function() { Canvas.prototype.viewbox = function(box) { if (box === undefined && this._cachedViewbox) { - return JSON.parse(JSON.stringify(this._cachedViewbox)); + return structuredClone(this._cachedViewbox); } const viewport = this._viewport, diff --git a/test/spec/core/CanvasSpec.js b/test/spec/core/CanvasSpec.js index 45624d01a..20c0b5fe6 100644 --- a/test/spec/core/CanvasSpec.js +++ b/test/spec/core/CanvasSpec.js @@ -869,20 +869,11 @@ describe('Canvas', function() { it('should return copy of viewbox', inject(function(canvas) { - // given - canvas.addShape({ id: 's0', x: 0, y: 0, width: 300, height: 300 }); - - var shape = canvas.addShape({ id: 's1', x: 10000, y: 0, width: 300, height: 300 }); - - var viewbox = canvas.viewbox(), - viewboxStringified = JSON.stringify(viewbox); - // when - canvas.scrollToElement(shape); + var viewbox = canvas.viewbox(); // then - expect(JSON.stringify(viewbox)).to.eql(viewboxStringified); - expect(JSON.stringify(canvas.viewbox())).not.to.eql(viewboxStringified); + expect(viewbox).to.not.equal(canvas.viewbox()); }));