-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix streaming SSR timing issue (#51333)
# Fix streaming SSR timing issue On certain rare occasions, streaming SSR could produce a blank page due to a timing issue. ## Description If a page component: * Has `@attribute [StreamRendering]` * Is being visited through enhanced navigtion * Has an `OnInitializedAsync` whose returned task is not pre-completed but does complete very quickly (e.g., `await Task.Yield()`) ... then there was a race condition. On rare occasions (seems to be about 1 in 20 page loads), the result would be a blank page. This didn't show up in our E2E tests because they always wait for fairly long async tasks so that the browser automation had time to observe the loading states. This PR adds a new E2E test that does recreate the issue and reliably fails - it does many, many page loads and basically always hits the problem at least once without the fix included here. Fixes #51345 ## Customer Impact Without this fix, a particular combination of features would be unreliable. ## Regression? - [ ] Yes - [x] No [If yes, specify the version the behavior has regressed from] ## Risk - [ ] High - [ ] Medium - [x] Low The only change is to fix what is definitely a bug. It's hard to see how this would have a negative effect, as no other code is built on top of this. It's not a public API - it's just part of how the Razor Components endpoint works. ## Verification - [x] Manual (required) - [x] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A
- Loading branch information
1 parent
cbfc558
commit faf594a
Showing
8 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...s/Components.TestServer/RazorComponents/Pages/StreamingRendering/VeryBriefStreaming.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@page "/brief-streaming" | ||
@attribute [StreamRendering] | ||
|
||
<h3 id="brief-streaming">Brief streaming</h3> | ||
|
||
<p> | ||
At one point there was a bug whereby, if streaming was enabled but only waited | ||
for a very short period, it could insert the SSR framing markers in the wrong place, | ||
making the output corrupt and causing the UI to be replace with a blank page. | ||
</p> | ||
<p> | ||
The test loads this page via enhanced nav many times, validating it always loads. | ||
</p> | ||
|
||
<a href="brief-streaming">Load this page</a> | ||
|
||
@if (isLoaded) | ||
{ | ||
<p> | ||
Load counter: <span id="load-count">@loadCount</span> | ||
</p> | ||
} | ||
|
||
@code { | ||
static int loadCount; | ||
bool isLoaded; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await Task.Yield(); | ||
loadCount++; | ||
isLoaded = true; | ||
} | ||
} |