Skip to content

Register main script handlers before the tag is parsed - #1773

Open
UmmmAGoodName wants to merge 1 commit into
JustArchiNET:mainfrom
UmmmAGoodName:fix/path-prefix-bootstrap-race
Open

UmmmAGoodName wants to merge 1 commit into
JustArchiNET:mainfrom
UmmmAGoodName:fix/path-prefix-bootstrap-race

Conversation

@UmmmAGoodName

Copy link
Copy Markdown
Contributor

Fixes #1635

Cause

index.html attached mainScript.onerror at the end of <body>, but the main bundle is a deferred <script> injected at the end of <head>. The browser starts fetching it immediately, and Firefox dispatches error for a failed deferred script as soon as the fetch fails. With a reverse proxy answering the unprefixed /scripts/main... request with a fast 404, the error arrived before the handler existed and the prefix discovery never ran.

Fix

  • Bootstrap moved into <head> ahead of the injected tag, with capturing load/error listeners on document registered before the tag is parsed. They act once on the parser-inserted main script and detach themselves. (document, not window: element load events never reach window, even in the capture phase.)
  • Base globals default to / up front, so a future mismatch degrades to root behaviour instead of leaving __BASE_URL__ undefined.
  • Retry scripts are appended only once the body is parsed, since the bundle mounts on #app synchronously and the error can now fire mid-parse.
  • Prefix walk, SRI check and __ASF_UI_LOADED__ check unchanged.

Verification

Deterministic reproduction: a small node server serves the build under /asf/, answers everything else with a fast 404, and injects a parser-blocking <script> at the start of <body> that it delays by 1.5 s. This holds the parser before the old bootstrap while the 404 for the root bundle has already arrived.

Firefox Chromium
old template white page, no retry under /asf/scripts/ loads (error dispatched after parsing)
new template loads loads

Also verified: deep nested route (/asf/bots/x/config) walks up to /asf/, root deployment without prefix sets the defaults, dev server boots.

The bootstrap that discovers a path prefix (Kestrel PathBase) attached
its onerror handler at the end of <body>, while the main bundle is a
deferred <script> injected at the end of <head>. Firefox dispatches the
error event for a failed deferred script as soon as the fetch fails, so
with a fast 404 from the proxy the handler was attached too late and the
page stayed white.

Move the bootstrap into <head> ahead of the injected tag and register
capturing load/error listeners on document up front. Default the base
globals to "/" so a non-match degrades to root behaviour, and hold retry
scripts until the body is parsed because the bundle mounts on #app
synchronously.

Fixes JustArchiNET#1635

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ASF-ui doesn't (always) respect PathBase (or url-prefix)

1 participant