Tailslide / fluxor-persist

Fluxor-persist is a library to persist Fluxor states.
MIT License
25 stars 13 forks source link

Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error. #14

Open vincejairam opened 1 year ago

vincejairam commented 1 year ago

I am using Blazor Server and followed the instructions on setting this up e.g. this was added to main, where I essentially copy the sample LocalStateStorage class

builder.Services.AddBlazoredLocalStorage();
builder.Services.AddScoped<IStringStateStorage, LocalStateStorage>();
builder.Services.AddScoped<IStoreHandler, JsonStoreHandler>();

builder.Services.AddFluxor(config =>
{
    config
        .ScanAssemblies(typeof(Program).Assembly)
#if DEBUG
        .UseReduxDevTools(rdt =>
        {
            rdt.Name = "MY APP";
        })
#endif
        .UsePersist()
        ;
});

When I start my app, I see the error at the top of the page "Attempting to reconnect to the server: 1 of 8" the console has the following error "[2023-09-10T17:05:49.166Z] Error: Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.'. log @ blazor.server.js:1 " The page eventually loads and I can see my view, data has loaded, store is created in localstorage. I now click on a detail page for an item or navigate to another page etc. same error etc.

Am I missing something for the setup? Does this work with Blazor Server vs Blazor WASM? I am using "Fluxor Version="5.9.1" and Blazored.LocalStorage" Version="4.4.0"

vincejairam commented 1 year ago

Also please confirm, I want all my stores or most of them to be stored in local storage and DO NOT want Fluxor to use in memory for the stores that I want to utilize for local storage any more, that is the intent of this library correct?

Tailslide commented 1 year ago

I haven’t tested with Fluxor 5.9.1 since I can’t find any information on what changed in that release.

Is Fluxor working in your project if you do not use Fluxor.Persist?

Does the sample blazer server project in this repo work for you with Fluxor 5.9.0?

This library lets you persist a copy of the state (typically in local storage but could also be elsewhere). You can persist all state or just the states you flag. There is still a copy in memory. If you have a large amount of data you don’t want in memory you should be looking at indexedDb.

vincejairam commented 1 year ago

Hi @Tailslide , thanks for the quick response. Yes when I comment out the line for UsePersist the app works with no issues. I haven't tried 5.9.0 with the sample application. I did download and run the sample app with no issues. I also change my version to 5.9.0 as I taught it might be an issue as the your docs indicate support at 5.9.0 level but it was still giving me the same issue.

I would like however to get rid of the in copy memory from Fluxor as its quite large, that was the main reason at looking at this package. I've never used indexedDb would that be a addon to Fluxor or a replacement all together....

Tailslide commented 1 year ago

Fluxor Persist will not solve your memory problems even if we get it working on your project.

IndexedDb is a completely different system than Fluxor. It is a database built into the browser you can inspect it with F12 from the browser. Here is a library for it:

https://github.com/amuste/DnetIndexedDb

The author disappeared so here is a fork and .NET 7 nuget I made of it: https://github.com/Tailslide/DnetIndexedDb/tree/newpublish. There might be other packages for it too if you search around.

If you have just certain states that are huge you might want to move those states from Fluxor to IndexedDb but then they will of course not be Fluxor states anymore.

vincejairam commented 1 year ago

Hi @Tailslide , thanks for the clarification and information, much appreciated.

Tailslide commented 10 months ago

Did you ever get this working? If you're still stuck since the sample is working for you just gradually copy your project into the sample project and keep testing after each page/state to make sure it doesn't break.

Tailslide commented 8 months ago

Feel free to re-open this issue or open another issue if you need more help.

danik121 commented 7 months ago

Same problem. FLuxor version 5.9.1. Sample code is not working

Tailslide commented 7 months ago

Ok I will take a look when I get a chance