Skip to content
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

Stop processing original response streaming content if user has started navigating away #50814

Conversation

SteveSandersonMS
Copy link
Member

@SteveSandersonMS SteveSandersonMS commented Sep 19, 2023

Stop processing original response streaming content if user has started navigating away

Fix a correctness issue with streaming SSR and enhanced nav

Description

If enhanced nav occurred while streaming SSR was still in progress, subsequent streaming SSR updates could be inserted into the new page even though they are for the old page.

Fixes #50733

Customer Impact

Without this fix, the combination of streaming SSR and enhanced navigation (which is on by default) would be subject to edge-case issues where pages could display incorrect content.

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

Risk

  • High
  • Medium
  • Low

Only affects this one scenario. The change is very targeted.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Sep 19, 2023
@SteveSandersonMS SteveSandersonMS added the Servicing-consider Shiproom approval is required for the issue label Sep 19, 2023
@ghost
Copy link

ghost commented Sep 19, 2023

Hi @SteveSandersonMS. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@SteveSandersonMS SteveSandersonMS self-assigned this Sep 19, 2023
@SteveSandersonMS SteveSandersonMS marked this pull request as ready for review September 19, 2023 12:35
@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner September 19, 2023 12:35
Comment on lines +43 to +46
const isFromEnhancedNav = node.getAttribute('enhanced-nav') === 'true';
if (isFromEnhancedNav || hasNeverStartedAnyEnhancedPageLoad()) {
insertStreamingContentIntoDocument(componentId, node.content);
}
Copy link
Member

Choose a reason for hiding this comment

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

Can it happen that we cancel an enhanced nav mid-way (while some content has already been inserted) and we start processing a new enhanced nav response? Would we be in a situation where we've updated half the DOM and we start updating the rest with a newer version? Or will the new version replace the updated bits so far + the non-updated bits.

Copy link
Member Author

@SteveSandersonMS SteveSandersonMS Sep 19, 2023

Choose a reason for hiding this comment

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

Or will the new version replace the updated bits so far + the non-updated bits.

Yes, that. Each enhanced nav response is treated as a desired end state, and we diff as needed to reach that state, no matter what state we were in before.

Because of the single-threadedness of JS, and because we cancel any preceding enhanced nav response stream before we issue a new request, only the latest enhanced nav response is processed and it replaces whatever content was there before. If the previous fetch was streaming SSR and hadn't finished sending streaming updates, we don't care - we just cancel that previous fetch and hence won't see any more of its streaming updates.

Copy link
Member

Choose a reason for hiding this comment

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

@SteveSandersonMS could that behavior cause weird outcomes/bugs? I imagine that worst case scenario it ends up with the whole document being replaced, I am just trying to think of situations where it could be problematic break things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I know of. This is the way it's designed and expected to work. The guiding principle of enhanced nav is that it should produce the same outcome as a full-page navigation, with the exception of specific things we explicitly preserve (interactive components and data-preserve elements). On those grounds it's correct to disregard orphaned streaming updates from prior navigations.

@SteveSandersonMS
Copy link
Member Author

Note that I've been forced to cherry-pick two other test fixes into this PR in order to get the tests to pass. This may be because the version of Selenium/Chrome has changed in Helix.

@rbhanda rbhanda added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Sep 19, 2023
@ghost
Copy link

ghost commented Sep 19, 2023

Hi @SteveSandersonMS. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed.

@SteveSandersonMS
Copy link
Member Author

The one test failure is completely unrelated (it's Kestrel Http2ConnectionTests), so merging anyway to begin unblocking the backlog of merges.

@SteveSandersonMS SteveSandersonMS merged commit 79b23f4 into release/8.0-rc2 Sep 20, 2023
24 of 26 checks passed
@SteveSandersonMS SteveSandersonMS deleted the stevesa/fix-50733-streaming-continues-after-navigation branch September 20, 2023 09:22
@ghost ghost added this to the 8.0-rc2 milestone Sep 20, 2023
SteveSandersonMS added a commit that referenced this pull request Sep 20, 2023
* Handle obsolete InterceptorsPreview with .NET 8 RC2 SDK (#50797)

* Quarantine (actually comment out) one of the CanRenderComponentWithPersistedState cases (#50811)

See #50810

* Stop processing original response streaming content if user has started navigating away (#50814)

* Reproduce #50733 as a failing E2E test

* Don't process original request blazor-ssr content if the user has already navigated away

* Quarantine (actually comment out) one of the CanRenderComponentWithPersistedState cases

See #50810

* Update EventTest.cs

* Disable another flaky test

---------

Co-authored-by: Matt Thalman <mthalman@microsoft.com>
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
SteveSandersonMS added a commit to dotnet-maestro-bot/AspNetCore that referenced this pull request Sep 20, 2023
…0823)

* Handle obsolete InterceptorsPreview with .NET 8 RC2 SDK (dotnet#50797)

* Quarantine (actually comment out) one of the CanRenderComponentWithPersistedState cases (dotnet#50811)

See dotnet#50810

* Stop processing original response streaming content if user has started navigating away (dotnet#50814)

* Reproduce dotnet#50733 as a failing E2E test

* Don't process original request blazor-ssr content if the user has already navigated away

* Quarantine (actually comment out) one of the CanRenderComponentWithPersistedState cases

See dotnet#50810

* Update EventTest.cs

* Disable another flaky test

---------

Co-authored-by: Matt Thalman <mthalman@microsoft.com>
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
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 Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants