-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add info of limitation for TextArea Control in Blazor #29523
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
Comments
Hello @MSIH ... I sympathize with you that the error message aspect has been backlogged for now. Hopefully, they'll get to that issue soon-ish; but with it not making the cut for .NET 8 this year, it likely will be next year. I see a couple of things to do here ...
I'm in and out on vacation for the end of this month, and we're working on .NET 8 as our top priority in July-August, but I'm fairly certain that I can reach this issue within a few weeks. I'll get on this ASAP. 🏃 Thanks for the issue! |
UPDATE: Mackinnon, I'm going to go ahead and get this on a PR and get it merged this morning to clear this, as I have a lot of .NET 8 content work to do next. I'll message you for a review after .NET 8 releases when we're less busy.@MackinnonBuck ... The ask is WRT moving a very large value from a Although we certainly can cross-link the large and complex For simple one-off value read and for the sake of a quick demo and explanation of streaming an element value like this (that I can also point out in the doc has broader application for reading very large values into C#), I think we should show something else in the Forms article. For a basic use case that dovetails with our other Forms article examples, what do you think about something like the following (versioned 6.0+)? <script>
window.getText = (elem) => {
const textValue = elem.value;
const utf8Encoder = new TextEncoder();
const encodedTextValue = utf8Encoder.encode(textValue);
return encodedTextValue;
};
</script> public class ExampleModel2
{
public string TextAreaValue { get; set; } = string.Empty;
} @page "/form-example-10"
@inject IJSRuntime JS
@inject ILogger<FormExample10> Logger
<h1>Form Example 10</h1>
<EditForm Model="@exampleModel" OnSubmit="@HandleSubmit">
<p>
<label>
<textarea> value streamed for assignment to <code>TextAreaValue (<= 50,000 characters)</code>:
<textarea @ref="largeTextArea" />
</label>
</p>
<button type="submit">Submit</button>
</EditForm>
<p>
TextAreaValue length: @exampleModel.TextAreaValue1.Length
</p>
@code {
private ExampleModel2 exampleModel = new();
private ElementReference largeTextArea;
private async Task HandleSubmit()
{
exampleModel.TextAreaValue = await GetTextAsync();
Logger.LogInformation("TextAreaValue length: {Length}", exampleModel.TextAreaValue.Length);
}
public async Task<string> GetTextAsync()
{
try
{
var streamRef = await JS.InvokeAsync<IJSStreamReference>("getText", largeTextArea);
var stream = await streamRef.OpenReadStreamAsync(maxAllowedSize: 50_000);
var streamReader = new StreamReader(stream);
return await streamReader.ReadToEndAsync();
}
catch (JSException jsException)
{
// Due to security considerations, zero-length streams/textareas aren't permitted for streaming JS Interop.
if (jsException.InnerException is ArgumentOutOfRangeException outOfRangeException &&
outOfRangeException.ActualValue is not null &&
outOfRangeException.ActualValue is long actualLength &&
actualLength == 0)
{
return string.Empty;
}
throw;
}
}
} |
It is unfortunate that this works with an exception that will be thrown regularly - a rather expensive approach for production. |
There is a known problem with copying and pasting a large amount of content into Textarea component with Blazor server. Please document the problem and solution so other users do not have to waste many hours searching the internet to understand and get a fix.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: