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.
src/loadScript.tshas two small rough edges — neither is a correctness bug, both are cheap.1. The prefetch is skipped when the page already loaded
embed.jsThe
loadlistener prefetches the versioned bundle so the firstcreateEditordoesn'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:
So on any page where the host injected
embed.jsitself — 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. Callingwindow.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_000is 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 alongsidescriptUrl, or at least exporting the constant.