8000 Move persistence reason implementations to Components.Web and update … · dotnet/aspnetcore@f938ea4 · GitHub
[go: up one dir, main page]

Skip to content

Commit f938ea4

Browse files
Copilotjaviercn
andcommitted
Move persistence reason implementations to Components.Web and update RazorComponentEndpointInvoker to detect enhanced navigation
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
1 parent 0fddad7 commit f938ea4

9 files changed

+40
-19
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Components;
5+
6+
/// <summary>
7+
/// Default persistence reason used when no specific reason is provided.
8+
/// </summary>
9+
internal sealed class DefaultPersistenceReason : IPersistenceReason
10+
{
11+
public static readonly DefaultPersistenceReason Instance = new();
12+
13+
private DefaultPersistenceReason() { }
14+
15+
/// <inheritdoc />
16+
public bool PersistByDefault => true;
17+
}

src/Components/Components/src/PersistentState/ComponentStatePersistenceManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task RestoreStateAsync(IPersistentComponentStateStore store)
6868
/// <param name="renderer">The <see cref="Renderer"/> that components are being rendered.</param>
6969
/// <returns>A <see cref="Task"/> that will complete when the state has been restored.</returns>
7070
public Task PersistStateAsync(IPersistentComponentStateStore store, Renderer renderer)
71-
=> PersistStateAsync(store, renderer, new PersistOnPrerendering());
71+
=> PersistStateAsync(store, renderer, DefaultPersistenceReason.Instance);
7272

7373
/// <summary>
7474
/// Persists the component application state into the given <see cref="IPersistentComponentStateStore"/>.
@@ -187,7 +187,7 @@ private void InferRenderModes(Renderer renderer)
187187
}
188188

189189
internal Task<bool> TryPauseAsync(IPersistentComponentStateStore store)
190-
=> TryPauseAsync(store, new PersistOnPrerendering());
190+
=> TryPauseAsync(store, DefaultPersistenceReason.Instance);
191191

