mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: fix dev HMR edge case and guard main() call
This commit is contained in:
1 parent
92639ccf32
commit
63ab7a0b0e
3 files changed
+45
-37
No files matched your search
+9
-1
@@ -2,6 +2,8 @@
|
|||||||
// is SEQTA and loads the rest of the extension on demand. Importing seqta/boot
|
// 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.
|
// statically here made every site download and parse the whole bundle.
|
||||||
|
|
||||||
|
import { recoverFromStaleDevModuleGraph } from "@/seqta/devModuleGraphRecovery";
|
||||||
|
|
||||||
let hasSEQTAText = false;
|
let hasSEQTAText = false;
|
||||||
let isSeqtaPage = false;
|
let isSeqtaPage = false;
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ if (document.childNodes[1]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasSEQTAText) {
|
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.
|
// Standalone 404 documents never pass the SEQTA SPA gate above.
|
||||||
@@ -27,3 +29,9 @@ if (!isSeqtaPage) {
|
|||||||
bootErrorPage(),
|
bootErrorPage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
window.addEventListener("unhandledrejection", (event) => {
|
||||||
|
recoverFromStaleDevModuleGraph(event.reason);
|
||||||
|
});
|
||||||
|
}
|
||||||
+14
-36
@@ -20,6 +20,7 @@ import {
|
|||||||
ensureKilledModeSettingsAccess,
|
ensureKilledModeSettingsAccess,
|
||||||
} from "@/seqta/utils/remoteConfig/runtime";
|
} from "@/seqta/utils/remoteConfig/runtime";
|
||||||
import { runStartupPopupQueue } from "@/seqta/utils/Openers/StartupPopupQueue";
|
import { runStartupPopupQueue } from "@/seqta/utils/Openers/StartupPopupQueue";
|
||||||
|
import { recoverFromStaleDevModuleGraph } from "@/seqta/devModuleGraphRecovery";
|
||||||
|
|
||||||
function registerFetchSeqtaAppLinkListener() {
|
function registerFetchSeqtaAppLinkListener() {
|
||||||
browser.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
browser.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||||
@@ -47,24 +48,24 @@ function registerFetchSeqtaAppLinkListener() {
|
|||||||
|
|
||||||
var IsSEQTAPage = false;
|
var IsSEQTAPage = false;
|
||||||
|
|
||||||
/**
|
/** Loaded on demand by SEQTA.ts for pages with the SEQTA copyright comment. */
|
||||||
* Loaded on demand by SEQTA.ts for pages with the SEQTA copyright comment.
|
export function boot() {
|
||||||
* `isSeqtaPage` is true when the title also matched SEQTA Learn/Engage.
|
|
||||||
*/
|
|
||||||
export function boot(isSeqtaPage: boolean) {
|
|
||||||
installSeqtaMenuColourPatch();
|
installSeqtaMenuColourPatch();
|
||||||
installThemeImagePagePatch();
|
installThemeImagePagePatch();
|
||||||
if (isSeqtaPage) init();
|
void init();
|
||||||
}
|
|
||||||
|
|
||||||
if (import.meta.env.DEV) {
|
|
||||||
window.addEventListener("unhandledrejection", (event) => {
|
|
||||||
recoverFromStaleDevModuleGraph(event.reason);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function 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;
|
IsSEQTAPage = true;
|
||||||
verboseInfo("[BetterSEQTA+] Verified SEQTA Page");
|
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.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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.",
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user