dotnet / dotnet/aspnetcore

Cancellation support for StreamRendering

Open
#51,838 1 comment 0 reactions 0 assignees View on GitHub
area-blazor enhancement feature-blazor-streaming-rendering
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

#50733 implemented the cancellation of the serverside streamrendering on navigation.

However, there does not seem to be a way to trigger cancellation from the user.

### Describe the solution you'd like

IE, the scenario is to have a cancel button that will just trigger the AbortController (`currentEnhancedNavigationAbortController` in https://github.com/dotnet/aspnetcore/blob/main/src/Components/Web.JS/src/Services/NavigationEnhancement.ts).

```csharp
@attribute [StreamRendering]

...
Abort request

[CascadingParameter]
public HttpContext HttpContext { get; set; } = default!;
private async Task OnValidSubmit()
{
_submitting = true;
try
{
await Task.Delay(TimeSpan.FromSeconds(10), HttpContext?.RequestAborted ?? default);
} catch (TaskCanceledException e) {
logger.LogInformation("Cancelled");
throw;
}
_submitting = false;
_submitted = true;
}
```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.