-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
1 / 11 of 1 issue completedLabels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Components
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issuesTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
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
:
@page "/counter-2"
@inject ILogger<Counter2> Logger
<PageTitle>Prerendered Counter 2</PageTitle>
<h1>Prerendered Counter 2</h1>
<p role="status">Current count: @CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
[SupplyParameterFromPersistentComponentState]
public int? CurrentCount { get; set; }
protected override void OnInitialized()
{
CurrentCount ??= Random.Shared.Next(100);
Logger.LogInformation("CurrentCount set to {Count}", CurrentCount);
}
private void IncrementCount() => CurrentCount++;
}
Exceptions (if any)
Output ...
info: BlazorSample.Components.Pages.Counter2[0]
CurrentCount set to 77
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: BlazorSample.Components.Pages.Counter2[0]
CurrentCount set to 43
.NET Version
10.0.100-preview.3.25201.16
Anything else?
No response
soundaranbu
Sub-issues
Collapse Sub-issuesSub-issues
- Manage this item control⌃ shift⇧ uU
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Components
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
soundaranbu commentedon Apr 11, 2025
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)
guardrex commentedon Apr 11, 2025
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
Weather
component approach akin to the counter example that I showed does work ...javiercn commentedon Apr 11, 2025
The way to set an initial value is through null coalescing within OnInitialized(Async)
javiercn commentedon Apr 11, 2025
@guardrex can you push the repro to a GH repo so that I can read through the details?
guardrex commentedon Apr 11, 2025
guardrex commentedon Apr 11, 2025
Placed it here ...
https://github.com/guardrex/DeclarativeStateTesting
The
Counter2
component is the one throwing and not restoring state 😈.UPDATE (5/12): I modified the
Counter2
component to make ...int
.OnInitialized
method use null-coalescing.guardrex commentedon Apr 11, 2025
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.
guardrex commentedon Apr 11, 2025
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 ...
... but since the approach is breaking, I just get the first block of the conditional called twice ...
decimal
anddouble
do the same thing.Works well with a class, so I'll use the following in the article so that we don't have a broken example published ...
[-]Declarative state persistence base case failure[/-][+][Pre5] Declarative state persistence base case failure[/+][-][Pre5] Declarative state persistence base case failure[/-][+]Declarative state persistence base case failure[/+]javiercn commentedon Jul 16, 2025
This was fixed in #62368