perf: prefetch the bundle when the host page already loaded embed.js - #56
Open
sidgaikwad wants to merge 1 commit into
Open
perf: prefetch the bundle when the host page already loaded embed.js#56sidgaikwad wants to merge 1 commit into
sidgaikwad wants to merge 1 commit into
Conversation
The load listener prefetches the versioned bundle so the first createEditor does not pay a second round trip, but the early return for an already-installed window.ImageEditor bypassed it entirely. So on exactly the pages the tag-reuse logic exists to support — where the host injected embed.js itself — the prefetch never happened and the first mount was a full round trip slower than the injected path. The embed loader caches its own promise, so the duplicate call is a no-op when the host already triggered it. Also make the reused-tag timeout a parameter (defaulting to the exported REUSED_TAG_TIMEOUT_MS) rather than a hardcoded constant, so the bound is overridable and directly testable.
|
@sidgaikwad is attempting to deploy a commit to the Unlayer Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #44.
1. The prefetch was skipped on host-injected pages (the real fix)
The
loadlistener prefetches the versioned bundle so the firstcreateEditordoesn't pay a second round trip — but the early return bypassed it:So on exactly the pages the tag-reuse logic exists to support — where the host injected
embed.jsitself — the prefetch never happened and the first mount was a full network round trip slower than the injected path.The embed loader caches its own promise, so the duplicate call is a no-op when the host already triggered it. The rejection is swallowed identically to the existing listener, since the same failure resurfaces through
createEditor.Red without the fix:
2. The reused-tag timeout
REUSED_TAG_TIMEOUT_MSis now exported andloadScripttakes it as an optional second argument, so the bound is overridable and directly testable rather than requiringvi.advanceTimersByTime(30_000).I deliberately stopped short of a component prop.
loadScriptisn't exported from the package entry point, so surfacing this to consumers means either exporting the module or adding a prop alongsidescriptUrl— an API decision that's yours, not mine. This change makes either one a one-liner later. Say the word and I'll add the prop in this PR.Verification
lint,typecheck,buildclean