support-prerendering skill
✓ VerifiedFix duplicate data loads, UI flicker, and state persistence issues when using prerendering in Blazor interactive components.
- GitHub stars
- 5,942
- Files
- 1
- Last commit
- Nov 11, 2026
- License
- MIT
- Allowed tools
- —
What does the support-prerendering skill do?
support-prerendering is an agent skill. Fix duplicate data loads, UI flicker, and state persistence issues when using prerendering in Blazor interactive components.
Summary generated from the skill's SKILL.md.
About the support-prerendering skill
Developers building Blazor applications use this skill to resolve common issues caused by the transition from static HTML prerendering to interactive runtimes. It addresses specific technical hurdles such as duplicate data fetching in OnInitializedAsync, UI flickering during the handoff, and null reference exceptions when components expect browser-only APIs. The skill provides methods to manage state persistence, ensuring that data loaded during the initial server render is available once the interactive session begins.
An agent should load this skill when a developer needs to implement the [PersistentState] attribute or the PersistentComponentState service to synchronize data. It is also used to disable prerendering for specific components or to exclude certain pages from interactive routing using the [ExcludeFromInteractiveRouting] attribute. By utilizing tools like RendererInfo.IsInteractive, developers can guard code execution to prevent errors during the static phase. This skill is intended for fixing existing prerendering bugs rather than initial project setup or general component authoring.
What an agent can do with it
- 1Prevent duplicate API callsApply state persistence to ensure data loaded during prerendering is not re-fetched when the interactive runtime attaches.
- 2Disable prerendering for specific componentsTurn off prerendering for components that require immediate access to browser APIs.
- 3Access HttpContext on specific pagesForce a full page reload for pages that require access to cookies or request headers.
- 4Guard interactive-only codeUse runtime checks to ensure certain logic only executes after the interactive runtime has attached.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the support-prerendering skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the support-prerendering skill in Plugin
/plugin marketplace add dotnet/skills /plugin install dotnet-blazor@dotnet-agent-skills
Install the support-prerendering skill in Claude Code
~/.claude/skills/support-prerendering/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-blazor/skills/support-prerendering ~/.claude/skills/support-prerenderingInstall the support-prerendering skill in Claude Code (project)
.claude/skills/support-prerendering/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-blazor/skills/support-prerendering .claude/skills/support-prerenderingInstall the support-prerendering skill in Codex
~/.agents/skills/support-prerendering/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-blazor/skills/support-prerendering ~/.agents/skills/support-prerenderingInstall the support-prerendering skill in Gemini CLI
~/.gemini/skills/support-prerendering/SKILL.md
$ npx degit dotnet/skills/plugins/dotnet-blazor/skills/support-prerendering ~/.gemini/skills/support-prerenderingInstall the support-prerendering skill in Claude.ai
npx degit dotnet/skills/plugins/dotnet-blazor/skills/support-prerendering support-prerendering && zip -r support-prerendering.zip support-prerendering # claude.ai → Customize → Skills → + → Create skill → Upload a skill → support-prerendering.zip
Automated checks
Ran Nov 14, 2026Full report →Passed our automated checks. That is not a security audit: read the scripts before you let an agent run them. How checks work
- Source repository linked and reachabledotnet/skills/plugins/dotnet-blazor/skills/support-prerendering is public and reachablegithub.com/dotnet/skills/tree/HEAD/plugins/dotnet-blazor/ski ↗Pass
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit 2026-11-11github.com/dotnet/skills/commits ↗Pass
- No download-and-run or credential theft in scriptsNo scripts in the skill folderPass
- No hidden instructions in SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/dotnet/skills/blob/HEAD/plugins/dotnet-blazor/ski ↗Pass
- Pre-approved tools are scopedNo pre-approved tools; the agent asks before using onegithub.com/dotnet/skills/blob/HEAD/plugins/dotnet-blazor/ski ↗Pass
SKILL.md
View on GitHubSupport 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:
OnInitializedAsyncruns twice — once during prerender (static), once when the interactive runtime attaches.OnAfterRenderAsyncis 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 the Project's AGENTS.md
Check the project's AGENTS.md for the Interactivity Mode and Interactivity Scope:
| Mode | Prerendering applies? |
|---|---|
| None (Static SSR) | No — there's no interactive handoff |
| Server | Yes |
| WebAssembly | Yes |
| Auto | Yes |
If the mode is None, this skill doesn't apply.
Persist State Across Prerender → Interactive
The most common prerendering problem: data loaded in OnInitializedAsync during prerender is thrown away and re-fetched when the interactive runtime attaches. This causes flicker and duplicate API/DB calls.
Recommended: [PersistentState] attribute
Annotate properties to automatically serialize during prerender and restore on interactive activation:
@page "/forecasts"
@rendermode InteractiveServer
<h1>Weather</h1>
@if (Forecasts is null)
{
<p>Loading...</p>
}
else
{
@foreach (var f in Forecasts)
{
<p>@f.Date: @f.TemperatureC°C</p>
}
}
@code {
[PersistentState]
public WeatherForecast[]? Forecasts { get; set; }
protected override async Task OnInitializedAsync()
{
Forecasts ??= await ForecastService.GetForecastsAsync();
}
}
The ??= pattern is critical — it means "only fetch if the property wasn't already restored from prerender state."
Multiple instances of the same component
When the same component type appears multiple times, use @key to disambiguate state:
@foreach (var item in items)
{
<ItemCard @key="item.Id" />
}
Advanced: PersistentComponentState service
For complex scenarios (dynamic keys, custom serialization), use the imperative API:
@inject PersistentComponentState ApplicationState
@code {
private List<Order>? orders;
protected override async Task OnInitializedAsync()
{
ApplicationState.RegisterOnPersisting(PersistOrders);
if (!ApplicationState.TryTakeFromJson<List<Order>>("orders", out var restored))
{
orders = await OrderService.GetOrdersAsync();
}
else
{
orders = restored;
}
}
private Task PersistOrders()
{
ApplicationState.PersistAsJson("orders", orders);
return Task.CompletedTask;
}
}
Disable Prerendering
Disable prerendering when a component depends on browser APIs immediately or when the prerender+interactive double render causes problems you can't solve with [PersistentState].
On a component definition
@rendermode @(new InteractiveServerRenderMode(prerender: false))
Replace InteractiveServerRenderMode with InteractiveWebAssemblyRenderMode or InteractiveAutoRenderMode as needed.
On a component instance
<MyChart @rendermode="new InteractiveServerRenderMode(prerender: false)" />
On the entire app
In App.razor:
<HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" />
<Routes @rendermode="new InteractiveServerRenderMode(prerender: false)" />
Note: A parent's prerendering setting overrides children. If <Routes> disables prerendering, individual pages cannot re-enable it.
Exclude Pages from Interactive Routing
In a globally interactive app, some pages may need HttpContext (cookies, request headers, response status codes). These pages must render via static SSR, not inside the interactive runtime.
Use [ExcludeFromInteractiveRouting]:
@page "/privacy"
@attribute [ExcludeFromInteractiveRouting]
<h1>Privacy Policy</h1>
This forces a full page reload when navigating to this page, exiting interactive routing. The page renders as static SSR with full HttpContext access.
In App.razor, conditionally apply the render mode:
<!DOCTYPE html>
<html>
<head>
<HeadOutlet @rendermode="RenderModeForPage" />
</head>
<body>
<Routes @rendermode="RenderModeForPage" />
<script src="_framework/blazor.web.js"></script>
</body>
</html>
@code {
[CascadingParameter]
public HttpContext HttpContext { get; set; } = default!;
private IComponentRenderMode? RenderModeForPage =>
HttpContext.AcceptsInteractiveRouting() ? InteractiveServer : null;
}
Replace InteractiveServer with the app's configured render mode.
Detect Prerender vs Interactive at Runtime
Use RendererInfo to guard code that should only run interactively:
protected override async Task OnInitializedAsync()
{
if (RendererInfo.IsInteractive)
{
// Only runs during the interactive render, not during prerender
await StartSignalRConnection();
}
}
RendererInfo properties:
IsInteractive—falseduring prerender,trueafter interactive runtime attachesName—"Static"during prerender,"Server"or"WebAssembly"when interactive
Client Services Fail During Prerender
Components in the .Client project prerender on the server. Services registered only in the client Program.cs (e.g., IWebAssemblyHostEnvironment) won't be available during prerender.
Fix by one of:
- Register a matching service on the server — both
Program.csfiles provide the service - Make the service optional — use constructor injection with a nullable default:
public MyComponent(IMyService? svc = null) - Create a service abstraction — interface in
.Client, implementations in both projects - Disable prerendering for that component
Don'ts
- Don't call JS interop in
OnInitializedAsync— JS isn't available during prerender. UseOnAfterRenderAsync(firstRender). - Don't assume
OnInitializedAsyncruns once — it runs twice with prerendering. Always use[PersistentState]or??=guards. - Don't use
HttpContextin interactive components — it's only available during the static prerender, not during the interactive lifetime. Use[ExcludeFromInteractiveRouting]for pages that need it. - Don't disable prerendering as a first resort — it hurts perceived load time and SEO. Use
[PersistentState]to preserve state instead.
Files in this skill
1support-prerendering skill questions
How do I install the support-prerendering skill in Claude Code?
Run npx degit dotnet/skills/plugins/dotnet-blazor/skills/support-prerendering ~/.claude/skills/support-prerendering. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the support-prerendering skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
How do I prevent duplicate data fetching during prerendering?
Use the [PersistentState] attribute on properties or the PersistentComponentState service to serialize data during prerender and restore it when the interactive runtime attaches.
Can I disable prerendering for a specific component?
Yes, you can disable it by passing a render mode with the prerender parameter set to false, such as @rendermode @(new InteractiveServerRenderMode(prerender: false)).
Why is my JS interop failing during OnInitializedAsync?
JavaScript is not available during the prerender phase. You should move JS interop calls to the OnAfterRenderAsync method.