-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Declarative state persistence base case failure #61456
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
Comments
You beat me to it. I was about to click submit on the same issue that I encountered after trying Preview 3. I also commented about similar issue I faced on the other day after trying the daily bits #26794 (comment) |
Indeed, @soundaranbu! Actually, the docs that I put up yesterday for the use of this are currently wrong 😢, but I only had the PR to go on. We (the whole docs team) even thought that release was next Tuesday, so we thought we had more time to iron bugs out of things. I'll have the guidance fixed by EOD. However, a [SupplyParameterFromPersistentComponentState]
public WeatherForecast[]? Forecasts { get; set; }
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate a loading indicator
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
Forecasts ??= Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
} XXXXXXXXXXX Logger: Executing OnInitializedAsync! 4/11/2025 1:12:44 PM
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/12/2025 - Bracing - 7 - 44
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/13/2025 - Balmy - 5 - 40
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/14/2025 - Chilly - -13 - 9
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/15/2025 - Cool - 39 - 102
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/16/2025 - Bracing - 44 - 111
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
XXXXXXXXXXX Logger: Executing OnInitializedAsync! 4/11/2025 1:12:45 PM
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/12/2025 - Bracing - 7 - 44
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/13/2025 - Balmy - 5 - 40
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/14/2025 - Chilly - -13 - 9
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/15/2025 - Cool - 39 - 102
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Weather[0]
4/16/2025 - Bracing - 44 - 111 |
The way to set an initial value is through null coalescing within OnInitialized(Async)
|
@guardrex can you push the repro to a GH repo so that I can read through the details? |
This comment has been minimized.
This comment has been minimized.
Placed it here ... https://github.com/guardrex/DeclarativeStateTesting The UPDATE (5/12): I modified the
|
Good news BTW ... I checked all of the guidance that I placed yesterday; and except for a few minor NITs here and there, all of the other examples of the approach are correct. This counter component problem/exception is the only actually broken 😈 example. |
One more note ... For demo purposes in the article, I need to show the assignment and the restoration, if possible. I was hoping something like this would work ... if (CurrentCount is null)
{
CurrentCount = Random.Shared.Next(100);
Logger.LogInformation("CurrentCount set to {Count}", CurrentCount);
}
else
{
Logger.LogInformation("CurrentCount restored to {Count}", CurrentCount);
} ... but since the approach is breaking, I just get the first block of the conditional called twice ... info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Counter2[0]
CurrentCount set to 69
fail: Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager[1000]
There was an error executing a callback while pausing the application.
System.ArgumentException: Cannot bind to the target method because its signature is not compatible with that of the delegate type.
at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags)
at Microsoft.AspNetCore.Components.Reflection.PropertyGetter..ctor(Type targetType, PropertyInfo property)
at Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateValueProvider.PropertyGetterFactory(ValueTuple`2 key)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateValueProvider.ResolvePropertyGetter(Type type, String propertyName)
at Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateValueProvider.<>c__DisplayClass11_0.<Subscribe>b__0()
at Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.<TryPauseAsync>g__TryExecuteCallback|18_0(Func`1 callback, ILogger`1 logger)
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Counter2[0]
CurrentCount set to 97
Works well with a class, so I'll use the following in the article so that we don't have a broken example published ... @page "/counter-3"
@inject ILogger<Counter3> Logger
<PageTitle>Prerendered Counter 3</PageTitle>
<h1>Prerendered Counter 3</h1>
<p role="status">Current count: @State?.CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
[SupplyParameterFromPersistentComponentState]
public CounterState? State { get; set; }
protected override void OnInitialized()
{
if (State is null)
{
State = new() { CurrentCount = Random.Shared.Next(100) };
Logger.LogInformation("CurrentCount set to {Count}", State.CurrentCount);
}
else
{
Logger.LogInformation("CurrentCount restored to {Count}", State.CurrentCount);
}
}
private void IncrementCount()
{
if (State is not null)
{
State.CurrentCount++;
}
}
public class CounterState
{
public int CurrentCount { get; set; }
}
} info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Counter3[0]
CurrentCount set to 60
info: BWA10P3TestDeclarativePersistStateDELETEME.Components.Pages.Counter3[0]
CurrentCount restored to 60 |
Is there an existing issue for this?
Describe the bug
Javier ...
Working on validating/updating the code demos in articles for the new persistent component state model and hit a gremlin 😈.
Expected Behavior
No exception and retain the generated value in a counter component that uses the new model.
Steps To Reproduce
Akin to what you show in the OP of the PR at #60634 (but I made the property
public
), BUT this demo should set an initial value on initialization to demo how a value created on the server can be held for final rendering.This issue is really just asking how to approach this scenario more so than a bug report. I don't think it's a bug, of course! 😄
Vanilla BWA 10.0 Preview 3 with global Interactive Server rendering.
Counter2.razor
:Exceptions (if any)
Output ...
.NET Version
10.0.100-preview.3.25201.16
Anything else?
No response
The text was updated successfully, but these errors were encountered: