CodeEditor widget is unusable when automatic theading is enabled

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:

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: