Skip to content

Commit feeba90

Browse files
authored
fix(blazor): migrate to ReactiveUI.Primitives.Blazor (#4445)
## What kind of change does this PR introduce? This is a Blazor scheduler and dependency compatibility fix. It migrates the Blazor packages from `Reactive.Wasm` to `ReactiveUI.Primitives.Blazor` and its System.Reactive variant, aligns required servicing dependencies, and adds lean/reactive regression coverage plus a runnable WebAssembly example. closes #4430 ## What is the new behavior? - Blazor WebAssembly uses `WasmSequencer.Default` in the lean package and `WasmScheduler.Default` in the System.Reactive package. - Blazor Server retains the current-thread fallback; renderer-affine work remains component-scoped through `ComponentBase.InvokeAsync`, avoiding an invalid process-wide renderer dispatcher. - `WithBlazorWasm()` consistently configures core services, the WASM main scheduler, the task-pool scheduler, and Blazor platform registrations. - ASP.NET, `Microsoft.Extensions.*`, `System.Text.Json`, and WebAssembly package versions satisfy the `ReactiveUI.Primitives 7.2.0` servicing floors. - A Blazor WebAssembly scheduler-probe example and reactive Blazor test project validate both package seams. ## What is the current behavior? The Blazor projects depend on the removed `Reactive.Wasm` package and do not provide equivalent lean/reactive validation. After updating to `ReactiveUI.Primitives 7.2.0`, lower central ASP.NET, `System.Collections.Immutable`, and `System.Text.Json` pins cause package-downgrade restore failures. ## Checklist - [x] Tests have been added or updated (for bug fixes / features) - [ ] Docs have been added or updated (for bug fixes / features) - [x] Changes target the main branch - [x] PR title follows [Conventional Commits](https://www.conventionalcommits.org/) ## Additional information Root-cause fixes were made without adding warning suppressions, `NoWarn`, pragmas, warning demotion, or analyzer exclusions. Validation completed: - Full solution restore and build: 0 warnings, 0 errors - `ReactiveUI.Blazor.Tests`: 38/38 passed - `ReactiveUI.Blazor.Tests.Reactive`: 11/11 passed - `ReactiveUI.Splat.Tests`: 6/6 passed - `ReactiveUI.Tests`: 2,024/2,024 passed - `ReactiveUI.Tests.Reactive`: 2,024/2,024 passed - `ReactiveUI.Builder.Tests`: 187/187 passed - `BlazorReactiveUIBuilderExtensions`: 100% line coverage in lean and reactive reports - `git diff --check`: clean
1 parent e227460 commit feeba90

17 files changed

Lines changed: 339 additions & 20 deletions

File tree

‎src/Directory.Packages.props‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
</PropertyGroup>
66

77
<PropertyGroup Label="Shared Version Variables">
8-
<SplatVersion>20.2.0</SplatVersion>
9-
<PrimitivesVersion>7.1.1</PrimitivesVersion>
8+
<SplatVersion>21.0.0</SplatVersion>
9+
<PrimitivesVersion>7.2.0</PrimitivesVersion>
1010
<TUnitVersion>1.63.0</TUnitVersion>
1111
<!-- StyleSharp.Analyzers, PerformanceSharp.Analyzers and SecuritySharp.Analyzers ship from the
1212
same release pipeline and always share a version. -->
13-
<RoslynCommonAnalyzersVersion>3.43.2</RoslynCommonAnalyzersVersion>
13+
<RoslynCommonAnalyzersVersion>3.45.0</RoslynCommonAnalyzersVersion>
1414
<XamarinAndroidXLifecycleLiveDataVersion>2.11.0.1</XamarinAndroidXLifecycleLiveDataVersion>
1515
</PropertyGroup>
1616

@@ -19,17 +19,17 @@
1919
<MauiVersion Condition="$(TargetFramework.StartsWith('net11'))">11.0.0-preview.7.26406.9</MauiVersion>
2020

2121
<AspNetVersion Condition="$(TargetFramework.StartsWith('netstandard'))">3.1.32</AspNetVersion>
22-
<AspNetVersion Condition="$(TargetFramework.StartsWith('net8'))">8.0.29</AspNetVersion>
23-
<AspNetVersion Condition="$(TargetFramework.StartsWith('net9'))">9.0.18</AspNetVersion>
24-
<AspNetVersion Condition="$(TargetFramework.StartsWith('net10'))">10.0.10</AspNetVersion>
22+
<AspNetVersion Condition="$(TargetFramework.StartsWith('net8'))">8.0.30</AspNetVersion>
23+
<AspNetVersion Condition="$(TargetFramework.StartsWith('net9'))">9.0.19</AspNetVersion>
24+
<AspNetVersion Condition="$(TargetFramework.StartsWith('net10'))">10.0.11</AspNetVersion>
2525
<AspNetVersion Condition="$(TargetFramework.StartsWith('net11'))">11.0.0-preview.7.26381.103</AspNetVersion>
2626

27-
<SystemTextJsonVersion>10.0.10</SystemTextJsonVersion>
27+
<SystemTextJsonVersion>10.0.11</SystemTextJsonVersion>
2828
<SystemTextJsonVersion Condition="$(TargetFramework.StartsWith('net11'))">11.0.0-preview.7.26381.103</SystemTextJsonVersion>
2929

3030
<!-- Microsoft.Extensions.* and the runtime data packages track the framework: stable 10.0.x for
3131
net8/9/10, the net11 preview on net11 so the net11 ReactiveUI.Primitives assemblies resolve. -->
32-
<MicrosoftExtensionsVersion>10.0.10</MicrosoftExtensionsVersion>
32+
<MicrosoftExtensionsVersion>10.0.11</MicrosoftExtensionsVersion>
3333
<MicrosoftExtensionsVersion Condition="$(TargetFramework.StartsWith('net11'))">11.0.0-preview.7.26381.103</MicrosoftExtensionsVersion>
3434

3535
<XamlBehaviorsWpfVersion Condition="$(TargetFramework.StartsWith('net4'))">1.1.142</XamlBehaviorsWpfVersion>
@@ -58,7 +58,6 @@
5858

5959
<ItemGroup Label="Rx Ecosystem">
6060
<PackageVersion Include="DynamicData" Version="9.4.33"/>
61-
<PackageVersion Include="Reactive.Wasm" Version="3.0.1"/>
6261
<PackageVersion Include="Splat" Version="$(SplatVersion)"/>
6362
<PackageVersion Include="Splat.Autofac" Version="$(SplatVersion)"/>
6463
<PackageVersion Include="Splat.Drawing" Version="$(SplatVersion)"/>
@@ -122,6 +121,8 @@
122121

123122
<ItemGroup Label="Platform - Blazor / ASP.NET">
124123
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="$(AspNetVersion)"/>
124+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.11"/>
125+
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.11"/>
125126
</ItemGroup>
126127

127128
<ItemGroup Label="Legacy Compat Shims">

‎src/ReactiveUI.Blazor.Reactive/ReactiveUI.Blazor.Reactive.csproj‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
<ItemGroup>
1515
<Using Include="ReactiveUI.Internal"/>
1616
<Using Include="ReactiveUI.Primitives.Disposables"/>
17+
<Using Include="ReactiveUI.Primitives.Reactive.Concurrency"/>
1718
</ItemGroup>
1819
<ItemGroup>
19-
<PackageReference Include="Reactive.Wasm"/>
20+
<PackageReference Include="ReactiveUI.Primitives.Blazor.Reactive"/>
2021
<PackageReference Include="Microsoft.AspNetCore.Components"/>
2122
</ItemGroup>
2223
<!-- The same ReactiveUI.Blazor source the lean package ships, recompiled here under REACTIVE_SHIM. -->

‎src/ReactiveUI.Blazor/Builder/BlazorReactiveUIBuilderExtensions.cs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ namespace ReactiveUI.Builder;
1414
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "ReactiveUI is the name of the product.")]
1515
public static class BlazorReactiveUIBuilderExtensions
1616
{
17-
/// <summary>Gets the blazor main thread scheduler.</summary>
17+
/// <summary>Gets the Blazor Server scheduler.</summary>
1818
/// <value>
19-
/// The blazor main thread scheduler.
19+
/// A current-thread scheduler. Renderer-affine work remains component-scoped and is marshalled through
20+
/// <c>ComponentBase.InvokeAsync</c> because Blazor Server has one renderer dispatcher per circuit.
2021
/// </value>
2122
public static ISequencer BlazorMainThreadScheduler { get; } = Sequencer.CurrentThread;
2223

23-
/// <summary>Gets the blazor wasm scheduler.</summary>
24+
/// <summary>Gets the browser WebAssembly event-loop scheduler.</summary>
2425
/// <value>
25-
/// The blazor wasm scheduler.
26+
/// The Primitives scheduler that yields work through the WebAssembly event loop without creating threads.
2627
/// </value>
2728
public static ISequencer BlazorWasmScheduler { get; } =
2829
#if REACTIVE_SHIM
2930
WasmScheduler.Default;
3031
#else
31-
Sequencer.CurrentThread;
32+
WasmSequencer.Default;
3233
#endif
3334

3435
/// <summary>Provides ReactiveUI builder extension methods for Blazor.</summary>
@@ -53,7 +54,7 @@ public IReactiveUIBuilder WithBlazorWasm()
5354
{
5455
ArgumentExceptionHelper.ThrowIfNull(builder);
5556

56-
return builder
57+
return ((IReactiveUIBuilder)builder.WithCoreServices())
5758
.WithBlazorWasmScheduler()
5859
.WithTaskPoolScheduler(TaskPoolSequencer.Default)
5960
.WithPlatformModule<Blazor.Registrations>();

‎src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Using Include="ReactiveUI.Primitives.Disposables"/>
1111
</ItemGroup>
1212
<ItemGroup>
13-
<PackageReference Include="Reactive.Wasm"/>
13+
<PackageReference Include="ReactiveUI.Primitives.Blazor"/>
1414
<PackageReference Include="Microsoft.AspNetCore.Components"/>
1515
</ItemGroup>
1616
<ItemGroup>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<PageTitle>ReactiveUI Blazor WebAssembly</PageTitle>
2+
3+
<main>
4+
<h1>ReactiveUI Blazor WebAssembly</h1>
5+
<SchedulerProbe />
6+
</main>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@inherits ReactiveComponentBase<SchedulerProbeViewModel>
2+
3+
<section>
4+
<p id="scheduler-status">@ViewModel?.Status</p>
5+
<button id="scheduler-probe" @onclick="Schedule">Schedule through ReactiveUI</button>
6+
</section>
7+
8+
@code {
9+
private IDisposable? _execution;
10+
11+
protected override void OnInitialized()
12+
{
13+
ViewModel = new();
14+
base.OnInitialized();
15+
}
16+
17+
private void Schedule()
18+
{
19+
if (ViewModel is not { } viewModel)
20+
{
21+
return;
22+
}
23+
24+
_execution?.Dispose();
25+
_execution = viewModel.Run.Execute().Subscribe();
26+
}
27+
28+
protected override void Dispose(bool disposing)
29+
{
30+
if (disposing)
31+
{
32+
_execution?.Dispose();
33+
}
34+
35+
base.Dispose(disposing);
36+
}
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2009-2026 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using Microsoft.AspNetCore.Components.Web;
7+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
8+
using ReactiveUI.Builder;
9+
10+
namespace ReactiveUI.Builder.BlazorWasm;
11+
12+
/// <summary>The host type generated for the example's top-level statements.</summary>
13+
internal static class Program
14+
{
15+
/// <summary>Gets the assembly containing the WebAssembly example.</summary>
16+
internal static System.Reflection.Assembly HostAssembly => typeof(Program).Assembly;
17+
18+
/// <summary>The main entry point for the WebAssembly example.</summary>
19+
/// <param name="args">The command-line arguments.</param>
20+
/// <returns>A task representing the asynchronous operation.</returns>
21+
internal static async Task Main(string[] args)
22+
{
23+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
24+
25+
builder.RootComponents.Add<App>("#app");
26+
27+
builder.RootComponents.Add<HeadOutlet>("head::after");
28+
29+
_ = RxAppBuilder.CreateReactiveUIBuilder()
30+
.WithBlazorWasm()
31+
.BuildApp();
32+
33+
await builder.Build().RunAsync();
34+
}
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"ReactiveUI.Builder.BlazorWasm": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:57237;http://localhost:57238"
10+
}
11+
}
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<Nullable>enable</Nullable>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<IsPackable>false</IsPackable>
7+
<DefaultPackageDescription>Blazor WebAssembly example app for ReactiveUI Builder.</DefaultPackageDescription>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.AspNetCore.Components" VersionOverride="10.0.11"/>
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly"/>
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" PrivateAssets="all"/>
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\ReactiveUI.Blazor\ReactiveUI.Blazor.csproj"/>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Using Include="ReactiveUI.Primitives"/>
22+
<Using Include="ReactiveUI.Primitives.Disposables"/>
23+
</ItemGroup>
24+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2009-2026 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using System.Diagnostics;
7+
using ReactiveUI.Builder;
8+
9+
namespace ReactiveUI.Builder.BlazorWasm.ViewModels;
10+
11+
/// <summary>View model that verifies work executes through the configured browser event-loop scheduler.</summary>
12+
[DebuggerDisplay("{Status}")]
13+
public sealed class SchedulerProbeViewModel : ReactiveObject
14+
{
15+
/// <summary>Initializes a new instance of the <see cref="SchedulerProbeViewModel"/> class.</summary>
16+
public SchedulerProbeViewModel() => Run = ReactiveCommand.CreateFromTask(ScheduleAsync);
17+
18+
/// <summary>Gets the command that schedules a browser event-loop callback.</summary>
19+
public ReactiveCommand<RxVoid, RxVoid> Run { get; }
20+
21+
/// <summary>Gets the current scheduler verification status.</summary>
22+
public string Status
23+
{
24+
get;
25+
private set => this.RaiseAndSetIfChanged(ref field, value);
26+
} = "Ready";
27+
28+
/// <summary>Schedules work through ReactiveUI's configured main scheduler.</summary>
29+
/// <returns>A task that completes after the event-loop callback runs.</returns>
30+
private async Task ScheduleAsync()
31+
{
32+
var completion = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
33+
using var scheduled = RxSchedulers.MainThreadScheduler.Schedule(
34+
completion,
35+
static (_, source) =>
36+
{
37+
source.SetResult();
38+
return EmptyDisposable.Instance;
39+
});
40+
41+
await completion.Task;
42+
43+
Status = ReferenceEquals(
44+
RxSchedulers.MainThreadScheduler,
45+
BlazorReactiveUIBuilderExtensions.BlazorWasmScheduler)
46+
? "WASM scheduler executed successfully"
47+
: "Unexpected scheduler configured";
48+
}
49+
}

0 commit comments

Comments
 (0)
⌂ 换网址