dotnet/skills✦ 精选0°

support-prerendering

仓库创建 2026年2月4日最近提交 14 小时前SkillHot 收录 20 天前
▸ 精选理由

解决 prerender 到交互切换常见坑,提升首屏稳定性与用户体验。

这个 Skill 做什么

处理 Blazor 预渲染导致的数据重复、闪烁与空引用等问题。

解决 Blazor 预渲染(prerendering)带来的重复数据加载、界面闪烁、空引用和状态丢失等问题,让组件能平滑从服务端静态渲染切换到浏览器交互态。适合在生命周期被调用两次或页面交互异常时排查修复。侧重点是处理 prerender 到 interactive 的交接和状态保持,而不是选渲染模式或常规组件开发。

▸ 展开 SKILL.md 英文原文

Make interactive Blazor components work correctly with prerendering. USE FOR fixing duplicate data loads, UI flicker during prerender-to-interactive handoff, null references during prerender, persisting state across prerender, disabling prerendering, excluding pages from interactive routing, or detecting whether a component is currently prerendering. DO NOT USE for choosing which render mode to use (see create-blazor-project) or general component authoring (see author-component).

开发编程预渲染生命周期状态保持通用
4.8k
Stars
351
Forks
40
仓库内 Skill
+610
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/dotnet/skills/main/plugins/dotnet-blazor/skills/support-prerendering/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/dotnet/skills/main/plugins/dotnet-blazor/skills/support-prerendering/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# Support Prerendering

## How Prerendering Works

Prerendering is **on by default** for all interactive render modes. The server renders the component as static HTML and ships it to the browser immediately. Then the interactive runtime (Server/WebAssembly) loads and re-renders the component with full interactivity.

This means:
- `OnInitializedAsync` runs **twice** — once during prerender (static), once when the interactive runtime attaches.
- `OnAfterRenderAsync` is **NOT** called during prerender — only after the interactive render.
- Internal navigation between interactive pages (interactive routing) **skips prerendering** — prerendering only happens on full page loads.

## Step 1 — Read
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有