le-nn / memento

A simple client-side state management container for Blazor/.NET includes redo/undo and ReduxDevTools support.
https://github.com/le-nn/memento
MIT License
39 stars 2 forks source link

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

Closed ikk3 closed 8 months ago

ikk3 commented 8 months ago

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.

ikk3 commented 8 months ago

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

And I tried global @rendermode to

, 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);
    }
}
le-nn commented 8 months ago

@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

ikk3 commented 8 months ago

@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

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

On the other hand, the project I am developing is

Thank you.