Skip to content

Commit 7445f32

Browse files
committed
Use CT instead of CTS in NavigationContext
1 parent 7300751 commit 7445f32

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public LocationChangedEventArgs(string location, bool isNavigationIntercepted) {
559559
public partial class NavigationContext
560560
{
561561
internal NavigationContext() { }
562-
public System.Threading.CancellationTokenSource CancellationTokenSource { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
562+
public System.Threading.CancellationToken CancellationToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
563563
public string Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
564564
}
565565
public partial class Router : Microsoft.AspNetCore.Components.IComponent, Microsoft.AspNetCore.Components.IHandleAfterRender, System.IDisposable

src/Components/Components/src/Routing/NavigationContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace Microsoft.AspNetCore.Components.Routing
1212
{
1313
public class NavigationContext
1414
{
15-
internal NavigationContext(string path, CancellationTokenSource cancellationTokenSource)
15+
internal NavigationContext(string path, CancellationToken cancellationToken)
1616
{
1717
Path = path;
18-
CancellationTokenSource = cancellationTokenSource;
18+
CancellationToken = cancellationToken;
1919
}
2020

2121
public string Path { get; }
2222

23-
public CancellationTokenSource CancellationTokenSource { get; }
23+
public CancellationToken CancellationToken { get; }
2424
}
2525
}

src/Components/Components/src/Routing/Router.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static readonly ReadOnlyDictionary<string, object> _emptyParametersDictionary
3232

3333
private CancellationTokenSource _onNavigateCts;
3434

35-
private HashSet<Assembly> _assemblies = new HashSet<Assembly>();
35+
private readonly HashSet<Assembly> _assemblies = new HashSet<Assembly>();
3636

3737
[Inject] private NavigationManager NavigationManager { get; set; }
3838

@@ -132,7 +132,7 @@ private void RefreshRouteTable()
132132
if (_assemblies.Count != assembliesSet.Count)
133133
{
134134
Routes = RouteTableFactory.Create(assemblies);
135-
_assemblies = assembliesSet;
135+
_assemblies.UnionWith(assembliesSet);
136136
}
137137
// If the new assemblies set is the same length as the previous one,
138138
// we check if they are equal-by-value and refresh the route table if
@@ -143,7 +143,7 @@ private void RefreshRouteTable()
143143
if (!_assemblies.SetEquals(assembliesSet))
144144
{
145145
Routes = RouteTableFactory.Create(assemblies);
146-
_assemblies = assembliesSet;
146+
_assemblies.UnionWith(assembliesSet);
147147
}
148148
}
149149
}
@@ -210,14 +210,14 @@ private async Task RunOnNavigateAsync(string path, bool isNavigationIntercepted)
210210
// Create a new cancellation token source for this instance
211211
_onNavigateCts = new CancellationTokenSource();
212212

213-
var navigateContext = new NavigationContext(path, _onNavigateCts);
213+
var navigateContext = new NavigationContext(path, _onNavigateCts.Token);
214214
var task = OnNavigateAsync(navigateContext);
215215

216216
// Create a cancellation task based on the cancellation token
217217
// associated with the current running task.
218218
var cancellationTaskSource = new TaskCompletionSource();
219-
navigateContext.CancellationTokenSource.Token.Register(() =>
220-
cancellationTaskSource.TrySetCanceled(navigateContext.CancellationTokenSource.Token));
219+
navigateContext.CancellationToken.Register(() =>
220+
cancellationTaskSource.TrySetCanceled(navigateContext.CancellationToken));
221221

222222
// If the user provided a Navigating render fragment, then show it.
223223
if (Navigating != null && task.Status != TaskStatus.RanToCompletion)

src/Components/test/testassets/BasicTestApp/RouterTest/TestRouterWithOnNavigate.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public static async Task TestOnNavCancel(NavigationContext args)
4242
{
43-
await Task.Delay(2000, args.CancellationTokenSource.Token);
43+
await Task.Delay(2000, args.CancellationToken);
4444
Console.WriteLine("I'm not happening...");
4545
}
4646
}

0 commit comments

Comments
 (0)