le-nn / memento

A simple client-side state management container for Blazor/.NET includes redo/undo and ReduxDevTools support.

Home Page:https://github.com/le-nn/memento

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET 8 : to be compatible with '@rendermode InteractiveAuto/InteractiveWebAssembly/InteractiveServer'

ikk3 opened this issue · comments

commented

While referring to sample projects, source folders, and documentation, I tried applying Memento ReduxDevToolMiddleware (Browser/Remote) to a template project set to 'Interactive render mode:Auto', but it cannot be connected with Redux DevTools.

image

I would be happy if I could see the status changes for SSR mode and WASM mode separately on DevTools, but is this possible to applying Memento ReduxDevToolMiddleware?

Thank you.

commented

I changed from the template options posted previously and created another project with the settings below.

  • Interactive render mode : Auto
  • Interactivity location : Global

And I tried global @rendermode to

  • InteractiveServer
  • InteractiveWebAssembly
  • InteractiveWebAssemblyRenderMode(false) - turning off pre-rendering using SSR

, but the result remained the same, it cannot be connected with Redux DevTools.

(App.razor)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="/" />
    <link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
    <link rel="stylesheet" href="app.css" />
    <link rel="stylesheet" href="BlazorApp.Net8Template.InteractiveAutoGlobal.styles.css" />
    <link rel="icon" type="image/png" href="favicon.png" />
    @if (ApplyInteractiveServer())
    {
        <HeadOutlet @rendermode="InteractiveServer" />
    }
    else if (ApplyInteractiveWebAssembly())
    {
        <HeadOutlet @rendermode="InteractiveWebAssembly" />
    }
    else if (ApplyInteractiveWebAssemblyPreRenderOff())
    {
        <HeadOutlet @rendermode="new InteractiveWebAssemblyRenderMode(false)" />
    }
    else
    {
        <HeadOutlet @rendermode="InteractiveAuto" />
    }
</head>

<body>
    <MementoInitializer />

    @if (ApplyInteractiveServer())
    {
        <Routes @rendermode="InteractiveServer" />
    }
    else if (ApplyInteractiveWebAssembly())
    {
        <Routes @rendermode="InteractiveWebAssembly" />
    }
    else if (ApplyInteractiveWebAssemblyPreRenderOff())
    {
        <Routes @rendermode="new InteractiveWebAssemblyRenderMode(false)" />
    }
    else
    {
        <Routes @rendermode="InteractiveAuto" />
    }
    <script src="_framework/blazor.web.js"></script>
</body>

</html>

@inject NavigationManager NavigationManager
@code {
    private bool ApplyInteractiveServer()
    {
        return NavigationManager.Uri.EndsWith("/SSR", StringComparison.InvariantCultureIgnoreCase);
    }

    private bool ApplyInteractiveWebAssembly()
    {
        return NavigationManager.Uri.EndsWith("/WASM", StringComparison.InvariantCultureIgnoreCase);
    }

    private bool ApplyInteractiveWebAssemblyPreRenderOff()
    {
        return NavigationManager.Uri.EndsWith("/WASM-NOPR", StringComparison.InvariantCultureIgnoreCase);
    }
}

@ikk3

Hi !
Thank you for reporting the issue.
You need to declare service registration for both Client Side Project and Server Side project.

Client Side

builder.Services
    .AddMemento()
    .AddBrowserReduxDevToolMiddleware(new() {
        StackTraceEnabled = true,
        OpenDevTool = true,
    })
    .ScanAssemblyAndAddStores(typeof(Memento.Sample.Blazor.App).Assembly);

Server Side

builder.Services
    .AddMemento()
    .AddBrowserReduxDevToolMiddleware(new() {
        StackTraceEnabled = true,
        OpenDevTool = true,
    }, true)
    .ScanAssemblyAndAddStores(typeof(Memento.Sample.Blazor._Imports).Assembly);

I have added the Blazor WebApp sample.

https://github.com/le-nn/memento/tree/main/samples/Memento.Samples.Blazor.WebApp

commented

@le-nn
Thank you for your reply.

I have confirmed that it is working with ReduxDevTools, in local execution by using
[samples/Memento.Samples.Blazor.WebApp]
referring to

  • samples/Memento.Sample.Blazor
    and the nuget package
  • Memento.ReduxDevTool.Browser(1.7.0)
  • Memento.Blazor(1.7.0)
  • Memento.Core(1.7.0)

It seems that
[Memento.Samples.Blazor.WebApp]
is applied to the VSTemplate of

  • Interactive render mode: Auto
  • Interactivity location: Global
    , so I think it is compatible with .NET8's @rendermode.

On the other hand, the project I am developing is

  • Interactive render mode: Auto
  • Interactivity location: Global
    so I tried to identify the difference between VSTemplate and
    [samples/Memento.Samples.Blazor.WebApp]
    ,and apply it, but integration with ReduxDevTools did not work well...

Thank you.