@lincyaw/kernel 1.0.0-rc.13 → 1.0.0-rc.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A page cached from before a deployment names an app version the deployment removed: its modules then fail to load
3
+ * ("Failed to fetch dynamically imported module", and the like in other browsers). The page's head answers the event
4
+ * below with one reload from the network (`STALE_RELOAD` in @lincyaw/web's page HTML).
5
+ */
6
+ export const STALE_MODULE_PATTERN = /dynamically imported module|Importing a module script failed|error loading dynamically imported module/i
7
+
8
+ /** The event a page dispatches on `window` when a module of it failed for a removed version. */
9
+ export const STALE_MODULE_EVENT = 'presmium:stale-module'
10
+
11
+ /** Reports a module load failure that a removed version explains; other failures are left alone. */
12
+ export function reportStaleModule(error: unknown): void {
13
+ if (typeof window === 'undefined' || !STALE_MODULE_PATTERN.test(String(error instanceof Error ? error.message : error))) return
14
+ window.dispatchEvent(new Event(STALE_MODULE_EVENT))
15
+ }