Skip to content

Commit 34b3127

Browse files
Fix issue with Blazor state (#4786)
* Update beta version * Update BlazorExample to net10.0 and csla 10 * #4774 Update state handling * #4774 Diagnosing and fixing blazor context issue * Update sample * Update Samples/BlazorExample/BlazorExample/BlazorExample.Client/Components/Pages/Counter.razor Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Samples/BlazorExample/BlazorExample/BlazorExample/Components/Layout/NavMenu.razor Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0dbacff commit 34b3127

File tree

15 files changed

+39
-36
lines changed

15 files changed

+39
-36
lines changed

Samples/BlazorExample/BlazorExample/BlazorExample.Client/BlazorExample.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>

Samples/BlazorExample/BlazorExample/BlazorExample.Client/Components/Pages/Counter.razor

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
<h1>Counter</h1>
1010

11+
<p>RenderMode: @RendererInfo.Name, Interactive: @RendererInfo.IsInteractive</p>
12+
1113
<p role="status">Current count: @currentCount</p>
1214

13-
@if (IsInteractive)
15+
@if (RendererInfo.IsInteractive)
1416
{
1517
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
1618
}
@@ -19,7 +21,6 @@
1921
[CascadingParameter]
2022
private Task<AuthenticationState>? authenticationState { get; set; }
2123
private int currentCount = 0;
22-
private bool IsInteractive;
2324

2425
protected override async Task OnInitializedAsync()
2526
{
@@ -32,19 +33,10 @@
3233
}
3334
}
3435

35-
protected override void OnAfterRender(bool firstRender)
36-
{
37-
base.OnAfterRender(firstRender);
38-
if (firstRender)
39-
{
40-
IsInteractive = true;
41-
StateHasChanged();
42-
}
43-
}
44-
4536
private void IncrementCount()
4637
{
4738
currentCount++;
4839
applicationContext.LocalContext["counter"] = currentCount;
40+
StateManager.SaveState();
4941
}
5042
}

Samples/BlazorExample/BlazorExample/BlazorExample/BlazorExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

Samples/BlazorExample/BlazorExample/BlazorExample/Components/App.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<base href="/" />
8-
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
9-
<link rel="stylesheet" href="app.css" />
10-
<link rel="stylesheet" href="BlazorExample.styles.css" />
11-
<link rel="icon" type="image/png" href="favicon.png" />
8+
<link rel="stylesheet" href="@Assets["bootstrap/bootstrap.min.css"]" />
9+
<link rel="stylesheet" href="@Assets["app.css"]" />
10+
<link rel="stylesheet" href="@Assets["BlazorExample.styles.css"]" />
11+
<link rel="icon" type="image/png" href="@Assets["favicon.png"]" />
1212
<HeadOutlet />
1313
</head>
1414

Samples/BlazorExample/BlazorExample/BlazorExample/Controllers/CslaStateController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Csla;
33
using Csla.State;
4+
using Csla.Blazor.State.Messages;
45

56
namespace BlazorExample.Controllers
67
{

Samples/BlazorExample/BlazorExample/BlazorExample/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
// Add CSLA
1919
builder.Services.AddCsla(o => o
2020
.AddAspNetCore()
21-
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false));
21+
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false)
22+
.DataPortal(o => o.AddServerSideDataPortal()));
2223

2324
// configure DAL services for EF or Mock:
2425

@@ -46,7 +47,7 @@
4647

4748
app.UseHttpsRedirection();
4849

49-
app.UseStaticFiles();
50+
app.MapStaticAssets();
5051
app.UseAntiforgery();
5152

5253
app.MapControllers();

Samples/BlazorExample/BlazorExample/BusinessLibrary/BusinessLibrary.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>

Samples/BlazorExample/BlazorExample/DataAccess.EF/DataAccess.EF.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

Samples/BlazorExample/BlazorExample/DataAccess.Mock/DataAccess.Mock.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<AssemblyName>DataAccess.Mock</AssemblyName>

Samples/BlazorExample/BlazorExample/DataAccess/DataAccess.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

0 commit comments

Comments
 (0)