Describe the bug 🐞
This bug involves the use of SetupDefaultSuspendResume<TAppState>(…), together with a typed suspension host. It occurs when no persisted application state exists, such as on first launch. Under these conditions, GetAppState<TAppState>(…) will return null, having failed to invoke the CreateNewAppStateTyped delegate.
According to the XML documentation for CreateNewAppStateTyped, the delegate is intended to be "typically used when the application is launching fresh". However, it is never invoked in this scenario. The suspension system instead seems to fail silently.
This behaviour forces developers to initialise manually the AppStateValue after execution of SetupDefaultSuspendResume<TAppState>(…), which defeats the documented purpose of CreateNewAppStateTyped.
Step to reproduce
- Create a new Avalonia application with ReactiveUI and ReactiveUI.Avalonia.
- Create a simple data transfer object (DTO) class to persist application state.
- Create a
JsonSerializerContext with [JsonSerializable] attributes for the DTO.
- Implement suspension:
- Call
OnFrameworkInitializationCompleted() on your AutoSuspendHelper instance.
- Cast
RxSuspension.SuspensionHost to ISuspensionHost<YourDto>.
- Assign a function to
CreateNewAppStateTyped.
- Call
SetupDefaultSuspendResume<TAppState>(…) with type info.
- Call
GetAppState<TAppState>().
- Ensure that no persisted state file exists. Run the application.
- Observe that
GetAppState<TAppState>(…) returns null, and that CreateNewAppStateTyped is never invoked.
You may refer to my 'DT-Version-2.0' repository linked in this issue as a convenient means of replicating the bug.
Reproduction repository
https://github.com/JosiahDanger/DateToday/tree/DT-Version-2.0
Expected behavior
If GetAppState<TAppState>(…) is called when no persisted state exists, it should:
- Invoke the
CreateNewAppStateTyped delegate to generate a default application state.
- Populate
AppStateValue with the result.
- Return the new, valid state.
Alternatively, the documentation should clarify that CreateNewAppStateTyped is never automatically invoked and that developers must manually initialise AppStateValue before calling GetAppState<TAppState>(…).
Screenshots 🖼️
IDE
Visual Studio 2022
Operating system
Windows 11
Version
25H2
Device
No response
ReactiveUI Version
23.1.8
Additional information ℹ️
ReactiveUI.Avalonia version is 11.4.12
Describe the bug 🐞
This bug involves the use of
SetupDefaultSuspendResume<TAppState>(…), together with a typed suspension host. It occurs when no persisted application state exists, such as on first launch. Under these conditions,GetAppState<TAppState>(…)will return null, having failed to invoke theCreateNewAppStateTypeddelegate.According to the XML documentation for
CreateNewAppStateTyped, the delegate is intended to be "typically used when the application is launching fresh". However, it is never invoked in this scenario. The suspension system instead seems to fail silently.This behaviour forces developers to initialise manually the
AppStateValueafter execution ofSetupDefaultSuspendResume<TAppState>(…), which defeats the documented purpose ofCreateNewAppStateTyped.Step to reproduce
JsonSerializerContextwith[JsonSerializable]attributes for the DTO.OnFrameworkInitializationCompleted()on yourAutoSuspendHelperinstance.RxSuspension.SuspensionHosttoISuspensionHost<YourDto>.CreateNewAppStateTyped.SetupDefaultSuspendResume<TAppState>(…)with type info.GetAppState<TAppState>().GetAppState<TAppState>(…)returns null, and thatCreateNewAppStateTypedis never invoked.You may refer to my 'DT-Version-2.0' repository linked in this issue as a convenient means of replicating the bug.
Reproduction repository
https://github.com/JosiahDanger/DateToday/tree/DT-Version-2.0
Expected behavior
If
GetAppState<TAppState>(…)is called when no persisted state exists, it should:CreateNewAppStateTypeddelegate to generate a default application state.AppStateValuewith the result.Alternatively, the documentation should clarify that
CreateNewAppStateTypedis never automatically invoked and that developers must manually initialiseAppStateValuebefore callingGetAppState<TAppState>(…).Screenshots 🖼️
IDE
Visual Studio 2022
Operating system
Windows 11
Version
25H2
Device
No response
ReactiveUI Version
23.1.8
Additional information ℹ️
ReactiveUI.Avalonia version is 11.4.12