Skip to content
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

.NET 8 RC1 Blazor Web App: [RenderModeAuto] keeps using the Server implementation then switches to WASM #50677

Closed
1 task done
dmm-l-mediehus opened this issue Sep 13, 2023 · 7 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@dmm-l-mediehus
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a simple Weather app that consists of 3 projects:

  • BlazorApp1 (server and API controller for the client)
  • BlazorApp1.Client (client)
  • ClassLibrary1 (shared lib)

Class Library holds interfaces, and service-implementations.

  • In BlazorApp1, I inject the IWeatherService to use WeatherService.cs
  • In BlazorApp1.Client, I inject the IWeatherService to use HttpClientWeatherService.cs

in Weather.razor (BlazorApp1.Client.Components.Weather.razor), I inject IWeatherService and use GetForecastsAsync()-method to get forecasts.

I noticed the app keeps using Server implementation (WeatherService.cs) at first (both navigating from /counter back to weather and F5 refresh) then switches to WASM implementation (HttpClientWeatherService.cs), even though the app is finished downloaded in the background.

Expected Behavior

I expect the Web App to only use the WASM implementation of the service, when the application is downloaded and cached.

Steps To Reproduce

  1. Clone https://github.com/dmm-l-mediehus/BlazorApp1-RenderModeIssue
  2. Run the app with debugging (F5)
  3. Set breakpoints at the HttpClientWeatherService.cs line 19, and WeatherService.cs line 22
  4. Navigate to /weather and the breakpoint will hit Server at first which is fine initially. But when navigating to another page, and back to /weather - it should hit the WASM breakpoint, but doesn't. Same for F5 - it should use the HttpClientWeatherService.cs implementation

Exceptions (if any)

No response

.NET Version

8.0.100-rc.1.23455.8

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Sep 13, 2023
@javiercn
Copy link
Member

@dmm-l-mediehus thanks for contacting us.

That's by design. At least for 8.0, handling the transition between server and webassembly is not trivial, so we require a page refresh (or the next visit) to avoid having to deal with complications derived from the page state.

@dmm-l-mediehus
Copy link
Author

In best practice, then how should I implement this example of using RenderModeAuto and calls to DB?

@mkArtakMSFT
Copy link
Member

Components should rely on abstractions when interacting with services which may have client or server implementations. That way, no matter where they get rendered the environment-specific implementation will provide the right functionality.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Sep 13, 2023
@ghost ghost added the Status: Resolved label Sep 13, 2023
@DM-98
Copy link

DM-98 commented Sep 13, 2023

@mkArtakMSFT That's what I did, right? I have client and server implementations abstracted by an interface, and it calls the database twice which is a bug.

I'm using Microsoft's documentation on stateful reconnection after prerendering by using IMemoryCache...But it still calls it twice since there's 2 different implementations and it calls them both.

Having await Task.Delay(1000); for testing, it waits 2 seconds, and I expect it to be 1 second to load /weather

@ynnob
Copy link

ynnob commented Sep 13, 2023

This might be related to issue #50686

@DM-98
Copy link

DM-98 commented Sep 13, 2023

@ynnob Sounds like it. Just odd they said that's by design, and said what to do in practice to get it to work... and that's exactly what I am doing.

@ghost
Copy link

ghost commented Sep 14, 2023

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Sep 14, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants