[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:
@@ -4766,6 +4766,10 @@ Object.defineProperties(window.trx, {
|
|||||||
locationSubtitle: { get() { return locationSubtitle; } },
|
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
|
// Start the app
|
||||||
initializeApp();
|
initializeApp();
|
||||||
window.addEventListener("resize", resizeHeaderSignalCanvas);
|
window.addEventListener("resize", resizeHeaderSignalCanvas);
|
||||||
|
|||||||
@@ -1646,12 +1646,13 @@
|
|||||||
document.body.appendChild(s);
|
document.body.appendChild(s);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Load core plugins immediately (needed on main tab).
|
// Eager plugin loading is triggered by app.js (after window.trx is set up)
|
||||||
// 'map-data' loads map-core.js + data handlers (ais/aprs/vdes/hf-aprs) eagerly
|
// via window.loadEagerPlugins(). Dynamic scripts are effectively async, so
|
||||||
// so decode history replay can populate map data structures before the map
|
// loading them before app.js would cause map-core.js to crash when
|
||||||
// tab is opened. The 'loaded' Set prevents double-loading when the map tab
|
// window.trx is not yet defined.
|
||||||
// is later activated.
|
window.loadEagerPlugins = function() {
|
||||||
['digital-modes', 'map-data', 'bookmarks', 'settings'].forEach(loadPlugins);
|
['digital-modes', 'map-data', 'bookmarks', 'settings'].forEach(loadPlugins);
|
||||||
|
};
|
||||||
// Load others on tab switch
|
// Load others on tab switch
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
var tab = e.target.closest('[data-tab]');
|
var tab = e.target.closest('[data-tab]');
|
||||||
|
|||||||
Reference in New Issue
Block a user