From 10f48aad66ffc2ea3f12ceb3e6e6a4abfac5c0ce Mon Sep 17 00:00:00 2001 From: borfyqiu Date: Wed, 28 Dec 2022 11:37:17 +0800 Subject: [PATCH] =?UTF-8?q?:=20=E5=85=A8=E5=B1=80=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E4=B8=8E=E5=85=B6=E5=AE=83=E9=81=AE=E7=BD=A9=E5=B1=82=E5=86=B2?= =?UTF-8?q?=E7=AA=81=20[issue=20129]=20=E5=B0=86MutationObserver=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E4=BA=8B=E4=BB=B6,=E9=81=BF=E5=85=8D=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E6=89=A7=E8=A1=8Crender=E5=87=BD=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=A4=9A=E6=AC=A1=E6=B3=A8=E5=86=8CMutationO?= =?UTF-8?q?bserver=20=E4=BB=8E=E8=80=8C=E8=BF=9B=E5=85=A5=E6=AD=BB?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #129 Close #129 --- packages/core/src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a7d6278..a0c128f 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -243,13 +243,18 @@ export class Watermark { if (MutationObserver && this.options.monitor) { this.mutationObserver = new MutationObserver(mutations => { + // 避免多次执行render函数,导致多次注册MutationObserver 从而进入死循环逻辑 + let lastMoutation; mutations.forEach(mutation => { if (this._isAgainRender(mutation)) { - this.destroy(); - this._render(); + lastMoutation = mutation; return; } }); + if(lastMoutation){ + this.destroy(); + this._render(); + } }); this.mutationObserver.observe(this.container, observeOptions); this.shadowRoot && this.mutationObserver.observe(this.shadowRoot, observeOptions);