C
C#10mo ago
Lamp

.NET 8 - Blazor Server with Per page/component interactivity vs Global

What's the difference? I don't understand the documentation.
10 Replies
lycian
lycian10mo ago
Per page defines how that component/page works. Global is a universal default if a page/component does not specify Basically just rules of specificity
Lamp
LampOP10mo ago
[CascadingParameter] private HttpContext HttpContext { get; set; } = default!; private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/Account") ? null : InteractiveServer; when i created a Blazor Server app with Global, i noticed this in App.razor. Why is it here? <HeadOutlet @rendermode="RenderModeForPage" /> <Routes @rendermode="RenderModeForPage" /> it's used in both of these ig my question from that would be, why would I ever use per-page if i'm using Server or WASM exclusively? Wouldn't per-page only be useful if i'm using Interactive Auto
lycian
lycian10mo ago
if you're using exclusively a single render mode, I would assume you wouldn't want per page/component. I would remove that. In the example above it seems that the page is just cascading the render mode down, since the components may specify a different default mode.
Lamp
LampOP10mo ago
gotcha, that's what i assumed. I forgot to add that this most likely was part of the template I chose bc I selected to add Auth with individual accounts? Is that even needed since its all Interactive Server
lycian
lycian10mo ago
Probably. The templates were recently updated, so they may be less succinct to show off new capabilities I think it depends on HeadOutlet and Routes default render mode. They may have a @rendermode directive in the component that specifies something different I'd have to look though
Lamp
LampOP10mo ago
<HeadOutlet @rendermode="InteractiveServer" /> <Routes @rendermode="InteractiveServer" /> would just directly changing it to this be bad practice?
lycian
lycian10mo ago
Not if that's what you always want Or you could remove that, and specify @rendermode in the two components If that's what you want by default, that's what I would do
Lamp
LampOP10mo ago
well i mean for /Accounts it sets rendermode to null currently, yes? how does that affect those components
lycian
lycian10mo ago
null would mean that the component rendermode would be checked. If it doesn't set one, then the global will be used
Lamp
LampOP10mo ago
so then its completely fine to just remove it as long as all i want is Interactive Server globally
Want results from more Discord servers?
Add your server