Skip to content

resetLoader removes a host-injected embed script tag and global it does not own #32

Open

Description

@sidgaikwad

loadScript is explicitly written to cooperate with a page that loads embed.js itself:

But resetLoader tears everything down unconditionally:

https://github.com/unlayer/react-image-editor/blob/628b507/src/loadScript.ts#L122-L128

findScriptTag(scriptUrl)?.remove();
delete window.ImageEditor;

It has no notion of who created the tag, and it is called automatically from the component's terminal .catch:

https://github.com/unlayer/react-image-editor/blob/628b507/src/ImageEditor.tsx#L135-L144

Impact

On a page where the host (or another library, or a second non-React embed) owns window.ImageEditor, a versioned-bundle load failure inside our component removes a DOM node we never created and deletes a global we do not own. Any other consumer of the embed on that page breaks, and nothing tells them why.

This is the exact scenario the reuse logic on line 52 was written to support, so the two halves of the module currently disagree about ownership.

Suggested fix

Record ownership when the tag is created — a flag on TrackedLoad, a data- attribute, or a module-level WeakSet of tags we injected — and have resetLoader only remove the tag / delete the global when we own them. When we don't, evict the cached promise (and abort pending waiters) but leave the page's own state alone.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions