Skip to content

Fix Persistent Component State for Re-executed Endpoints - #68032

Merged
ilonatommy merged 27 commits into
dotnet:mainfrom
Yuvan111:fix-64386-persiststate
Aug 5, 2026
Merged

ilonatommy merged 27 commits into
dotnet:mainfrom
Yuvan111:fix-64386-persiststate

Conversation

@Yuvan111

Copy link
Copy Markdown
Contributor

Fix Persistent Component State for Re-executed Endpoints

Description

When a request results in endpoint re-execution (for example, navigating to a non-existent route that is re-executed to render a /not-found page), persisted component state is not emitted to the response. As a result, components using persistent state lose their prerendered state during hydration and behave as if no state was persisted.

The root cause is that persisted state rendering is currently skipped for both error handlers and re-executed requests. However, persisted state should only be suppressed for error handler responses. Re-executed endpoints, including interactive NotFound pages, still require persisted state to be rendered.

Changes

  • Updated the persisted state rendering logic to continue emitting persistent component state during endpoint re-execution.
  • Preserved the existing behavior for error handler responses where persisted state should not be rendered.
  • Added/updated tests covering the re-execution scenario to ensure persisted state is available for interactive NotFound pages.

Before

  • Direct navigation to an interactive page correctly persisted component state.
  • Requests that triggered endpoint re-execution (for example, /asd → NotFound page) did not persist component state.
  • Authentication state serialization/deserialization and other features that rely on persistent state could fail for re-executed pages.

After

  • Persisted component state is correctly rendered for re-executed endpoints.
  • Interactive NotFound pages hydrate correctly with their prerendered state.
  • Authentication state persistence works consistently across normal and re-executed requests.

Testing

  • Added coverage for endpoint re-execution scenarios.
  • Verified that persisted state is rendered when a request is re-executed to a NotFound endpoint.
  • Verified that existing error handler behavior remains unchanged.

Fixes #64386

@Yuvan111
Yuvan111 requested a review from a team as a code owner July 27, 2026 06:28
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 27, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @Yuvan111. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copilot AI review requested due to automatic review settings August 5, 2026 03:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes persisted component state emission for endpoint re-execution scenarios (e.g., StatusCodePages re-executing a request to render an interactive NotFound page). This aligns persistent state behavior with expected hydration requirements: suppress state only for exception-handler responses, not for re-executed endpoints.

Changes:

  • Update RazorComponentEndpointInvoker to emit persisted component state during endpoint re-execution (but still suppress it for exception-handler responses).
  • Extend the interactive re-executed NotFound test page to include a persistent-state component.
  • Add an E2E test validating that persisted state is restored and that the persisted-state marker is present in the raw HTML response for a re-executed NotFound page.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPageInteractive.razor Adds a persistent-state component to the interactive re-executed NotFound page to validate restoration.
src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs Adds an E2E test asserting persisted state restoration and presence of the persisted-state marker for re-executed NotFound responses.
src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs Changes persisted-state emission to be skipped only for exception-handler responses (not re-executed endpoints).

@ilonatommy
ilonatommy enabled auto-merge (squash) August 5, 2026 09:57
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Aug 5, 2026
@ilonatommy ilonatommy added this to the 11.0-rc1 milestone Aug 5, 2026
@ilonatommy
ilonatommy merged commit c445615 into dotnet:main Aug 5, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PersistentState] not working when page is re-executed

3 participants