Preventing parent re-renders or preventing input fields from losing their current value on re-render
Hi all.
I have a Solara application where there is a separate thread (using solara.thread) that periodically performs some work and updates a text component, at some interval. In addition, there are some other components that use solara.InputInt/solara.InputFloat/solara.InputText that the user can interact with.
However, if the user is in the middle of inputting a value (the cursor is located in the Input component) and the thread runs its work and updates its text component, the current value of the Input component is resetted. This makes it very hard to input values if the thread runs at .e.g. once every second, as it will just reset the value the user tries to input.
I know that there is a parameter called "continuous_update=True" that will set the value of the Input component for every single character inputted, but the problem is that this, in turn, would trigger a huge amount of updates in other places of my application, which I would want to avoid (e.g. a text field might contain 50 characters, which would mean 50 updates).
I have attached some python code with an small example that shows the problem. You can run it with "solara run example.py".
If you try to input an integer into the first IntInput, your progress will be lost every second, so you need to be very quick when inputting the value. I have also added some debug prints to show when a component is updated, and it actually seems like the input components are not updated when the thread is running, but even still the progress seems to be lost? I don't understand that.
This problem (so far) only occurs with solara.InputInt/solara.InputFloat/solara.InputText, and other types of components behave as expected.
Can I avoid a child component (TimerComponent in my example) from resetting the value of other Input components in the parent component?
Thanks beforehand for reading 🙂
Python: 3.11.7
Solara: 1.39.0
3 Replies
Yeah, this sounds like a bug in the solara component:
https://py.cafe/maartenbreddels/solara-rerender-input-bug
I've added a 3rd field, using the underlying v.TextField where this does not happen. Would you mind opening an issue on GitHub?
PyCafe - Solara - Demonstrates a bug with solara updating the Input...
Create & Share Streamlit, Dash and Python Apps Online.
Thanks for the input! I created an issue for it here: https://github.com/widgetti/solara/issues/779
suhren
<:issue_open:882464248951877682> [widgetti/solara] Input fields losing their current in-progress value on re-render
I have a Solara application where there is a separate thread (solara.use_thread or solara.lab.use_task) that periodically performs some work and updates a text component, at some interval. In addition, there are some other components that use solara.InputInt/solara.InputFloat/solara.InputText that the user can interact with.
However, if the user is in the middle of inputting a value (the cursor is located in the Input component) and the thread runs its work and updates its text component, the current value of the Input component is resetted. This makes it very hard to input values if the thread runs at, .e.g. once every second, as it will just reset the value the user tries to input.
I know that there is a parameter called "continuous_update=True" that will set the value of the Input component for every single character inputted, but the problem is that this, in turn, would trigger a huge amount of updates in other places of my application, which I would want to avoid (e.g. a text field might contain 50 characters, which would mean 50 updates).
I checked with @maartenbreddels in the Solara discord server, and he suggested that this is a bug, and that i can open an issue here. He even created a small working example of the problem in PyCafe here (thanks!): https://py.cafe/maartenbreddels/solara-rerender-input-bug
If you try to input an integer into the first IntInput, your progress will be lost every second, so you need to be very quick when inputting the value. There are also some debug prints to show when a component is updated, and it actually seems like the input components are not updated when the thread is running, but even still the progress seems to be lost? I don't understand that.
This problem (so far) only occurs with solara iunput components, and other types of components behave as expected.
Python: 3.11.7
Solara: 1.39.0
Created