feat: 운영 안정성과 세션 음성 경험 개선
This commit is contained in:
parent
facc4ad2d9
commit
c788343467
95 changed files with 8431 additions and 1785 deletions
42
apps/web/src/lib/chunkRecovery.ts
Normal file
42
apps/web/src/lib/chunkRecovery.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
const RECOVERY_KEY_PREFIX = "vignette:chunk-recovery:";
|
||||
|
||||
type ChunkRecoveryWindow = Window & {
|
||||
__vignetteChunkRecoveryInstalled?: boolean;
|
||||
};
|
||||
|
||||
function recoveryKey(pathname: string) {
|
||||
return `${RECOVERY_KEY_PREFIX}${pathname}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cloudflare Pages 배포 전환 뒤 열린 탭이 삭제된 Vite 청크를 요청하면 한 번만
|
||||
* 최신 문서를 다시 받는다. 두 번째 실패는 ErrorBoundary로 보내 무한 새로고침을 막는다.
|
||||
*/
|
||||
export function installChunkRecovery() {
|
||||
const recoveryWindow = window as ChunkRecoveryWindow;
|
||||
if (recoveryWindow.__vignetteChunkRecoveryInstalled) return;
|
||||
recoveryWindow.__vignetteChunkRecoveryInstalled = true;
|
||||
|
||||
window.addEventListener("vite:preloadError", (event) => {
|
||||
const key = recoveryKey(window.location.pathname);
|
||||
try {
|
||||
if (window.sessionStorage.getItem(key)) return;
|
||||
window.sessionStorage.setItem(key, new Date().toISOString());
|
||||
} catch {
|
||||
// 재시도 상태를 보존할 수 없으면 무한 reload 대신 원래 오류 경계로 보낸다.
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
/** 라우트 청크가 정상 렌더된 뒤에만 같은 경로의 재시도 잠금을 해제한다. */
|
||||
export function clearChunkRecoveryMarker(pathname: string) {
|
||||
try {
|
||||
window.sessionStorage.removeItem(recoveryKey(pathname));
|
||||
} catch {
|
||||
// storage 접근 불가 환경에서도 정상 렌더는 유지한다.
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue