Skip to content

Commit

Permalink
Fix StateRoot not restoring it's own state
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Sep 16, 2024
1 parent eb23921 commit 5ee1ea2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<p>Current rendermode: @RendererInfo.Name</p>

State: @Text

@if (!RendererInfo.IsInteractive)
{
<p>Waiting for interactivity..</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using BitzArt.Blazor.State.SampleApp.Client.Components;

namespace BitzArt.Blazor.State.SampleApp.Client.Pages;
namespace BitzArt.Blazor.State.SampleApp.Client.Pages;

public partial class CounterPage : PersistentComponentBase
{
[ComponentState]
private string Text = "Not Initialized";

protected override void InitializeState()
{
Text = "Initialized";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
Expand Down Expand Up @@ -83,6 +82,16 @@ protected override async Task<bool> TryRestoringStateAsync()
}

PageState = RestoreBase64State(stateBase64);

var state = PageState.GetComponentState([]);

if (state is null)
{
// Root state not found.
return false;
}

RestoreComponentState(state);
StateInitialized = true;

PersistentComponent.OnStateRestoredInternal();
Expand Down

0 comments on commit 5ee1ea2

Please sign in to comment.