Move session ID logic to OnAfterRenderAsync
The session ID generation and redirection logic was moved from OnInitialized to OnAfterRenderAsync to address issues with NavigationException during SSR prerendering. OnInitialized is now intentionally left empty, and the new OnAfterRenderAsync method ensures the session ID is appended to the URL only after the first interactive render, when SignalR is connected and NavigateTo is safe.
This commit is contained in:
@@ -348,8 +348,17 @@
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
// If no session id exists yet, generate one and redirect so it sticks in the URL.
|
||||
// This is the ONLY navigation that uses forceLoad; afterwards the page lives forever.
|
||||
// Intentionally empty.
|
||||
// esid redirect is done in OnAfterRenderAsync to avoid NavigationException
|
||||
// during SSR prerendering, where NavigateTo throws by design.
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender) return;
|
||||
|
||||
// Generate a session id on first interactive render and push it into the URL.
|
||||
// At this point SignalR is connected and NavigateTo is safe.
|
||||
if (string.IsNullOrWhiteSpace(Esid))
|
||||
{
|
||||
var sid = Guid.NewGuid().ToString("N");
|
||||
|
||||
Reference in New Issue
Block a user