From 171585491dd1bee4f30691328bd22e978f3ac79e Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Tue, 13 Jul 2021 18:07:09 +0800 Subject: [PATCH] fix: logger unique names (#2575) --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 8331f84..5b5fc8a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,7 +29,12 @@ if (typeof window !== 'undefined') { CacheStorage.setContext(window); } +let instanceCount = 1; + const renderElement = async (element: HTMLElement, opts: Partial): Promise => { + if (typeof element !== 'object') { + return Promise.reject('Invalid element provided as first argument'); + } const ownerDocument = element.ownerDocument; if (!ownerDocument) { @@ -42,7 +47,7 @@ const renderElement = async (element: HTMLElement, opts: Partial): Prom throw new Error(`Document is not attached to a Window`); } - const instanceName = (Math.round(Math.random() * 1000) + Date.now()).toString(16); + const instanceName = `#${instanceCount++}`; const {width, height, left, top} = isBodyElement(element) || isHTMLElement(element) ? parseDocumentSize(ownerDocument) : parseBounds(element);