dotnet / dotnet/aspnetcore

[Blazor] NavigationLock LocationChangingContext CancellationToken cancelled every time navigation location changes

Open
#45,618 6 comments 0 reactions 0 assignees View on GitHub
area-blazor bug feature-blazor-builtin-components Pillar: Technical Debt
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Describe the bug

I am attempting to react to navigation being canceled. I have a NavigationLock component in my razor and am handling its OnBeforeInternalNavigation event. That event has 1 parameter of type LocationChangingContext which has a CancellationToken property. When I register a delegate to be called when that CancellationToken is cancelled, I find that it fires the delegate every time the location is changed - regardless of whether it was actually cancelled or not.

### Expected Behavior

LocationChangingContext's CancellationToken only calls registered delegates when the navigation is cancelled, not on successful navigation.

### Steps To Reproduce

https://github.com/pantoast/NavigationLockCancellationTokenDelegateDemo

### .NET Version

7.0.101

### Anything else?

Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.4.3

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.