video-flow-b/utils/dev-helper.tsx
2025-07-25 11:41:12 +08:00

28 lines
847 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { useEffect } from 'react';
export default function DevHelper() {
useEffect(() => {
// 在客户端环境下设置全局错误处理
if (typeof window !== 'undefined') {
window.addEventListener('error', (event) => {
if (event.error?.name === 'ChunkLoadError' || event.error?.message?.includes('Loading chunk')) {
console.warn('检测到 ChunkLoadError尝试刷新页面');
window.location.reload();
event.preventDefault();
}
});
window.addEventListener('unhandledrejection', (event) => {
if (event.reason?.name === 'ChunkLoadError') {
console.warn('检测到未处理的 ChunkLoadError Promise 拒绝');
event.preventDefault();
window.location.reload();
}
});
}
}, []);
return null;
}