Closed dannyBies closed 3 years ago
In case this is purely a docs issue ...
Although we've made updates to the Prerendering and integration topic for 6.0, I haven't confirmed the guidance/fixed remaining problems with the coverage. I've noted to do so for this topic on the 6.0 docs tracking issue. I'll keep an 👁️ on this PU issue in the meantime.
@dannyBies thanks for contacting us.
Would you mind providing a minimal repro as a publicly accessible GH repository to help us move forward? We have automation covering this scenario and its very hard for us to detect if you are missing a step or doing something slightly differently based on the docs.
Yeah no problem, I have added the repro here: https://github.com/dannyBies/BlazorPreserveComponentStateRepro.
This repro has been generated using the default blazor server template with VS 2022 17.0.0 Preview 3.1
and sdk 6.0.0-preview.7.21378.6
.
The only files that I've changed are:
@dannyBies ... Was the app not generated from the 6.0 preview project template? _Host.cshtml
with that content leads me to believe that's the case. The markup for the layout of a 6.0 preview app would be in _Layout.cshtml
.
Here's the spot that I'd expect based on the new project template ...
... but I see that you do target net6.0
in the project file and otherwise looks like a 6.0 preview app.
I have generated it using the .NET 6.0 (Preview) option and have used this template to use other preview features which work fine.
I just checked that running dotnet new blazorserver
will generate the same template as VS and not the one you've linked. I've also ran dotnet new --update-check
to confirm I have the latest version of the templates.
Is there something special I need to do to use the preview templates?
I'm not sure as I haven't adopted 6.0 preview yet. I tend to adopt them for final doc content check with the release of RC1 (coming soon) due to engineering churn. At RC1, I will check all of (or most of) our 6.0 preview content in local test apps to make sure that we're good on coverage.
I just noticed that it didn't match, so either the SDK that VS is using might be older/different or there's another reason for it ... e.g., a short delay until the latest SDK (or latest VS preview) rolls out given that the PU repo here (or VS preview) can lag the actual appearance of the SDK for download.
Could you generate a Blazor Server project fresh from the command line ... dotnet new blazorserver
... and see if you get a project with _Layout.cshtml
. If so, give that a shot with the guidance. If not ... or if it still doesn't work even with _Layout.cshtml
... stand-by here for product unit support.
I'll continue to watch this 👀 as the "doc guy" for a potential update that I can make to our current doc guidance.
I can confirm that I don't get a _Layout.cshtml
file when using dotnet new blazorserver
, I'll see if I can manually copy paste the relevant code from https://github.com/dotnet/aspnetcore/tree/main/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp later tonight to see if that fixes the issue.
Although I would assume that I would be able to use <preserve-component-state />
even without the latest template. But I'll try it out later to see if that fixes the main issue.
I appreciate the help :)
I don't think it will turn out to be the cause of the problem. The PU will respond when they get a chance, and I'll update the doc guidance as needed based on what they come up with.
UPDATE: But it turns out that the original feature was Preview 7, which is out now ...
https://github.com/dotnet/aspnetcore/pull/34518
I see you noted that you have 6.0.100-preview.7.21379.14
in your opening remarks.
I just had another quick look and I found the issue.
In the docs the following needs to be changed:
if (!ApplicationState.TryTakeAsJson<WeatherForecast[]>("fetchdata", out var forecasts))
to
if (!ApplicationState.TryTakeAsJson<WeatherForecast[]>("fetchdata", out forecasts))
as currently it shadows the forecasts
variable. I completely overlooked that!
I'm assuming the issue with my templates not being up to date is because these have not been released yet. I'll have another look when a new update gets released for VS 2022, but for now my issue has been solved. Thanks for the help @guardrex!
Thanks @dannyBies. The code was dumped into the doc from the blog post. When I get on RC1, all of (or most of) the code examples will be checked. Some of them, including that example, will be improved and loaded into a snippet sample app that will break at runtime on that type of error. I'll get the doc fixed up soon.
In the meantime, ~I'll revert back to the example and use data
~ ... actually, there were updates that follow the second blog post, so I'll adopt your approach ...
UPDATE: This will be resolved on https://github.com/dotnet/AspNetCore.Docs/pull/23152.
No problem at all, I'm working with preview bits after all :)
Describe the bug
I'm following the guide at https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-6.0&pivots=server#preserve-prerendered-state to preserve the prerendered component state. However when I try to run the application I get the following error:
To Reproduce
1 -> Create new Blazor Server template 2 -> Add the
<preserve-component-state />
below<script src="_framework/blazor.server.js"></script>
in_Host.cshtml
3 -> Change the code inFetchDate.razor
to the code mentioned in https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-6.0&pivots=server#preserve-prerendered-state. 4 -> Run applicationIt seems this issue also occurs using the hosted webassembly template but I'm not familiar enough with that approach to be 100% sure of that.
A few more potential issuesI have noticed:
ApplicationState.OnPersisting
is not working because when I add a breakpoint it doesn't seem to be getting hit<preserve-component-state />
Further technical details
ASP.NET Core version 6.0.100-preview.7.21379.14 Visual studio community 2022 preview 3.1