From 67dba981a15b04a84512de277f633d0f7d19d543 Mon Sep 17 00:00:00 2001 From: Zaytsev Kirill Date: Thu, 21 Oct 2021 12:45:43 +0300 Subject: [PATCH] fix: Blob objects are no longer cloned --- src/utils/clone.ts | 3 ++- test/unit/utils/clone.test.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/clone.ts b/src/utils/clone.ts index 6275f19..5cb949c 100644 --- a/src/utils/clone.ts +++ b/src/utils/clone.ts @@ -9,7 +9,8 @@ const cloneInstance = (original: T): T => { * case of needing to unbind reactive watchers. */ export default function clone (value: T): T { - if (isScalar(value)) { + // scalars & immutables + if (isScalar(value) || value instanceof Blob) { return value } diff --git a/test/unit/utils/clone.test.js b/test/unit/utils/clone.test.js index bccaa08..ea95a7e 100644 --- a/test/unit/utils/clone.test.js +++ b/test/unit/utils/clone.test.js @@ -76,4 +76,11 @@ describe('clone', () => { expect(copy.sample.doSomething).toBeTruthy() expect(copy.sample.doSomething).not.toThrow() }) + + test('does not create a copy of a blob', () => { + const blob = new Blob(['{"fieldA": "fieldA"}'], { type : 'application/json' }) + const copy = clone(blob) + + expect(blob === copy).toBeTruthy() + }) })