@micha.bigler/ui-core-micha 4.13.0 → 4.14.0
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.
- package/CHANGELOG.md +8 -0
- package/README.md +16 -0
- package/dist/index.js +1 -0
- package/dist/utils/chunkLoadRecovery.js +65 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.14.0 - UCM-PERF-5
|
|
4
|
+
|
|
5
|
+
New `installChunkLoadRecovery({ guardWindowMs?, reload? })` and `isChunkLoadError(error)`. Installed once at app
|
|
6
|
+
startup, a failed chunk load after a deploy (Vite `vite:preloadError` or an unhandled dynamic-import rejection whose
|
|
7
|
+
error is a fetch failure) reloads the page once; a repeat within the guard window (default 60 s, held in
|
|
8
|
+
`sessionStorage` across the reload) does not, and without usable storage nothing reloads. Module evaluation errors and
|
|
9
|
+
all other errors are left alone. Additive; nothing changes for apps that do not install it.
|
|
10
|
+
|
|
3
11
|
## 4.13.0 - UCM-AUTH-14
|
|
4
12
|
|
|
5
13
|
Composable account and profile steps for a page-based setup wizard; all additive. New exports: `SetupWizardShell`
|
package/README.md
CHANGED
|
@@ -86,6 +86,22 @@ const setupBillingApi = createBillingApi({
|
|
|
86
86
|
<PlanPicker api={setupBillingApi} plans={plans} />;
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
## Stale chunks after a deploy
|
|
90
|
+
|
|
91
|
+
An app that lazy-loads code calls `installChunkLoadRecovery()` once at startup (before rendering). When a deploy has
|
|
92
|
+
removed a chunk that an open page still asks for ("Failed to fetch dynamically imported module", Vite's
|
|
93
|
+
`vite:preloadError`, "Unable to preload CSS"), the page reloads once onto the new build. A second chunk failure within
|
|
94
|
+
60 seconds of that reload is left alone and surfaces as today, so a genuinely broken deploy cannot loop; a later failure
|
|
95
|
+
reloads again. Without usable `sessionStorage` it never reloads. Other errors are untouched; `isChunkLoadError(error)`
|
|
96
|
+
lets an error boundary tell the cases apart. Option `guardWindowMs` changes the window; the function returns an
|
|
97
|
+
uninstall. A reload loses unsaved input, so do not lazy-load routes where people type before the chunk is needed.
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
import { installChunkLoadRecovery } from '@micha.bigler/ui-core-micha';
|
|
101
|
+
|
|
102
|
+
installChunkLoadRecovery();
|
|
103
|
+
```
|
|
104
|
+
|
|
89
105
|
## Consumer integration check
|
|
90
106
|
|
|
91
107
|
```js
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import './theme/fonts';
|
|
|
8
8
|
export { createAppTheme, assertThemeComplete, assertKitSxDisjoint, calculateContrastRatio, KIT_COMPONENT_SX_REGISTRY, reportOffPaletteColours, reportKitSxBypasses, reportRedundantThemeValues, reportThemeAdoption, THEME_COMPLETENESS_SURFACES, } from './theme';
|
|
9
9
|
// --- 0.1 Consumer integration ---
|
|
10
10
|
export { checkKitIntegration } from './testing/checkKitIntegration';
|
|
11
|
+
export { installChunkLoadRecovery, isChunkLoadError } from './utils/chunkLoadRecovery';
|
|
11
12
|
// --- 1. Auth Context (Essentiell für den Wrapper) ---
|
|
12
13
|
export { AuthContext, AuthProvider } from './auth/AuthContext';
|
|
13
14
|
export { UserMenu } from './auth/UserMenu';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const LAST_RELOAD_KEY = 'ucm:chunk-load-recovery:last-reload';
|
|
2
|
+
const DEFAULT_GUARD_WINDOW_MS = 60000;
|
|
3
|
+
let activeInstallation = null;
|
|
4
|
+
/**
|
|
5
|
+
* Returns whether an error indicates that a JavaScript or CSS module chunk could not be fetched.
|
|
6
|
+
* Errors thrown while evaluating a successfully fetched module do not count.
|
|
7
|
+
*/
|
|
8
|
+
export function isChunkLoadError(error) {
|
|
9
|
+
if (!error || (typeof error !== 'object' && typeof error !== 'function'))
|
|
10
|
+
return false;
|
|
11
|
+
if (error.name === 'ChunkLoadError')
|
|
12
|
+
return true;
|
|
13
|
+
if (typeof error.message !== 'string')
|
|
14
|
+
return false;
|
|
15
|
+
return /failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed|unable to preload css/i.test(error.message);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Installs one-shot recovery for failed Vite or unhandled dynamic module loads.
|
|
19
|
+
* The session storage guard defaults to 60 seconds and survives a page reload; storage failures
|
|
20
|
+
* leave the error untouched. Options accept `guardWindowMs` and an injected `reload` function.
|
|
21
|
+
* Returns an uninstall function, or a no-op when called without `window`.
|
|
22
|
+
*/
|
|
23
|
+
export function installChunkLoadRecovery({ guardWindowMs = DEFAULT_GUARD_WINDOW_MS, reload = () => window.location.reload() } = {}) {
|
|
24
|
+
if (typeof window === 'undefined')
|
|
25
|
+
return () => { };
|
|
26
|
+
if (activeInstallation)
|
|
27
|
+
return activeInstallation.uninstall;
|
|
28
|
+
// A zero, negative or non-numeric window would disable the loop guard; use the default instead.
|
|
29
|
+
const windowMs = Number.isFinite(guardWindowMs) && guardWindowMs > 0 ? guardWindowMs : DEFAULT_GUARD_WINDOW_MS;
|
|
30
|
+
const tryRecover = (error, event) => {
|
|
31
|
+
if (!isChunkLoadError(error))
|
|
32
|
+
return;
|
|
33
|
+
let storage;
|
|
34
|
+
try {
|
|
35
|
+
storage = window.sessionStorage;
|
|
36
|
+
const previousValue = storage.getItem(LAST_RELOAD_KEY);
|
|
37
|
+
const previousReload = Number(previousValue);
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
if (previousValue !== null && Number.isFinite(previousReload) && now - previousReload < windowMs)
|
|
40
|
+
return;
|
|
41
|
+
const storedTime = String(now);
|
|
42
|
+
storage.setItem(LAST_RELOAD_KEY, storedTime);
|
|
43
|
+
if (storage.getItem(LAST_RELOAD_KEY) !== storedTime)
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
catch (_a) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
50
|
+
reload();
|
|
51
|
+
};
|
|
52
|
+
const onVitePreloadError = (event) => tryRecover(event.payload, event);
|
|
53
|
+
const onUnhandledRejection = (event) => tryRecover(event.reason, event);
|
|
54
|
+
window.addEventListener('vite:preloadError', onVitePreloadError);
|
|
55
|
+
window.addEventListener('unhandledrejection', onUnhandledRejection);
|
|
56
|
+
const uninstall = () => {
|
|
57
|
+
if ((activeInstallation === null || activeInstallation === void 0 ? void 0 : activeInstallation.uninstall) !== uninstall)
|
|
58
|
+
return;
|
|
59
|
+
window.removeEventListener('vite:preloadError', onVitePreloadError);
|
|
60
|
+
window.removeEventListener('unhandledrejection', onUnhandledRejection);
|
|
61
|
+
activeInstallation = null;
|
|
62
|
+
};
|
|
63
|
+
activeInstallation = { uninstall };
|
|
64
|
+
return uninstall;
|
|
65
|
+
}
|