Repository navigation
Description
Right now, after prerendering we replace the entire contents of the prerendered component with a fresh DOM copy created from scratch. This has several bad side-effects like:
- Videos are stopped and restarted
- Animations can be retriggered
- The page can flicker if CSS is injected as part of the head contents.
- LCP score suffers because (even though there is no significant visual change in most cases) the tools detect the interactive DOM insertion as the LCP element.
Instead of replacing the contents of the DOM wholesale, we can do a best effort to reconciliate the DOM with the new rendered DOM when we are trying to apply the render batch.
In an ideal scenario, a developer should be able to produce exact prerenders, meaning that the render after prerendering is identical to the prerendered one.
In that case, the renderer would only need to "attach" event handlers to the appropriate nodes, leaving everything else the same.
The renderer does not have to be perfect and handle all possible scenarios, it can impose strict limitations and "bail out" if it can't figure out how to reconcile a given DOM subtree by replacing that node wholesale.
For example, the render can impose a strict order, suggesting that DOM children nodes in a given subtree must appear in the same order as the prerendered node (in other words, the renderer won't search for them, but iterate in order). A similar restriction might be imposed on attributes (which is not rare, since attributes are emitted in compilation order, except for splatting). Things like @key could be leveraged during prerendering too to offer a bit more flexibility in the ordering.
In general, this will likely result in a much higher node reuse and will give the developers the chance to always get this right.
Activity
3hxx commentedon Nov 21, 2022
Yes yes yes. This is long overdue my guys 🙏😍😇
67 remaining items
NearNihil commentedon Nov 27, 2025
I've not really done much with animations before, but now I am and it's really noticeable. Is it so much to ask to fix this? It's been years and it's causing headaches all round.
ice6 commentedon Jan 17, 2026
this issue is good showcase about github copilot's inability. :)
Ali1Jamal commentedon Mar 9, 2026
also moving from static page to interactive page or vice versa, when the theme of the browser or os is different from the website or app theme ( i add pwa ability to my blazor web app ), causes this flashing because of replacing Dom and reload all assets.
WhatsApp.Video.2026-03-09.at.17.35.47.mp4
BrendanRidenour commentedon Apr 11, 2026
Adding diagnostic evidence from .NET 10 with InteractiveWebAssembly that may be useful for anyone investigating this.
We confirmed that static HTML elements in App.razor (outside any component boundary) are destroyed and recreated during the SSR-to-WASM handoff. Specifically, a
<link rel="stylesheet">that is plain markup in<head>, not rendered by any Blazor component.How we confirmed it: We set all three DOM breakpoints (subtree modified, node removed, attribute modified) on the
<link>element in Edge DevTools before triggering the navigation. After the WASM handoff completed, the breakpoints were gone without ever firing. This indicates the node was replaced as part of a wholesale parent replacement rather than individual node operations, which bypasses per-node mutation observers.This means the wholesale DOM replacement described in the original issue extends beyond Blazor-managed component subtrees to static HTML that Blazor does not own.
Workarounds evaluated:
data-permanent: only applies to enhanced navigation, not render mode transitions.<link rel="preload">: resource stays cached, but the FOUC still occurs because the DOM node itself is destroyed and recreated.<style>fallback: blocked by Content Security Policy in our environment.<head>: no effect.We have no remaining workaround available to us.
cbordeman commentedon Apr 11, 2026
This is why everyone says Blazor is garbage now. It's nearly unusable.
pr8x commentedon May 25, 2026
.NET 11 is coming up and this is nowhere to be found on the roadmap.
ilonatommy commentedon Nov 3, 2026
Let me summarize the pain points listed in this issue:
Replacing the DOM was a deliberate design choice taken at the time when prerendering to interactive transition didn't exist. Preserving the existing DOM when the prerendered and first interactive output match would solve 2-4. In the case of mismatch, we would fall back to today's whole-root replacement. That should make the work relatively small but would be already a great improvement for majority of the scenarios.
Here is the draft PR with the proposal: #70270
ilonatommy commentedon Nov 4, 2026
@Ali1Jamal or anyone who experienced the same problem. I cannot reproduce your report that I listed as point 3. A smallest reproduction app would be very helpful to make sure the issue is indeed related and not e.g. a variation of #64566 or a navigation problem.
Ali1Jamal commentedon Nov 4, 2026
@ilonatommy nav like the video above from home to shopping card or vice versa make sure to make the website theme different from os theme to see clearly, in the ios Safari its very clear you can test the website from this link production demo
ilonatommy commentedon Nov 4, 2026
Thank you. Maybe the phrasing "smallest reproduction app" was unclear. I meant code of the application and, in case your app's code cannot be public, reproducing the same issue on a template app and providing us with a link to the repo with that template app. If you prefer not to share it here and you are not able to create the smallest repro app but you still want us to take a look, you can email the relevant private code to itomkowicz@microsoft.com.
Otherwise, it will be hard to reason about the issue without the code.
ilonatommy commentedon Nov 4, 2026
I made measurements of LCP and there seems to be no improvement when looking at a median and average values of 100 loads of an image, regardless if we replace the DOM or not.
It's mostly due to the fact that LCP records the time when the largest visible content finished painting and doesn't care what happens to it later (if hydration will replace it with a new node or not). If the item doesn't get fully loaded during static rendering, loading in interactivity reuses the existing in-flight request rather than loading from 0.
It doesn't make this issue less important, I am just flagging that my initial claim that the fix will improve LCP when collecting the list of affected scenarios was not correct.
jirisykora83 commentedon Nov 4, 2026
One edge case worth considering regarding LCP is when the primary candidate (e.g. hero image or dynamic heading) cannot be prerendered at all—such as when it depends on client-side state (
localStorage, auth tokens, geolocation). In those cases, the server only renders a placeholder, and the actual LCP element paints only after hydration kicks in.That said, this is likely only noticeable on pages with a larger/heavier DOM. In an isolated benchmark, tearing down and recreating nodes takes negligible time. On a complex DOM tree, however, the main-thread blocking time from a full replacement (style recalculation, layout thrashing, GC pressure) could meaningfully delay hydration and push back that final paint.