fix: fix dev HMR edge case and guard main() call

This commit is contained in:
AdenMGB committed 2026-11-03 08:38:02 +10:30
1 parent 92639ccf32
commit 63ab7a0b0e
3 files changed
+45 -37

No files matched your search

+9 -1
View File
@@ -2,6 +2,8 @@
// is SEQTA and loads the rest of the extension on demand. Importing seqta/boot
// statically here made every site download and parse the whole bundle.
import { recoverFromStaleDevModuleGraph } from "@/seqta/devModuleGraphRecovery";
let hasSEQTAText = false;
let isSeqtaPage = false;
@@ -18,7 +20,7 @@ if (document.childNodes[1]) {
}
if (hasSEQTAText) {
void import("@/seqta/boot").then(({ boot }) => boot(isSeqtaPage));
void import("@/seqta/boot").then(({ boot }) => boot());
}
// Standalone 404 documents never pass the SEQTA SPA gate above.
@@ -27,3 +29,9 @@ if (!isSeqtaPage) {
bootErrorPage(),
);
}
if (import.meta.env.DEV) {
window.addEventListener("unhandledrejection", (event) => {
recoverFromStaleDevModuleGraph(event.reason);
});
}
+14 -36
View File
@@ -20,6 +20,7 @@ import {
ensureKilledModeSettingsAccess,
} from "@/seqta/utils/remoteConfig/runtime";
import { runStartupPopupQueue } from "@/seqta/utils/Openers/StartupPopupQueue";
import { recoverFromStaleDevModuleGraph } from "@/seqta/devModuleGraphRecovery";
function registerFetchSeqtaAppLinkListener() {
browser.runtime.onMessage.addListener((request, _sender, sendResponse) => {
@@ -47,24 +48,24 @@ function registerFetchSeqtaAppLinkListener() {
var IsSEQTAPage = false;
/**
* Loaded on demand by SEQTA.ts for pages with the SEQTA copyright comment.
* `isSeqtaPage` is true when the title also matched SEQTA Learn/Engage.
*/
export function boot(isSeqtaPage: boolean) {
/** Loaded on demand by SEQTA.ts for pages with the SEQTA copyright comment. */
export function boot() {
installSeqtaMenuColourPatch();
installThemeImagePagePatch();
if (isSeqtaPage) init();
}
if (import.meta.env.DEV) {
window.addEventListener("unhandledrejection", (event) => {
recoverFromStaleDevModuleGraph(event.reason);
});
void init();
}
async function init() {
if (!IsSEQTAPage) {
const hasSEQTAText =
document.childNodes[1]?.textContent?.includes(
"Copyright (c) SEQTA Software",
) ?? false;
if (
hasSEQTAText &&
(document.title.includes("SEQTA Learn") ||
document.title.includes("SEQTA Engage")) &&
!IsSEQTAPage
) {
IsSEQTAPage = true;
verboseInfo("[BetterSEQTA+] Verified SEQTA Page");
@@ -159,26 +160,3 @@ function replaceIcons() {
}
});
}
/** Vite/CRX HMR can leave modules with missing named exports until the graph is cleared. */
function recoverFromStaleDevModuleGraph(error: unknown) {
if (!import.meta.env.DEV) return;
const message = error instanceof Error ? error.message : String(error);
if (!/does not provide an export named/.test(message)) return;
const key = "bsplus-dev-export-recovery";
if (!sessionStorage.getItem(key)) {
sessionStorage.setItem(key, "1");
import.meta.hot?.send("bsplus:reset-module-graph");
setTimeout(() => {
location.reload();
}, 80);
return;
}
sessionStorage.removeItem(key);
console.error(
"[BetterSEQTA+] Dev module graph is still stale after recovery. Restart `npm run dev`, then reload this page.",
);
}
+22
View File
@@ -0,0 +1,22 @@
/** Vite/CRX HMR can leave modules with missing named exports until the graph is cleared. */
export function recoverFromStaleDevModuleGraph(error: unknown) {
if (!import.meta.env.DEV) return;
const message = error instanceof Error ? error.message : String(error);
if (!/does not provide an export named/.test(message)) return;
const key = "bsplus-dev-export-recovery";
if (!sessionStorage.getItem(key)) {
sessionStorage.setItem(key, "1");
import.meta.hot?.send("bsplus:reset-module-graph");
setTimeout(() => {
location.reload();
}, 80);
return;
}
sessionStorage.removeItem(key);
console.error(
"[BetterSEQTA+] Dev module graph is still stale after recovery. Restart `npm run dev`, then reload this page.",
);
}