192192
internal Task<bool> TryPauseAsync(IPersistentComponentStateStore store, IPersistenceReason persistenceReason)
193193
{

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,18 @@ Microsoft.AspNetCore.Components.Routing.NotFoundEventArgs.NotFoundEventArgs(stri
1010
Microsoft.AspNetCore.Components.Routing.NotFoundEventArgs.Path.get -> string!
1111
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.ComponentStatePersistenceManager(Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager!>! logger, System.IServiceProvider! serviceProvider) -> void
1212
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.SetPlatformRenderMode(Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
13-
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.PersistStateAsync(Microsoft.AspNetCore.Components.IPersistentComponentStateStore! store, Microsoft.AspNetCore.Components.RenderTree.Renderer! renderer, Microsoft.AspNetCore.Components.IPersistenceReason! persistenceReason) -> System.Threading.Tasks.Task
14-
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.PersistStateAsync(Microsoft.AspNetCore.Components.IPersistentComponentStateStore! store, Microsoft.AspNetCore.Components.RenderTree.Renderer! renderer, Microsoft.AspNetCore.Components.IPersistenceReason! persistenceReason) -> System.Threading.Tasks.Task
13+
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.PersistStateAsync(Microsoft.AspNetCore.Components.IPersistentComponentStateStore! store, Microsoft.AspNetCore.Components.RenderTree.Renderer! renderer, Microsoft.AspNetCore.Components.IPersistenceReason! persistenceReason) -> System.Threading.Tasks.Task!
1514
Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions
1615
Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttribute
1716
Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttribute.SupplyParameterFromPersistentComponentStateAttribute() -> void
1817
Microsoft.AspNetCore.Components.IPersistenceReason
1918
Microsoft.AspNetCore.Components.IPersistenceReason.PersistByDefault.get -> bool
2019
Microsoft.AspNetCore.Components.IPersistenceReasonFilter
2120
Microsoft.AspNetCore.Components.IPersistenceReasonFilter.ShouldPersist(Microsoft.AspNetCore.Components.IPersistenceReason! reason) -> bool?
22-
Microsoft.AspNetCore.Components.PersistOnCircuitPause
23-
Microsoft.AspNetCore.Components.PersistOnCircuitPause.PersistByDefault.get -> bool
24-
Microsoft.AspNetCore.Components.PersistOnCircuitPause.PersistOnCircuitPause() -> void
25-
Microsoft.AspNetCore.Components.PersistOnEnhancedNavigation
26-
Microsoft.AspNetCore.Components.PersistOnEnhancedNavigation.PersistByDefault.get -> bool
27-
Microsoft.AspNetCore.Components.PersistOnEnhancedNavigation.PersistOnEnhancedNavigation() -> void
28-
Microsoft.AspNetCore.Components.PersistOnPrerendering
29-
Microsoft.AspNetCore.Components.PersistOnPrerendering.PersistByDefault.get -> bool
30-
Microsoft.AspNetCore.Components.PersistOnPrerendering.PersistOnPrerendering() -> void
3121
Microsoft.AspNetCore.Components.PersistReasonFilter<TReason>
3222
Microsoft.AspNetCore.Components.PersistReasonFilter<TReason>.PersistReasonFilter(bool persist) -> void
3323
Microsoft.AspNetCore.Components.PersistReasonFilter<TReason>.ShouldPersist(Microsoft.AspNetCore.Components.IPersistenceReason! reason) -> bool?
3424
Microsoft.AspNetCore.Components.PersistentComponentState.RegisterOnPersisting(System.Func<System.Threading.Tasks.Task!>! callback, Microsoft.AspNetCore.Components.IComponentRenderMode? renderMode, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Components.IPersistenceReasonFilter!>? reasonFilters) -> Microsoft.AspNetCore.Components.PersistingComponentStateSubscription
35-
Microsoft.AspNetCore.Components.PersistentComponentState.RegisterOnPersisting(System.Func<System.Threading.Tasks.Task!>! callback, Microsoft.AspNetCore.Components.IComponentRenderMode? renderMode, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Components.IPersistenceReasonFilter!>? reasonFilters) -> Microsoft.AspNetCore.Components.PersistingComponentStateSubscription
3625
Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions
3726
static Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<TService>(Microsoft.Extensions.DependencyInjection.IServiceCollection! services, Microsoft.AspNetCore.Components.IComponentRenderMode! componentRenderMode) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
3827
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsMetrics(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!

src/Components/Components/test/Microsoft.AspNetCore.Components.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<ItemGroup>
99
<Reference Include="Microsoft.AspNetCore.Components" />
10+
<Reference Include="Microsoft.AspNetCore.Components.Web" />
1011
<Reference Include="Microsoft.Extensions.DependencyInjection" />
1112
<Reference Include="Microsoft.Extensions.Diagnostics.Testing" />
1213
</ItemGroup>

src/Components/Components/test/PersistentState/ComponentStatePersistenceManagerTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.Json;
77
using Microsoft.AspNetCore.Components.Infrastructure;
88
using Microsoft.AspNetCore.Components.RenderTree;
9+
using Microsoft.AspNetCore.Components.Web;
910
using Microsoft.Extensions.DependencyInjection;
1011
using Microsoft.Extensions.Logging;
1112
using Microsoft.Extensions.Logging.Abstractions;

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.PrerenderingState.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public async ValueTask<IHtmlContent> PrerenderPersistedStateAsync(HttpContext ht
5050

5151
if (store != null)
5252
{
53-
await manager.PersistStateAsync(store, this, new PersistOnPrerendering());
53+
IPersistenceReason persistenceReason = IsProgressivelyEnhancedNavigation(httpContext.Request)
54+
? new PersistOnEnhancedNavigation()
55+
: new PersistOnPrerendering();
56+
await manager.PersistStateAsync(store, this, persistenceReason);
5457
return store switch
5558
{
5659
ProtectedPrerenderComponentApplicationStore protectedStore => new ComponentStateHtmlContent(protectedStore, null),
@@ -80,7 +83,10 @@ public async ValueTask<IHtmlContent> PrerenderPersistedStateAsync(HttpContext ht
8083
var webAssembly = new CopyOnlyStore<InteractiveWebAssemblyRenderMode>();
8184
store = new CompositeStore(server, auto, webAssembly);
8285

83-
await manager.PersistStateAsync(store, this, new PersistOnPrerendering());
86+
IPersistenceReason persistenceReason = IsProgressivelyEnhancedNavigation(httpContext.Request)
87+
? new PersistOnEnhancedNavigation()
88+
: new PersistOnPrerendering();
89+
await manager.PersistStateAsync(store, this, persistenceReason);
8490

8591
foreach (var kvp in auto.Saved)
8692
{

src/Components/Web/src/PersistenceReasonFilters.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.AspNetCore.Components;
5-
64
namespace Microsoft.AspNetCore.Components.Web;
75

86
/// <summary>

src/Components/Components/src/PersistenceReasons.cs renamed to src/Components/Web/src/PersistenceReasons.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.AspNetCore.Components;
4+
namespace Microsoft.AspNetCore.Components.Web;
55

66
/// <summary>
77
/// Represents persistence during prerendering.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
#nullable enable
22
Microsoft.AspNetCore.Components.Web.Internal.IInternalWebJSInProcessRuntime.InvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> string!
3+
Microsoft.AspNetCore.Components.Web.PersistOnCircuitPause
4+
Microsoft.AspNetCore.Components.Web.PersistOnCircuitPause.PersistByDefault.get -> bool
5+
Microsoft.AspNetCore.Components.Web.PersistOnCircuitPause.PersistOnCircuitPause() -> void
36
Microsoft.AspNetCore.Components.Web.PersistOnCircuitPauseFilter
47
Microsoft.AspNetCore.Components.Web.PersistOnCircuitPauseFilter.PersistOnCircuitPauseFilter(bool persist = true) -> void
8+
Microsoft.AspNetCore.Components.Web.PersistOnEnhancedNavigation
9+
Microsoft.AspNetCore.Components.Web.PersistOnEnhancedNavigation.PersistByDefault.get -> bool
10+
Microsoft.AspNetCore.Components.Web.PersistOnEnhancedNavigation.PersistOnEnhancedNavigation() -> void
511
Microsoft.AspNetCore.Components.Web.PersistOnEnhancedNavigationFilter
612
Microsoft.AspNetCore.Components.Web.PersistOnEnhancedNavigationFilter.PersistOnEnhancedNavigationFilter(bool persist = true) -> void
13+
Microsoft.AspNetCore.Components.Web.PersistOnPrerendering
14+
Microsoft.AspNetCore.Components.Web.PersistOnPrerendering.PersistByDefault.get -> bool
15+
Microsoft.AspNetCore.Components.Web.PersistOnPrerendering.PersistOnPrerendering() -> void
716
Microsoft.AspNetCore.Components.Web.PersistOnPrerenderingFilter
817
Microsoft.AspNetCore.Components.Web.PersistOnPrerenderingFilter.PersistOnPrerenderingFilter(bool persist = true) -> void
918
virtual Microsoft.AspNetCore.Components.Routing.NavLink.ShouldMatch(string! uriAbsolute) -> bool

0 commit comments

Comments
 (0)
0