mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.25k stars 144 forks source link

Fluxor is not compatible in .NET 6. #224

Closed hkillp closed 2 years ago

hkillp commented 2 years ago

I have a Blazor web assembly project target .NET 5, this project implemented Fluxor. When I upgraded this project to .NET 6, it does not work anymore.

How to reproduce the issue?

  1. Create 2 default Web Assembly projects, one project target .NET 5, the other project target .NET 6. https://github.com/hkillp/blazorFluxor
  2. Implementing Fluxor with the latest version (Fluxor.Blazor.Web 4.1.0).
  3. Monitor CounterState changes when clicking the button "click me" of the Counter component in the Chrome Development tool. Results :
    • With project target .NET 5, we can see the state changes.
    • With project target .NET 6, when we click the button click me, the state does not change. Issue: the view on UI does not change accordingly to the application state.

So are there any workarounds to make it work or do we have to wait for other Fluxor versions to support .NET 6?

mrpmorris commented 2 years ago

@hkillp would you mind adding a comment explaining what the cause of the problem was?

sinnerbenkei commented 2 years ago

I am having the same problem, everything works perfectly until switching to use .NET 6 (Not sure if it is the same issue as the original poster.

The problem I am encountering is the store initializer does not seem to appropriately parse the javascript response in StoreInitializer.cs when calling:

protected override async Task OnAfterRenderAsync(bool firstRender)

  try
  {
    **if (!await this.JSRuntime.InvokeAsync<bool>("tryInitializeFluxor"))**
      throw new StoreInitializationException("Failed to initialize store");
    await this.Store.InitializeAsync();
  }
  catch (JSException ex)
  {
    throw new StoreInitializationException("JavaScript error", (Exception) ex);
  }

it appears to be returning a null and fails to determine that the initialize method succeeded, even though if I execute tryInitializeFluxor() or put a breakpoint in the javascript it should be returning true.

Error trace from Rider:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: JavaScript error Fluxor.Exceptions.StoreInitializationException: JavaScript error ---> Microsoft.JSInterop.JSException: An exception occurred executing JS interop: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4.. See InnerException for more details. ---> System.Text.Json.JsonException: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4. ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a boolean. at System.Text.Json.Utf8JsonReader.GetBoolean() at System.Text.Json.Serialization.Converters.BooleanConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) at System.Text.Json.Serialization.JsonConverter1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Boolean& value) at System.Text.Json.Serialization.JsonConverter1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) at System.Text.Json.Serialization.JsonConverter1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.Serialization.JsonConverter1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[Object](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.Read[Object](Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo) at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options) at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 taskId, Boolean succeeded, Utf8JsonReader& jsonReader) --- End of inner exception stack trace --- at Microsoft.JSInterop.JSRuntime.d__16`1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() at Fluxor.Blazor.Web.StoreInitializer.OnAfterRenderAsync(Boolean firstRender) --- End of inner exception stack trace --- at Fluxor.Blazor.Web.StoreInitializer.OnAfterRenderAsync(Boolean firstRender) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

mrpmorris commented 2 years ago

@hkillp @sinnerbenkei I just tried a basic counter app from scratch and it worked. Could either of you provide me with a repro?

robertmrobo commented 2 years ago

@hkillp @sinnerbenkei I just tried a basic counter app from scratch and it worked. Could either of you provide me with a repro?

I can confirm as well that my app is currently running on dotnet 6 with Fluxor without any issues.

hkillp commented 2 years ago

Sorry for late reply. My app is working well in .Net 6.

Vào 0:13, Th 2, 15 thg 11, 2021 robertmrobo @.***> đã viết:

@hkillp https://github.com/hkillp @sinnerbenkei https://github.com/sinnerbenkei I just tried a basic counter app from scratch and it worked. Could either of you provide me with a repro?

I can confirm that my app is currently running on dotnet 6 with Fluxor without any issues.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mrpmorris/Fluxor/issues/224#issuecomment-968330099, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG6OJN36U55TTOX7VSLVDMDUL7U4LANCNFSM5HDM2QAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sinnerbenkei commented 2 years ago

just wanted to drop back in and say after making some modifications to my project with varying results, eventually I tried upgrading to the 4.2.2 Alpha preview build, and I haven't had any issues since.