Skip to content

Recover from embed script load failures#482

Open
farhan523 wants to merge 1 commit into
unlayer:masterfrom
farhan523:fix/load-script-error-recovery
Open

Recover from embed script load failures#482
farhan523 wants to merge 1 commit into
unlayer:masterfrom
farhan523:fix/load-script-error-recovery

Conversation

@farhan523

Copy link
Copy Markdown

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 subsequent loadScript call then sees isScriptInjected() return true and waits for an onload that 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 onerror handler that removes the failed script tag and logs the failure. Queued callbacks stay pending, so the next loadScript call (e.g. a remount) re-injects the script, and everything proceeds normally once it loads.

Testing

  • New test in test/loadScript.test.ts: injects the script, dispatches an error event, asserts the tag is removed and callbacks are not run; then calls loadScript again, dispatches load, and asserts the queued callbacks fire. Fails without the fix.
  • tsdx test / tsdx build — pass

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant