Files
jiang13-forum/frontend/src/utils/softRefresh.ts
freefire 44eed97fe0 feat: 首页 Go SSR 与 React hydrate 同构,消壳层与帖行闪动
补齐侧栏/右栏图标与徽章、鉴权种子、StaticFeedList,并修正嵌套 a 与标题徽章对齐。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-01 07:07:38 +08:00

30 lines
1.1 KiB
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.
import { prefetchLayoutShell, prefetchRoute } from './prefetchRoute';
import { doneTransition, startTransition } from './spaTransition';
/** 软刷新齐套后的单一提交:各组件同一拍从 cache/快照同步 UI禁止分批闪烁 */
export const PAGE_SOFT_REFRESH_COMMIT_EVENT = 'page-soft-refresh-commit';
export type SoftRefreshOpts = {
/** 是否显示顶栏进度条Logo 刷新开;下拉关) */
progress?: boolean;
};
/**
* 软刷新当前页:预热齐套后派发一次 commit。
* `progress: true` 时走顶栏进度条。
*/
export async function softRefreshCurrentPage(to?: string, opts?: SoftRefreshOpts): Promise<void> {
const path = to ?? `${window.location.pathname}${window.location.search}`;
const id = opts?.progress ? startTransition() : undefined;
try {
await Promise.all([
prefetchRoute(path, { force: true }),
prefetchLayoutShell({ force: true }),
]);
} catch {
// 仍派发 commit让界面有机会用已有缓存自愈
}
window.dispatchEvent(new Event(PAGE_SOFT_REFRESH_COMMIT_EVENT));
if (id != null) doneTransition(id);
}