[fix](trx-frontend-http): fix map-core.js crash when cached scripts race app.js

Dynamic scripts (map-core.js etc.) are effectively async and can execute
before the defer'd app.js that creates window.trx. When map-core.js is
served from browser cache it loads instantly and crashes on
`const T = window.trx` (undefined), preventing window.trx.map from
ever being set — the map never initialises and Ctrl+R is needed.

Move eager plugin loading from the inline script to app.js, triggered
via window.loadEagerPlugins() after window.trx is fully populated.
This guarantees the namespace exists before any plugin script runs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
2026-04-04 15:44:44 +02:00
parent 71650c0e70
commit 2a1c97a8dd
2 changed files with 11 additions and 6 deletions
@@ -4766,6 +4766,10 @@ Object.defineProperties(window.trx, {
locationSubtitle: { get() { return locationSubtitle; } },
});
// Load plugin scripts now that window.trx is populated. Dynamic scripts are
// async so they must not be created before the namespace they depend on exists.
if (typeof window.loadEagerPlugins === "function") window.loadEagerPlugins();
// Start the app
initializeApp();
window.addEventListener("resize", resizeHeaderSignalCanvas);
@@ -1646,12 +1646,13 @@
document.body.appendChild(s);
});
}
// Load core plugins immediately (needed on main tab).
// 'map-data' loads map-core.js + data handlers (ais/aprs/vdes/hf-aprs) eagerly
// so decode history replay can populate map data structures before the map
// tab is opened. The 'loaded' Set prevents double-loading when the map tab
// is later activated.
['digital-modes', 'map-data', 'bookmarks', 'settings'].forEach(loadPlugins);
// Eager plugin loading is triggered by app.js (after window.trx is set up)
// via window.loadEagerPlugins(). Dynamic scripts are effectively async, so
// loading them before app.js would cause map-core.js to crash when
// window.trx is not yet defined.
window.loadEagerPlugins = function() {
['digital-modes', 'map-data', 'bookmarks', 'settings'].forEach(loadPlugins);
};
// Load others on tab switch
document.addEventListener('click', function(e) {
var tab = e.target.closest('[data-tab]');