From aa549d0cd8d5c64ac95cdef2d41e9c978bbe8375 Mon Sep 17 00:00:00 2001 From: sidgaikwad Date: Fri, 4 Sep 2026 11:53:43 +0530 Subject: [PATCH 1/2] fix: only tear down an embed script tag we injected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit loadScript deliberately cooperates with a page that loads embed.js itself — it returns early when window.ImageEditor already exists, and reuses a host-injected tag rather than duplicating it. resetLoader did not: it removed whatever tag matched the URL and deleted window.ImageEditor unconditionally. On such a page a versioned-bundle failure inside one component removed a DOM node we never created and deleted a global we do not own, breaking every other consumer of the embed with no indication why. Track the tags we inject in a WeakSet and gate resetLoader's teardown on it. A tag that has provably failed (error event or reused-tag timeout) is still removed either way — a dead tag is no use to the host either, and leaving it would make every retry reuse it. Co-Authored-By: Claude Opus 5 --- src/loadScript.ts | 48 ++++++++++++++++++++++++++++++----------- test/loadScript.test.ts | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/src/loadScript.ts b/src/loadScript.ts index 8cceb77..c4aeb0b 100644 --- a/src/loadScript.ts +++ b/src/loadScript.ts @@ -15,6 +15,13 @@ interface TrackedLoad { // share a single