'use client';

import { useEffect } from 'react';
import { FC } from 'react';

const 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;
}) as FC;

export default DevHelper; 