update
This commit is contained in:
1 parent
0690285147
commit
5618cd2738
154 files changed
+5021
-3161
No files matched your search
@@ -15,6 +15,15 @@ interface State {
|
||||
errorInfo: ErrorInfo | null;
|
||||
}
|
||||
|
||||
function isChunkLoadError(error: Error | null) {
|
||||
// 发版后旧入口引用已删除 chunk 时,浏览器会抛动态 import 加载失败。 // Logan.Li
|
||||
const message = error?.message || '';
|
||||
return message.includes('Failed to fetch dynamically imported module') ||
|
||||
message.includes('Importing a module script failed') ||
|
||||
message.includes('ChunkLoadError') ||
|
||||
message.includes('Loading chunk');
|
||||
}
|
||||
|
||||
/**
|
||||
* ErrorBoundary - 全局错误边界组件
|
||||
*
|
||||
@@ -38,6 +47,10 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
}
|
||||
|
||||
handleRetry = () => {
|
||||
if (isChunkLoadError(this.state.error)) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
this.setState({ hasError: false, error: null, errorInfo: null });
|
||||
};
|
||||
|
||||
@@ -60,6 +73,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
if (this.props.fallback) {
|
||||
return this.props.fallback;
|
||||
}
|
||||
const chunkLoadError = isChunkLoadError(this.state.error);
|
||||
|
||||
return (
|
||||
<div className="min-h-[60vh] flex items-center justify-center p-6">
|
||||
@@ -75,7 +89,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
{i18n.t('common.ebPageError')}
|
||||
</h2>
|
||||
<p className="text-sm text-[var(--dg-text-muted)] mt-2">
|
||||
{i18n.t('common.ebDescription')}
|
||||
{chunkLoadError ? i18n.t('common.ebChunkDescription') : i18n.t('common.ebDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -116,7 +130,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
||||
onClick={this.handleRetry}
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-1.5" />
|
||||
{i18n.t('common.reload')}
|
||||
{chunkLoadError ? i18n.t('common.reloadPage') : i18n.t('common.reload')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
|
||||
Reference in new issue
Block a user