Skip to content

Persisting Data Across SSR and Blazor Server #50741

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

Closed
1 task done
darena-pjindal opened this issue Sep 15, 2023 · 3 comments
Closed
1 task done

Persisting Data Across SSR and Blazor Server #50741

darena-pjindal opened this issue Sep 15, 2023 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@darena-pjindal
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This is not a bug. I am hoping there is a best-practice answer for this. We have a scenario where a page loads as SSR, but then the interactive Blazor server component takes over. We need to call an API to a secured endpoint from the interactive component. We already have the access token during the SSR call. We create a scoped service and use that to save the access token when the SSR page loads. Then, we can get the access token back from that service in the interactive component to make the calls to the API. Is it ok to assume that a scoped service will stay between a SSR call and the Signal R session. If not, how do you share data between SSR and Signal R session. We saw that we could use the persist pre-render state but not sure if that is a better way. Thanks in advance for help.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

dotnet8

Anything else?

No response

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Sep 15, 2023
@javiercn
Copy link
Member

@darena-pjindal thanks for contacting us.

No, the scope is not shared between the initial SSR request and Blazor Server. Blazor already has a feature to persist prerendered component state (link below) and we are working to make it work on Blazor Web too (no need for the tag helper, it happens automatically).

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/persist-component-state?view=aspnetcore-7.0#persist-state-for-prerendered-components

@darena-pjindal
Copy link
Author

Hello @javiercn - thanks so much for your response. Could you please clarify where we should add the today for a blazor web app, as the index and host page don't exist? Also, it seems that the docs might not be correct for the Webassembly section. There are referring to the _host page here.
image

@javiercn
Copy link
Member

@darena-pjindal the feature is expected to land in RC2 for Blazor Web.

Those docs are for the implementation before Blazor Web, where the components were hosted on an MVC/Razor pages page.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

2 participants