Recover from embed script load failures#482
Open
farhan523 wants to merge 1 commit into
Open
Conversation
If the unlayer embed script failed to load (network error, CDN hiccup, ad blocker), the dead <script> tag stayed in the document. Every subsequent loadScript call then saw isScriptInjected() return true and waited for an onload that would never fire, so the editor could never load again on that page - even after a remount. Remove the failed script tag in an onerror handler and log the failure. Queued callbacks stay pending, so the next loadScript call re-injects the script and everything proceeds normally once it loads.
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.
Summary
If the unlayer embed script fails to load (network error, CDN hiccup, ad blocker), the dead
<script>tag currently stays in the document. Every subsequentloadScriptcall then seesisScriptInjected()returntrueand waits for anonloadthat will never fire — so the editor can never load again on that page, even after a remount. The failure is also completely silent.This adds an
onerrorhandler that removes the failed script tag and logs the failure. Queued callbacks stay pending, so the nextloadScriptcall (e.g. a remount) re-injects the script, and everything proceeds normally once it loads.Testing
test/loadScript.test.ts: injects the script, dispatches anerrorevent, asserts the tag is removed and callbacks are not run; then callsloadScriptagain, dispatchesload, and asserts the queued callbacks fire. Fails without the fix.tsdx test/tsdx build— pass