8000 Address review feedback: Use PrerenderComponentApplicationStore, make… · dotnet/aspnetcore@2bc3d0e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2bc3d0e

Browse files
Copilotjaviercn
andcommitted
Address review feedback: Use PrerenderComponentApplicationStore, make attribute implementations explicit, clear state after operations
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
1 parent 6a9513e commit 2bc3d0e

File tree

7 files changed

+27
-50
lines changed

7 files changed

+27
-50
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ Microsoft.AspNetCore.Components.Web.Internal.IInternalWebJSInProcessRuntime.Invo
33
virtual Microsoft.AspNetCore.Components.Routing.NavLink.ShouldMatch(string! uriAbsolute) -> bool
44
Microsoft.AspNetCore.Components.Web.RestoreStateOnPrerenderingAttribute
55
Microsoft.AspNetCore.Components.Web.RestoreStateOnPrerenderingAttribute.RestoreStateOnPrerenderingAttribute(bool restore = true) -> void
6-
Microsoft.AspNetCore.Components.Web.RestoreStateOnPrerenderingAttribute.ShouldRestore(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
76
Microsoft.AspNetCore.Components.Web.RestoreStateOnReconnectionAttribute
87
Microsoft.AspNetCore.Components.Web.RestoreStateOnReconnectionAttribute.RestoreStateOnReconnectionAttribute(bool restore = true) -> void
9-
Microsoft.AspNetCore.Components.Web.RestoreStateOnReconnectionAttribute.ShouldRestore(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
108
Microsoft.AspNetCore.Components.Web.UpdateStateOnEnhancedNavigationAttribute
119
Microsoft.AspNetCore.Components.Web.UpdateStateOnEnhancedNavigationAttribute.UpdateStateOnEnhancedNavigationAttribute() -> void
12-
Microsoft.AspNetCore.Components.Web.UpdateStateOnEnhancedNavigationAttribute.ShouldRestore(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
1310
Microsoft.AspNetCore.Components.Web.WebPersistenceScenario
1411
Microsoft.AspNetCore.Components.Web.WebPersistenceScenario.RenderMode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode?
1512
override Microsoft.AspNetCore.Components.Web.WebPersistenceScenario.Equals(object? obj) -> bool

src/Components/Web/src/RestoreStateOnPrerenderingAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public RestoreStateOnPrerenderingAttribute(bool restore = true)
2121
}
2222

2323
/// <inheritdoc />
24-
public bool ShouldRestore(IPersistentComponentStateScenario scenario)
24+
bool IPersistentStateFilter.ShouldRestore(IPersistentComponentStateScenario scenario)
2525
{
2626
return WebPersistenceFilter?.ShouldRestore(scenario) ?? false;
2727
}

src/Components/Web/src/RestoreStateOnReconnectionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public RestoreStateOnReconnectionAttribute(bool restore = true)
2121
}
2222

2323
/// <inheritdoc />
24-
public bool ShouldRestore(IPersistentComponentStateScenario scenario)
24+
bool IPersistentStateFilter.ShouldRestore(IPersistentComponentStateScenario scenario)
2525
{
2626
return WebPersistenceFilter?.ShouldRestore(scenario) ?? false;
2727
}

src/Components/Web/src/UpdateStateOnEnhancedNavigationAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class UpdateStateOnEnhancedNavigationAttribute : Attribute, IPersi
1212
internal WebPersistenceFilter WebPersistenceFilter { get; } = WebPersistenceFilter.EnhancedNavigation;
1313

1414
/// <inheritdoc />
15-
public bool ShouldRestore(IPersistentComponentStateScenario scenario)
15+
bool IPersistentStateFilter.ShouldRestore(IPersistentComponentStateScenario scenario)
1616
{
1717
return WebPersistenceFilter.ShouldRestore(scenario);
1818
}

src/Components/Web/test/ScenarioBasedPersistentComponentStateTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ public void FilterAttributes_ShouldRestore_WorksCorrectly()
111111
var rec 8000 onnectionFilter = new RestoreStateOnReconnectionAttribute();
112112

113113
// Act & Assert
114-
Assert.True(enhancedNavFilter.ShouldRestore(enhancedNavScenario));
115-
Assert.False(enhancedNavFilter.ShouldRestore(prerenderingScenario));
116-
Assert.False(enhancedNavFilter.ShouldRestore(reconnectionScenario));
114+
Assert.True(((IPersistentStateFilter)enhancedNavFilter).ShouldRestore(enhancedNavScenario));
115+
Assert.False(((IPersistentStateFilter)enhancedNavFilter).ShouldRestore(prerenderingScenario));
116+
Assert.False(((IPersistentStateFilter)enhancedNavFilter).ShouldRestore(reconnectionScenario));
117117

118-
Assert.False(prerenderingFilter.ShouldRestore(enhancedNavScenario));
119-
Assert.True(prerenderingFilter.ShouldRestore(prerenderingScenario));
120-
Assert.False(prerenderingFilter.ShouldRestore(reconnectionScenario));
118+
Assert.False(((IPersistentStateFilter)prerenderingFilter).ShouldRestore(enhancedNavScenario));
119+
Assert.True(((IPersistentStateFilter)prerenderingFilter).ShouldRestore(prerenderingScenario));
120+
Assert.False(((IPersistentStateFilter)prerenderingFilter).ShouldRestore(reconnectionScenario));
121121

122-
Assert.False(reconnectionFilter.ShouldRestore(enhancedNavScenario));
123-
Assert.False(reconnectionFilter.ShouldRestore(prerenderingScenario));
124-
Assert.True(reconnectionFilter.ShouldRestore(reconnectionScenario));
122+
Assert.False(((IPersistentStateFilter)reconnectionFilter).ShouldRestore(enhancedNavScenario));
123+
Assert.False(((IPersistentStateFilter)reconnectionFilter).ShouldRestore(prerenderingScenario));
124+
Assert.True(((IPersistentStateFilter)reconnectionFilter).ShouldRestore(reconnectionScenario));
125125
}
126126
}

src/Components/WebAssembly/WebAssembly/src/Rendering/DictionaryPersistentComponentStateStore.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Components/WebAssembly/WebAssembly/src/Rendering/WebAssemblyRenderer.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ public WebAssemblyRenderer(IServiceProvider serviceProvider, ResourceAssetCollec
5252
[UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "These are root components which belong to the user and are in assemblies that don't get trimmed.")]
5353
private async void OnUpdateRootComponents(RootComponentOperationBatch batch, IDictionary<string, byte[]>? persistentState)
5454
{
55+
PrerenderComponentApplicationStore? store = null;
56+
5557
// Handle persistent state restoration if available
5658
if (_componentStatePersistenceManager != null && persistentState != null)
5759
{
58-
var store = new DictionaryPersistentComponentStateStore(persistentState);
60+
store = new PrerenderComponentApplicationStore();
61+
store.ExistingState.Clear();
62+
foreach (var kvp in persistentState)
63+
{
64+
store.ExistingState[kvp.Key] = kvp.Value;
65+
}
66+
5967
var scenario = _isFirstUpdate
6068
? WebPersistenceScenario.Prerendering()
6169
: WebPersistenceScenario.EnhancedNavigation(RenderMode.InteractiveWebAssembly);
@@ -97,6 +105,12 @@ private async void OnUpdateRootComponents(RootComponentOperationBatch batch, IDi
97105
}
98106
}
99107

108+
// Clear state after processing operations when it's not the first update
109+
if (!_isFirstUpdate && store != null)
110+
{
111+
store.ExistingState.Clear();
112+
}
113+
100114
NotifyEndUpdateRootComponents(batch.BatchId);
101115
}
102116

0 commit comments

Comments
 (0)
0