mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-31 10:14:15 +00:00
After a panel upgrade the embedded dist/ ships with new hashed chunk filenames, so SPA tabs loaded before the upgrade hold references to chunks that no longer exist on the server and lazy modals 404. Hook `vite:preloadError` and force one full reload (guarded by a session flag) so the browser picks up the new index.html.
17 lines
747 B
TypeScript
17 lines
747 B
TypeScript
// After a panel upgrade the embedded dist/ ships with new hashed chunk
|
|
// filenames, so an SPA that was loaded before the upgrade still holds
|
|
// references to chunks that no longer exist on the server. The first
|
|
// time a lazy import 404s we force a full reload so the browser picks
|
|
// up the new index.html and its new chunk references.
|
|
if (typeof window !== 'undefined') {
|
|
const RELOAD_FLAG = '__xuiChunkReloadOnce';
|
|
window.addEventListener('vite:preloadError', (event) => {
|
|
event.preventDefault();
|
|
if (sessionStorage.getItem(RELOAD_FLAG) === '1') return;
|
|
sessionStorage.setItem(RELOAD_FLAG, '1');
|
|
window.location.reload();
|
|
});
|
|
window.addEventListener('load', () => {
|
|
sessionStorage.removeItem(RELOAD_FLAG);
|
|
});
|
|
}
|