-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to use Fluxor with the new Blazor Web App paradigm? .NET8.0 #459
Comments
Okay, so I found a way to get things going. Works like this: You define your actions, state and reducers completely like normal on the
You call this method in
and also on the
I didn't find a good place to initialize the store yet. Currently it only gets initialized the first time you hit a
but then it'll work and seemingly won't reinitialize every time you hit this page. The store also doesn't get destroyed if you navigate away. But registering the service on both sides is essential! |
Can confirm I get this same error on a clean .Net 8 webassembly app with a simple Fluxor state.
Program.cs
Routes.razor
Home.razor
|
Interestingly...... I just converted my static web app WebAssembly application to .Net 8 and Fluxor had no issues. So maybe it's some conflict with the hosted model? |
@Rhywden When you add Fluxor to your services in the server project, the ScanAssemblies method has an overload that allows you to include additional assemblies so you can reference the Client assembly.
I have also not found a way to initialize the store so for now I am also placing the initializer on any client side page that uses Fluxor in the same manner as you are doing. |
One way to initialize the client side store is to add a component in your client project that contains
and then add this component to your main layout page in the server project. |
The default |
This would scan with the official docs on DI: |
Yes, that's where I got it from. |
Having the same problem but still struggling with following the above suggestions. Does anyone have a minimal implementation they could share? |
Please tell us what options you selected for Interactive render mode and Interactivity location when creating the project(s). |
Auto and (is this my issue?) per page/component |
Do the components using Fluxor exist only in the Client (WebAssembly) project? |
I have created a sample application that demonstrates Fluxor working in the client (WASM) successfully with a client counter. The application also includes a server side counter that does not work consistently, and if it does work, the client side counter will not work. |
Thank you so much. Your solution works for me, but copying across into my solution doesn't work. I think I must have other issues to resolve as part of my .net8 migraion. I will continue hunting. |
Are you talking about the new "static server side rendering"? If so, that's a stateless approach. The state of the page is determined on every render, so you don't need local state. |
Yes, but the original issue was on how to get it working at all. We found out but the docs might need an update. |
@mrpmorris The example that I put on Github is using InteractiveServer and InteractiveWebAssembly rendering to represent a stateful application on both the server and the client. This example will only work with one of these render modes, and the server rendered counter does not always work. Please try the example to see this. |
Isn't asking how to get a state library to work on a stateless architecture like asking where to put the petrol in a solar panel? They are different things. |
InteractiveServer render mode is not stateless. |
@mrpmorris Did you have a chance to look at my stateful server and client application? It seems that the Fluxor library will only work with either InteractiveServer or InteractiveWebAssembly rendering. |
So I had to register my fluxor and other services on both client and server. However, my stores are only on the client as I do not intend on using them ons server currently, or Ill move them to a shared library and register them that way. However, I also required making the StoreInitializer on the Routes, utilize the InteractiveServer rendermode as it was running as static and thus, no functionality.
Hope that Helps |
It looks like the Store can only be initialized once, either WASM or Server. If InteractiveAuto is used and only InteractiveServer pages are used, the store is initialized as InteractiveServer and then InteractiveAuto components can't use the store. If only InteractiveWebAssembly pages are used the store is initialized as InteractiveWebAssembly and then InteractiveServer pages don't work. It seems like some work is required to initialize the store once but in a way that both WASM and Server components can use it. |
Just to make it clear: Even if both sides (server and client) can initialize a store, they'll be decoupled and completely independent of each other. |
I have registered the services on both server and client, however the store has had no issues with interactive auto. The initial load uses server, subsequent loads use the DLL. If you refresh the page the state is always lost, which is normal Fluxor behaviour. |
I don't think InteractiveAuto actually works, see the following link: All my tests show that it just does pre-rendering. I'm not sure if this affects the use of the In my tests I'm going with the @Rhywden suggestion of using the store initializer from a component in the client project with interactive auto rendering but it only initializes once, either on the server or the client. @SethVanderZanden how are you initializing the store if you have it working in both places? |
This would mean that InteractiveAuto (if it actually worked) wouldn't really work well with Fluxor. The page would load by fetching data from a server side store and then any interactivity on the page would then be handed off to WASM, which would be a different store, so the state would be different. I see limited uses for InteractiveAuto anyway, so I wouldn't say this was a "show-stopper". |
In routes.razor w rendermode as InteractiveServer. The base functionality will work fine for InteractiveAuto. The base functionality of Fluxor works the same on both interactiveserver and interactivewebassembly to my knowledge, correct me if I'm wrong. Just like in the past I don't recall setting up Fluxor differently or having 2 different set of code to work on Server or WebAssembly, they all store state within the tab and is lost on refresh no matter the rendering method. |
I updated my sample. Counters on both Server and WebAssembly work. State will be lost on the Server counters once you switch to using only WebAssembly as the connection to the server is cleaned up (this is to be expected). There are 2 separate Server counters (Server Counter and Server Double Counter) that you can switch between and see that they maintain state. A couple of points:
|
I'm facing the same issue as above. |
@mrpmorris can you elaborate? Oringally there was an App.razor file in the client project of the old templates. With the new template there is no App.razor file, and no mention in the documentation on where to place Is it that the new template is simply not supported at this time? |
All my routable components I have decided I will keep in /Pages Thanks to @stagep for pointing me to putting the render mode on the component to ensure it only loads on client side. |
Hey - Have only just now started thinking about this, haven't had a play with the idea yet but thought I would give my first thoughts...
Again, its just a first thought, I've not tried it but will be looking into this when I do get a chance... |
@Rhywden Is your intention to only use it in WASM? |
I've created a PR at #481 that fixes the issues with Fluxor (currently only supports .NET 6 or newer) not appearing to work on both the server/web assembly (pre-render or not), but also added a persistence mechanism so state is maintained whether the user transitions between either render mode. There's some smaller work remaining as described on the PR comments:
Demonstration (using .NET 8) available here. |
Sorry for the late reply - currently I'm only using it for the client side. The components which rely on Fluxor also make heavy use of interactivity like click events and thus don't really work server-rendered anyway ;) |
You might consider using |
@Rhywden I've been playing around with Unfortunately, it doesn't appear I can write to the And when the data is being persisted to another state store (e.g. Redis, Cosmos, etc.) after each set of non-setup actions, you don't know why the rehydration is happening, so even if you were using the So neat tool, especially in the use case described in the blog post you linked to (e.g. one-time data per circuit that need only be retrieved at startup), but I don't think it's a good fit here. |
We should be able to revert this once mrpmorris/Fluxor#459 is fixed. More context: mrpmorris/Fluxor#481.
Now with .NET8 released into production we also have what was formerly called Blazor United, i.e. where there formerly was a strict distinction between Blazor Server and Blazor WASM we now have both in one application.
Problem is that I cannot quite figure out how to get Fluxor to get to work on the "client side". For example,
App.razor
simply does not exist anymore, only on the "server". This here does not work:client/Program.cs
client/Pages/Counter.razor
which yields:
InvalidOperationException: Cannot provide a value for property 'Store' on type 'Fluxor.Blazor.Web.StoreInitializer'. There is no registered service of type 'Fluxor.IStore'.
Changing to
InteractiveWebAssembly
does not change anything about that.So, is there a way forward?
The text was updated successfully, but these errors were encountered: