8000 [Blazor] Add ability to filter persistent component state callbacks based on persistence reason by Copilot · Pull Request #62394 · dotnet/aspnetcore · GitHub
[go: up one dir, main page]

Skip to content

[Blazor] Add ability to filter persistent component state callbacks based on persistence reason #62394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove Components.Web reference from Components.Tests project
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
  • Loading branch information
Copilot and javiercn committed Jun 18, 2025
commit 4439a8cdd9a9347f5d4eaa965f12a79ea35deae8
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Components" />
<Reference Include="Microsoft.AspNetCore.Components.Web" />
<Reference Include="Microsoft.Extensions.DependencyInjection" />
<Reference Include="Microsoft.Extensions.Diagnostics.Testing" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Text.Json;
using Microsoft.AspNetCore.Components.Infrastructure;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down Expand Up @@ -423,9 +422,9 @@ IEnumerator IEnumerable.GetEnumerator()
public void PersistenceReasons_HaveCorrectDefaults()
{
// Arrange & Act
var prerenderingReason = new PersistOnPrerendering();
var enhancedNavReason = new PersistOnEnhancedNavigation();
var circuitPauseReason = new PersistOnCircuitPause();
var prerenderingReason = new TestPersistOnPrerendering();
var enhancedNavReason = new TestPersistOnEnhancedNavigation();
var circuitPauseReason = new TestPersistOnCircuitPause();

// Assert
Assert.True(prerenderingReason.PersistByDefault);
Expand All @@ -446,7 +445,7 @@ public async Task PersistStateAsync_RespectsReasonFilters()
// Register callback with filter that blocks enhanced navigation
var filters = new List<IPersistenceReasonFilter>
{
new TestPersistenceReasonFilter<PersistOnEnhancedNavigation>(false)
new TestPersistenceReasonFilter<TestPersistOnEnhancedNavigation>(false)
};

manager.State.RegisterOnPersisting(() =>
Expand All @@ -456,7 +455,7 @@ public async Task PersistStateAsync_RespectsReasonFilters()
}, new TestRenderMode(), filters);

// Act - persist with enhanced navigation reason
await manager.PersistStateAsync(store, renderer, new PersistOnEnhancedNavigation());
await manager.PersistStateAsync(store, renderer, new TestPersistOnEnhancedNavigation());

// Assert - callback should not be executed
Assert.False(callbackExecuted);
Expand All @@ -475,7 +474,7 @@ public async Task PersistStateAsync_AllowsWhenFilterMatches()
// Register callback with filter that allows prerendering
var filters = new List<IPersistenceReasonFilter>
{
new TestPersistenceReasonFilter<PersistOnPrerendering>(true)
new TestPersistenceReasonFilter<TestPersistOnPrerendering>(true)
};

manager.State.RegisterOnPersisting(() =>
Expand All @@ -485,7 +484,7 @@ public async Task PersistStateAsync_AllowsWhenFilterMatches()
}, new TestRenderMode(), filters);

// Act - persist with prerendering reason
await manager.PersistStateAsync(store, renderer, new PersistOnPrerendering());
await manager.PersistStateAsync(store, renderer, new TestPersistOnPrerendering());

// Assert - callback should be executed
Assert.True(callbackExecuted);
Expand Down Expand Up @@ -515,6 +514,22 @@ private class TestRenderMode : IComponentRenderMode
{
}

// Test implementations of persistence reasons
private class TestPersistOnPrerendering : IPersistenceReason
{
public bool PersistByDefault => true;
}

private class TestPersistOnEnhancedNavigation : IPersistenceReason
{
public bool PersistByDefault => false;
}

private class TestPersistOnCircuitPause : IPersistenceReason
{
public bool PersistByDefault => true;
}

private class PersistentService : IPersistentServiceRegistration
{
public string Assembly { get; set; }
Expand Down
Loading
0