As a user of a Panel application when attempting to type inside a CodeEditor widget, the full contents of the CodeEditor is randomly deleted. It doesn’t happen on every keystroke, but will happen intermittently and more frequently with bursts of keystrokes. Holding down a single key is the best way to reproduce. Example application to reproduce:
import panel as pn
pn.extension(
'codeeditor',
nthreads=0,
)
template = pn.template.FastListTemplate(title='Bug')
template.main.append(
pn.Row(
pn.Row(pn.widgets.CodeEditor(language='yaml', sizing_mode='stretch_both')),
)
)
server = pn.serve(
{
'bug': template,
},
port=8080,
show=True,
start=True,
websocket_origin=['localhost:8080', '127.0.0.1:8080'],
)
Save as bug.py
, and execute as python -m bug.py
If the nthreads=0
config option is removed or commented out, then CodeEditor works as expected (no issues). The presence of nthreads with any value (including 1) will cause this issue.
Based on the info in this article:
https://panel.holoviz.org/how_to/concurrency/threading.html
my understanding is that enabling automatic threading will allow the possibility that the order in which events are processed is non-deterministic. Given that CodeEditor appears to send an event for every keystroke (to update the model on the backend), it seems like processing keystrokes out of order would be problematic. How is this intended to work, and is there a workaround?
This issue sounds similar:
opened 03:25PM - 29 Feb 24 UTC
type: bug
#### ALL software version info
panel 1.3.8
bokeh 3.3.4
#### Description of … expected behavior and the observed behavior
When using the pn.widgets.TextInput widget either alone, as the widget for a param.String, or in the new chat interface I run into an issue where the some of the characters of the input text are lost when the user is typing quickly.
You can see the text very briefly then it'll look like it's rolled back to a split second before the latest character or two is entered. For example, you will be typing something like "hello world" and all characters will appear then a split second later it will show "hello worl" with the cursor now after the "l".
#### Complete, minimal, self-contained example code that reproduces the issue
Below is a simple example that appears to replicate the issue on my end, either served locally or on a hosted server. It maybe related to the nthreads parameter as it appears to at least be far less common when that parameter is None/no thread pool is created.
```
import panel as pn
pn.extension(
nthreads=0,
)
def dashboard_page():
return pn.widgets.TextInput(name="Enter text", placeholder="Type here...")
ROUTES = {
"Dashboard": dashboard_page,
}
pn.serve(ROUTES, port=8501, admin=True, static_dirs={"thumbnails": "./static/thumbnails"})
```
#### Stack traceback and/or browser JavaScript console output
N/A
#### Screenshots or screencasts of the bug in action
Difficult to capture in action, but seems to happen frequently enough when typing fast.
- [X] I may be interested in making a pull request to address this, but unsure where to start on this one.
Thanks! Can you also create a new GitHub issue?
I’d also like to see CodeEditor watch on value
instead of value_input
(per keystroke) like TextInput.
New issue is created here:
opened 03:54AM - 17 Apr 24 UTC
#### ALL software version info
python 3.11.9
panel 1.4.0
bokeh 3.4.0
Chrome … 123.0.6312.107 on Windows 11
#### Description of expected behavior and the observed behavior
The expected behavior is that I can run the application code below, type inside the CodeEditor widget, and the editor works as you'd expect for a typical text input field (e.g., holding down the 'x' key will continuously append additional 'x' characters while the key is held down).
Actual behavior is that holding down the 'x' key will add some 'x' characters, then delete the entire contents of the field so that it's empty, then start over appending 'x' characters. This repeats over and over, though the interval for text deletion is somewhat random. It also also happens intermittently with normal text input (not just holding down a key), but holding down a single key is the easiest/fastest way to reproduce.
If the `nthreads=0` config option is removed or commented out, then CodeEditor works as expected (no issues). The presence of nthreads with any value (including 1) will cause all existing text to be deleted periodically as new keystrokes occur (i.e., it acts as if the user performed Select All followed by Backspace).
#### Complete, minimal, self-contained example code that reproduces the issue
```
import panel as pn
pn.extension(
'codeeditor',
nthreads=0,
)
template = pn.template.FastListTemplate()
template.main.append(
pn.Row(pn.widgets.CodeEditor(language='yaml', sizing_mode='stretch_both')),
)
pn.serve(
{
'bug': template,
},
port=8080,
show=True,
start=True,
websocket_origin=['localhost:8080', '127.0.0.1:8080'],
)
```
Save as `bug.py`, and execute as `python -m bug.py`
Potentially related to this issue: https://github.com/holoviz/panel/issues/6414