-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Update the weather page in the Blazor Web App template to persist prerendered state #64644
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
base: main
Are you sure you want to change the base?
Conversation
…ate] attribute Co-authored-by: javiercn <[email protected]>
There was a problem hiding this 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
WeatherForecastclass public (required for JSON serialization)
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
/azp run aspnetcore-template-tests-pr, aspnetcore-ci |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Update the weather page in the Blazor Web App template to persist prerendered state
Use
[PersistentState]attribute in Weather.razor to avoid "Loading..." flash on direct navigationDescription
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:[PersistentState]attribute toForecastspropertyWeatherForecastclass public (required for JSON serialization)OnInitializedAsyncwhen state is already restoredOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.