Skip to content

loadScript: prefetch skipped on host-injected pages, and the 30s reused-tag timeout is not configurable #44

Description

@sidgaikwad

src/loadScript.ts has two small rough edges — neither is a correctness bug, both are cheap.

1. The prefetch is skipped when the page already loaded embed.js

The load listener prefetches the versioned bundle so the first createEditor doesn't pay a second round trip:

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

But the early return on line 40 bypasses it entirely:

if (window.ImageEditor) {
  return Promise.resolve();
}

So on any page where the host injected embed.js itself — the exact scenario the tag-reuse logic on line 52 exists to support — the prefetch never happens and the first mount is a full round trip slower than it needs to be. Calling window.ImageEditor.load().catch(() => {}) before resolving would make both paths behave the same. (The embed loader caches its own promise, so an extra call is a no-op if the host already triggered it.)

2. The reused-tag timeout isn't configurable

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

REUSED_TAG_TIMEOUT_MS = 30_000 is a module constant. The reasoning behind having a bound is sound and well documented, but 30s is a long time to stare at a blank editor (see #37) and there's no way to shorten it — or to lengthen it on a slow network — without forking. Worth exposing through the component's props alongside scriptUrl, or at least exporting the constant.

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