-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[BLAZOR WASM] Lagging textarea binding with large amount of text #17951
Comments
Please show your code for LoadNotes |
There you go.
However, I am pretty convinced this doesn't cause the delay, beause it fires only when the user stops typing, but the lagging is while the user presses keystrokes. Moreover, I tried to commend out the content of the LoadNotes() and the lagging textarea for huge text still persisted. |
Can you create a new Blazor wasm app that reproduces this? |
I have created a sample repo showing this lagging behaviour in the textarea: Just paste huge amounts of texts in the textarea and you will see the lagging letters as you type. For me, the lagging in the sample demo started around the length of 7535 characters. In my own project, it starts much sooner, somewhere around 1000-2000 characters. |
This is a more minimal reproduction of the problem.
It seems the lag is when JS invokes Blazor in order to update |
|
It's expected that Blazor components will trigger a re-render when an event handler is invoked. The solution that @mrpmorris shared above should help with programmatically controlling when re-renders happen. As for the original performance issue, I profiled this on Edge with the latest version of Blazor WASSM (the RC, at the moment) with a textbox containing 18,000 characters. Each handler takes around 100ms to execute, which is slightly noticeable but not super laggy. Some follow-ups:
|
That is correct. However, you have to look at the context. Who types text in textarea in rate of 1 character/second? The delay obviously stacks, so when you type quickly you get delay of seconds before you see the word in the textarea. Please use the multiple reproductions posted above to try the real UI experience in context. |
You could also havr the element change event go to solve javascript and control how often it calls blazor. Say, immediately, but not again for another 50 or 100ms, the typing experience might be better that way. |
I am having this problem too, it's very very easy to reproduce, you should not need an example from the community to reproduce this behavior, it's mind numbingly easy. Just bind-value and bind-value:event="oninput" or attach any onkey* event handler on a textarea OR input type="text" and hold a key down or try to type quickly, the words do not appear until you pause typing and let go of keys. This is very confusing to the user because they think it's not working until they stop typing and the text suddenly appears. The strange part about this, is that I have an input box on another page that has an 'oninput' event handler and does not suffer from the same input lagg even though the event handlers are virtually identical. I have tried every single combination of onkeydown, onkeypress, onkeyup, oninput, onchange, etc.. There is no input lagg on the element unitl I attach a blazor binding/event-handler, and it seems to only happen on complex pages during the "onkeyup" phase. The lowest amount of lagg I had in the elements were when using "onkeyup" as an event handler. If you hold a key down, there was no lagg, but if you tried typing random characters quickly then it would lagg. So my guess is there's something on the "KeyUp" handler internally that's slowing things down when attached to blazor events/binding. I'm assuming a re-rendering (however it should be noted that the new characters appear, meaning rendering is still happening even with the keydown and there is no lagg). |
I think I might have found a workaround. @captainsafia had mentioned something that gave me an idea.
When an input control or textarea is INSIDE of a larger, more complex Blazor component, the events cause the parent component to re-render it's contents. This is laggy when the Blazor component is large, however! If you make a NEW component, and ONLY put the input box in that component and then add that component in the same place as the original input box. It's renders MUCH MUCH MUCH faster, and I have virtually no lagg. So this problem is definitely tied to how complex the input/textarea's parent component is, and you can side skirt this issue by placing the input in a much less complicated container component. |
Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue! |
I am using textarea in Blazor webassembly (core 3.1) which is binded to a property in the page. I am using bind-value and bind-value:event because when I use only bind="Property" then It does not update as the user is typing which is my use case. I am using this binded value to send requests and save current content of the textarea after the user stops typing.
<textarea @bind-value="Note.Content" @bind-value:event="oninput" @onkeyup="@NoteTypingKeyUp"></textarea>
It works fine when the text in the textarea is short. For large amounts it causes UI delays as the user types letters are appearing with a very significant delay.
Is it a known bug and is there some workaround?
Thanks
The text was updated successfully, but these errors were encountered: