修复发帖长文布局与手机下拉刷新,发版后自动重载失效 chunk,并整理站务文案。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import { Component, ErrorInfo, ReactNode } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { isChunkLoadError, reloadForStaleChunk } from '../utils/chunkLoad';
|
||||
|
||||
interface Props { children: ReactNode }
|
||||
interface State { error: Error | null }
|
||||
interface State { error: Error | null; reloading: boolean }
|
||||
|
||||
/** 捕获渲染异常,避免整页白屏 */
|
||||
/** 捕获渲染异常;发版 chunk 失效时自动刷新 */
|
||||
export default class ErrorBoundary extends Component<Props, State> {
|
||||
state: State = { error: null };
|
||||
state: State = { error: null, reloading: false };
|
||||
|
||||
static getDerivedStateFromError(error: Error) {
|
||||
return { error };
|
||||
if (isChunkLoadError(error) && reloadForStaleChunk()) {
|
||||
return { error, reloading: true };
|
||||
}
|
||||
return { error, reloading: false };
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, info: ErrorInfo) {
|
||||
@@ -17,6 +21,18 @@ export default class ErrorBoundary extends Component<Props, State> {
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.reloading) {
|
||||
return (
|
||||
<div className="error-page-shell">
|
||||
<div className="error-page">
|
||||
<div className="error-page__code" aria-hidden>…</div>
|
||||
<h1 className="error-page__title">正在更新页面</h1>
|
||||
<p className="error-page__desc">检测到程序已更新,正在自动刷新以加载最新版本…</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (this.state.error) {
|
||||
return (
|
||||
<div className="error-page-shell">
|
||||
|
||||
Reference in New Issue
Block a user