Skip to content
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Components.HotReload;
using Microsoft.AspNetCore.Components.Routing;

namespace Microsoft.AspNetCore.Components.Endpoints.DependencyInjection;

internal sealed class EndpointRoutingStateProvider : IRoutingStateProvider
{
public RouteData? RouteData { get; internal set; }
private static volatile bool _cacheInvalidated;
private RouteData? _routeData;
Copy link
Member

@oroztocil oroztocil Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot _routeData is a non-static field yet you treat it as a static cache. This does not seem correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Rework the solution. Investigate how the EndpointRoutingStateProvider is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right about the flawed design. I've reworked the solution to fix the root cause in EndpointHtmlRenderer instead of using a broken static flag approach.

The new solution validates that the endpoint's route template matches the component's current route attributes before setting the template. When they don't match (hot reload scenario), the template stays null, forcing the router to use normal routing with updated metadata. Commit: caad798


static EndpointRoutingStateProvider()
{
if (HotReloadManager.Default.MetadataUpdateSupported)
{
HotReloadManager.Default.OnDeltaApplied += InvalidateCache;
}
}

public RouteData? RouteData
{
get => _cacheInvalidated ? null : _routeData;
internal set => _routeData = value;
}

private static void InvalidateCache()
{
// Invalidate cached route data during hot reload to prevent stale route data
// from being used when component route templates change
_cacheInvalidated = true;
}
}
Loading