Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

Update the weather page in the Blazor Web App template to persist prerendered state

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Use [PersistentState] attribute in Weather.razor to avoid "Loading..." flash on direct navigation

Description

When navigating directly to the weather page in an interactive Blazor Web App, users see the prerendered content, then a flash of "Loading...", then the data again. This is particularly noticeable due to the 500ms simulated delay.

The fix uses [PersistentState] to persist the prerendered forecasts and restore them when interactive mode starts:

  • Add [PersistentState] attribute to Forecasts property
  • Change from private field to public property (required for attribute)
  • Make WeatherForecast class public (required for JSON serialization)
  • Skip data loading in OnInitializedAsync when state is already restored
@code {
    [PersistentState]
    public WeatherForecast[]? Forecasts { get; set; }

    protected override async Task OnInitializedAsync()
    {
        if (Forecasts is null)
        {
            await Task.Delay(500);
            // ... load forecasts
        }
    }

    public class WeatherForecast { ... }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Update the weather page in the Blazor Web App template to persist prerendered state</issue_title>
<issue_description>The weather page in the Blazor Web App template doesn't currently persist its prerendered state. This means that if the weather page is rendered interactively and you browse directly to the weather page, you'll see the weather prerendered, then replaced with Loading..., and then rendered again. The flash is particularly visible because we include the Task.Delay(500) to simulate loading the weather data.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@ Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.</comment_new>
<comment_new>@
Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ate] attribute

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Copilot AI changed the title [WIP] Update weather page to persist prerendered state Update the weather page in the Blazor Web App template to persist prerendered state Dec 3, 2025
Copilot AI requested a review from javiercn December 3, 2025 23:40
Copilot finished work on behalf of javiercn December 3, 2025 23:40
@javiercn javiercn marked this pull request as ready for review December 4, 2025 09:38
Copilot AI review requested due to automatic review settings December 4, 2025 09:38
Copilot finished reviewing on behalf of javiercn December 4, 2025 09:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Weather page in the Blazor Web App template to use the [PersistentState] attribute, which eliminates the "Loading..." flash that occurs when directly navigating to the weather page. The feature works by persisting the prerendered weather forecast data and restoring it when the component becomes interactive, avoiding the need to reload the data and display the loading indicator.

Key Changes:

  • Applied [PersistentState] attribute to persist weather forecast data across prerendering
  • Converted private field to public property (required for state persistence)
  • Made WeatherForecast class public (required for JSON serialization)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update the weather page in the Blazor Web App template to persist prerendered state

2 participants