28 lines
877 B
TypeScript
28 lines
877 B
TypeScript
const VIEW_TRANSITION_TIMEOUT = 'Transition was aborted because of timeout in DOM update';
|
|
|
|
export const isViewTransitionTimeoutError = (error: unknown) => {
|
|
if (process.env['NODE_ENV'] !== 'development') return false;
|
|
return (
|
|
error instanceof Error &&
|
|
error.name === 'TimeoutError' &&
|
|
error.message === VIEW_TRANSITION_TIMEOUT
|
|
);
|
|
};
|
|
|
|
export const handleGlobalError = (e: Error) => {
|
|
if (isViewTransitionTimeoutError(e)) return;
|
|
|
|
const isChunkError = e?.message?.includes('Loading chunk');
|
|
|
|
if (!isChunkError) {
|
|
const now = Date.now();
|
|
const lastReload = Number(sessionStorage.getItem('lastErrorReload') || '0');
|
|
if (now - lastReload > 60_000) {
|
|
sessionStorage.setItem('lastErrorReload', String(now));
|
|
window.location.reload();
|
|
} else {
|
|
console.warn('Error detected, but reload suppressed (rate limit)');
|
|
}
|
|
}
|
|
};
|