Skip to content

[Blazor] Supplying a null parameter value to an interactive root component causes a NullReferenceException on enhanced navigation #52434

Closed
@MackinnonBuck

Description

@MackinnonBuck

Summary

If a null value is supplied as a parameter to a render mode boundary component during static SSR, and the SSR'd component is matched up with an existing interactive root component, a NullReferenceException gets thrown by the framework.

Steps to reproduce

  1. Create a Blazor Web App with Server interactivity
  2. Define a component (MyComponent.razor):
    @inject NavigationManager NavigationManager
    
    <button @onclick="@(() => NavigationManager.Refresh())">Refresh</button>
    
    @code {
        [Parameter]
        public string? Value { get; set; }
    }
  3. Render the component from Home.razor and supply the value null for the Value parameter:
    <MyComponent Value="@null" @rendermode="InteractiveServer" />
  4. Run the app
  5. Click the button labeled "Refresh"
  6. Observe that an exception gets thrown and the circuit gets terminated

Relevant output

Stack trace:

Microsoft.AspNetCore.Components.Server.dll!Microsoft.AspNetCore.Components.WebRootComponentParameters.DefinitelyEquals(Microsoft.AspNetCore.Components.WebRootComponentParameters other) Line 43
	at Microsoft.AspNetCore.Components\WebRootComponentParameters.cs(43)
Microsoft.AspNetCore.Components.Server.dll!Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer.WebRootComponentManager.WebRootComponent.UpdateAsync(Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer renderer, System.Type newComponentType, Microsoft.AspNetCore.Components.ComponentMarkerKey? newKey, Microsoft.AspNetCore.Components.WebRootComponentParameters newParameters) Line 245
	at Microsoft.AspNetCore.Components.Server.Circuits\RemoteRenderer.cs(245)
.
.
.

Proposed fix

Update WebRootComponentParameters to account for the possibility that the parameter values are null rather than being valid JsonElements.

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions