修复发帖长文布局与手机下拉刷新,发版后自动重载失效 chunk,并整理站务文案。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-03 18:18:35 +08:00
parent 61b47363e9
commit 2c06eaccb2
20 changed files with 811 additions and 360 deletions

View File

@@ -0,0 +1,25 @@
import { lazy, type ComponentType, type LazyExoticComponent } from 'react';
import { isChunkLoadError, reloadForStaleChunk } from './chunkLoad';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyComponent = ComponentType<any>;
/**
* 带发版容错的 React.lazy动态 import 失败时自动整页刷新一次。
* (部署后 hashed chunk 更名,旧标签页点到懒加载路由时常见)
*/
export function lazyWithRetry<T extends AnyComponent>(
factory: () => Promise<{ default: T }>,
): LazyExoticComponent<T> {
return lazy(async () => {
try {
return await factory();
} catch (err) {
if (isChunkLoadError(err) && reloadForStaleChunk()) {
// 刷新进行中,挂起 Promise避免再抛到错误页闪一下
return new Promise<{ default: T }>(() => {});
}
throw err;
}
});
}