enhancement
major
minor
defect
critical
major
minor
major
#30043
TL Views: a value the server sets while the React rich-text editor has the focus is never applied; the composer keeps its text after sending
Problem
TLWysiwygEditor.tsx (com.top_logic.layout.react.wysiwyg) applies a value change from the server only while the editor is not focused:
React.useEffect(() => {
currentHtmlRef.current = value;
if (editor && !editor.isDestroyed && !editor.isFocused) {
... editor.commands.setContent(value, { emitUpdate: false });
}
...
}, [value, editor]);
If the server sets a new value while the editor holds the focus, it is skipped. Nothing applies it later: the effect runs again only on the next change of value, and blurring the editor does not catch up. The editor keeps showing the old text, and the next keystroke sends that old text back as the user's input.
Seen in the TL Development app on snapshot build 59 with the comment composer, a rich-text <value-input> over a channel. "Add comment" stores the comment and clears the channel. The server sends the empty value (visible in the SSE state), and the editor still shows the sent text. The file chips and the "cited" field of the same composer clear as expected.
Expected
A value the server sets is shown by the editor. If the editor has the focus and the user has typed nothing since the value they last sent, the new value replaces the content at once. Otherwise the conflict is resolved deliberately, for example the server value wins and the caret is kept where possible. A value is never dropped silently.
Test
A rich-text <value-input> and a command that clears its channel, run by a keyboard shortcut or a button that does not take the focus, while the editor is focused: the editor is empty afterwards.
Lösung
- Der Editor merkt sich den zuletzt gesendeten Text. Ein Serverwert gleich diesem Text ist das Echo der eigenen Eingabe und wird ignoriert (sonst ginge inzwischen Getipptes verloren). Ein anderer Serverwert wird ohne ungesendete Eingabe sofort übernommen, auch mit Fokus; mit ungesendeter Eingabe gewinnt der Serverwert, das ausstehende Senden entfällt. Der Cursor bleibt, soweit möglich, an seiner Stelle. Dasselbe gilt für die HTML-Quelltextansicht.
- Der Editor meldet seinen ausstehenden (entprellten) Text beim Befehlskanal an wie die anderen Eingabefelder (registerPendingFlush): Ein Aktionsbefehl, z.B. "Kommentar hinzufügen" per Tastenkürzel, sendet zuerst den getippten Text.
- Andere unkontrollierte Editoren mit derselben Fokusprüfung (z.B. der Code-Editor) erhalten dieselbe Regel über eine gemeinsame Hilfsfunktion in tl-react-bridge.