Performance issues with input.on_change #414
Replies: 3 comments 6 replies
-
Thanks for this feedback, this is something I think we can find a solution for and will just take some work arounds on our end. Ideally uncontrolled events like I'm going to brainstorm this over the next day or so and see if I can find a solution that is purely under the hood so the user doesn't have to do anything special for this to work. This solution should enable the |
Beta Was this translation helpful? Give feedback.
-
Thanks! Perhaps another option is to only set Just using |
Beta Was this translation helpful? Give feedback.
-
For anyone who needs to solve this before a fix gets released, here's a useful hack: 1. Change your input field to use on_blur, like this: pc.input(
on_blur=State.set_user_message,
), 2. Use injected JavaScript to clear input fields after the user does something, like this: pc.html(
"""<script>
var buttons = document.getElementsByTagName("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", function() {
if (this.innerText == "Send") {
var inputs = document.getElementsByTagName("input");
for (var j = 0; j < inputs.length; j++) {
inputs[j].value = "";
}
}
});
}
</script>""" |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is an issue or I'm doing something wrong, so posting here before issues.
I'm building a chat interface. I have this state:
Then, in my form, I have this:
This works fine when there isn't a lot of message history, but as soon as it starts getting long it becomes exceedingly difficult to type in the input, I assume because there's some kind of memory issue related to saving the message with each key pressed.
Is there a way around this? I tried with
on_blur
, but then I couldn't clear the input after the user posted their message.PS: Loving Pynecone. Just working through some of the differences with pure Python, HTML, and JS that I'm more used to.
Beta Was this translation helpful? Give feedback.
All reactions