-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Support persistent component state across enhanced page navigations #62526
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
Draft
Copilot
wants to merge
15
commits into
main
Choose a base branch
from
copilot/fix-51584
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5d415ec
Initial plan
Copilot bd834c2
Initial commit - start implementing scenario-based persistent compone…
Copilot 2524d25
Implement core scenario-based persistent component state interfaces a…
Copilot 8265903
Complete scenario-based persistent component state implementation wit…
Copilot 85759ef
Move scenario-based persistent component state tests to Components.We…
Copilot 3a1d69c
Address feedback: Refactor scenario-based component state filtering
Copilot a8f65ed
Implement updated design for scenario-based persistent component state
Copilot 757ba83
Remove scenario-based RegisterOnRestoring method per review feedback
Copilot 5d2bb55
Address review feedback: Use filters directly instead of scenarios in…
Copilot 59e2436
Add comprehensive tests for scenario-based RestoreStateAsync in Compo…
Copilot 60fcdf5
Implement E2E tests for scenario-based persistent component state fil…
Copilot 96c41d9
Implement core scenario-based persistent component state functionality
Copilot 6a9513e
Complete server-side circuit integration for scenario-based persisten…
Copilot 2bc3d0e
Address review feedback: Use PrerenderComponentApplicationStore, make…
Copilot e180005
Fix E2E test scenarios to match design document specifications
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
16 changes: 16 additions & 0 deletions
16
src/Components/Components/src/IPersistentComponentStateScenario.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Represents a scenario for persistent component state restoration. | ||
/// </summary> | ||
public interface IPersistentComponentStateScenario | ||
{ | ||
/// <summary> | ||
/// Gets a value indicating whether callbacks for this scenario can be invoked multiple times. | ||
/// If false, callbacks are automatically unregistered after first invocation. | ||
/// </summary> | ||
bool IsRecurring { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Defines filtering logic for persistent component state restoration. | ||
/// </summary> | ||
public interface IPersistentStateFilter | ||
{ | ||
/// <summary> | ||
/// Determines whether state should be restored for the given scenario. | ||
/// </summary> | ||
/// <param name="scenario">The restoration scenario.</param> | ||
/// <returns>True if state should be restored; otherwise false.</returns> | ||
bool ShouldRestore(IPersistentComponentStateScenario scenario); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Components/Components/src/RestoreComponentStateRegistration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Represents a registration for state restoration callbacks. | ||
/// </summary> | ||
internal readonly struct RestoreComponentStateRegistration | ||
{ | ||
public RestoreComponentStateRegistration(IPersistentStateFilter filter, Action callback) | ||
{ | ||
Filter = filter; | ||
Callback = callback; | ||
} | ||
|
||
public IPersistentStateFilter Filter { get; } | ||
public Action Callback { get; } | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Components/Components/src/RestoringComponentStateSubscription.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Represents a subscription to state restoration notifications. | ||
/// </summary> | ||
public readonly struct RestoringComponentStateSubscription : IDisposable | ||
{ | ||
private readonly List<RestoreComponentStateRegistration>? _callbacks; | ||
private readonly IPersistentStateFilter? _filter; | ||
private readonly Action? _callback; | ||
|
||
internal RestoringComponentStateSubscription( | ||
List<RestoreComponentStateRegistration> callbacks, | ||
IPersistentStateFilter filter, | ||
Action callback) | ||
{ | ||
_callbacks = callbacks; | ||
_filter = filter; | ||
_callback = callback; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() | ||
{ | ||
if (_callbacks != null && _filter != null && _callback != null) | ||
{ | ||
for (int i = _callbacks.Count - 1; i >= 0; i--) | ||
{ | ||
var registration = _callbacks[i]; | ||
if (ReferenceEquals(registration.Filter, _filter) && ReferenceEquals(registration.Callback, _callback)) | ||
{ | ||
_callbacks.RemoveAt(i); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for this in ComponentStatePersistenceManagerTests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comprehensive tests for the scenario-based RestoreStateAsync functionality in ComponentStatePersistenceManagerTest. The tests cover first-time initialization, scenario-based updates, and backward compatibility behavior including the _isFirstRestore logic. (59e2436)