Skip to content

Commit 6e8d759

Browse files
bruno-garciaclaude
andauthored
fix(blazor): Skip duplicate navigation breadcrumbs in WASM (#4922)
* fix(blazor): Skip duplicate navigation breadcrumbs in WASM When Blazor apps use both @OnClick+NavigateTo and href on links, LocationChanged fires twice for the same URL. Skip creating a breadcrumb when the new location matches the previous one. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add changelog entry for duplicate breadcrumb fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Remove changelog entry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 14ec84f commit 6e8d759

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Sentry.AspNetCore.Blazor.WebAssembly/Internal/BlazorWasmOptionsSetup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public void Configure(SentryBlazorOptions options)
4242

4343
_navigationManager.LocationChanged += (_, args) =>
4444
{
45+
// Skip duplicate navigations (e.g. when both @onclick+NavigateTo and href fire)
46+
if (string.Equals(args.Location, previousUrl, StringComparison.Ordinal))
47+
{
48+
return;
49+
}
50+
4551
var from = ToRelativePath(previousUrl);
4652
var to = ToRelativePath(args.Location);
4753

test/Sentry.AspNetCore.Blazor.WebAssembly.Tests/BlazorWasmOptionsSetupTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,18 @@ public void Navigation_FromInitialPath_TracksCorrectFrom()
147147
crumb.Data.Should().ContainKey("from").WhoseValue.Should().Be("/login");
148148
crumb.Data.Should().ContainKey("to").WhoseValue.Should().Be("/home");
149149
}
150+
151+
[Fact]
152+
public void DuplicateNavigation_SkipsBreadcrumb()
153+
{
154+
// Arrange
155+
_sut.Configure(new SentryBlazorOptions());
156+
157+
// Act — navigate to /page1, then fire LocationChanged again for the same URL
158+
_navigationManager.NavigateTo("/page1");
159+
_navigationManager.NavigateTo("/page1");
160+
161+
// Assert — only one breadcrumb should be created
162+
_scope.Breadcrumbs.Should().ContainSingle();
163+
}
150164
}

0 commit comments

Comments
 (0)