diff --git a/src/Sentry.AspNetCore.Blazor.WebAssembly/Internal/BlazorWasmOptionsSetup.cs b/src/Sentry.AspNetCore.Blazor.WebAssembly/Internal/BlazorWasmOptionsSetup.cs index ad1f5bbcc9..e284e81836 100644 --- a/src/Sentry.AspNetCore.Blazor.WebAssembly/Internal/BlazorWasmOptionsSetup.cs +++ b/src/Sentry.AspNetCore.Blazor.WebAssembly/Internal/BlazorWasmOptionsSetup.cs @@ -42,6 +42,12 @@ public void Configure(SentryBlazorOptions options) _navigationManager.LocationChanged += (_, args) => { + // Skip duplicate navigations (e.g. when both @onclick+NavigateTo and href fire) + if (string.Equals(args.Location, previousUrl, StringComparison.Ordinal)) + { + return; + } + var from = ToRelativePath(previousUrl); var to = ToRelativePath(args.Location); diff --git a/test/Sentry.AspNetCore.Blazor.WebAssembly.Tests/BlazorWasmOptionsSetupTests.cs b/test/Sentry.AspNetCore.Blazor.WebAssembly.Tests/BlazorWasmOptionsSetupTests.cs index d9960f3087..6a1435c284 100644 --- a/test/Sentry.AspNetCore.Blazor.WebAssembly.Tests/BlazorWasmOptionsSetupTests.cs +++ b/test/Sentry.AspNetCore.Blazor.WebAssembly.Tests/BlazorWasmOptionsSetupTests.cs @@ -147,4 +147,18 @@ public void Navigation_FromInitialPath_TracksCorrectFrom() crumb.Data.Should().ContainKey("from").WhoseValue.Should().Be("/login"); crumb.Data.Should().ContainKey("to").WhoseValue.Should().Be("/home"); } + + [Fact] + public void DuplicateNavigation_SkipsBreadcrumb() + { + // Arrange + _sut.Configure(new SentryBlazorOptions()); + + // Act — navigate to /page1, then fire LocationChanged again for the same URL + _navigationManager.NavigateTo("/page1"); + _navigationManager.NavigateTo("/page1"); + + // Assert — only one breadcrumb should be created + _scope.Breadcrumbs.Should().ContainSingle(); + } }