From f6a4df1b087963ea48a939ed2d94c04cfeb0d5a4 Mon Sep 17 00:00:00 2001 From: claude_code Date: Mon, 22 Jun 2026 19:20:46 +0300 Subject: [PATCH] fix(editor): stop title input losing characters while typing The fork's server-authoritative WS redesign rebroadcasts PAGE_UPDATED (updateOne) title changes to the whole space room including the author. The author's own client applied that echo to the ["pages", slugId] cache, which feeds the title prop; the setContent effect then overwrote the in-progress title with the lagging echo, dropping just-typed characters and jumping the cursor. Guard the setContent effect so it skips while the title editor is focused (and when destroyed): external/echo title updates are applied only when the field is not being actively edited. Page navigation is unaffected because TitleEditor remounts per page (key={page.id}) and seeds content at creation. --- apps/client/src/features/editor/title-editor.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/client/src/features/editor/title-editor.tsx b/apps/client/src/features/editor/title-editor.tsx index fefe9f33..0b1fb924 100644 --- a/apps/client/src/features/editor/title-editor.tsx +++ b/apps/client/src/features/editor/title-editor.tsx @@ -152,7 +152,17 @@ export function TitleEditor({ const debounceUpdate = useDebouncedCallback(saveTitle, 500); useEffect(() => { - if (titleEditor && title !== titleEditor.getText()) { + // Do not overwrite the title while the user is actively editing it. The + // server rebroadcasts PAGE_UPDATED to the author too, and that echo can + // carry a title that lags behind what the user has just typed; resetting + // content from it here would drop in-progress characters and jump the + // cursor. Apply external title changes only when the field is not focused. + if ( + titleEditor && + !titleEditor.isDestroyed && + !titleEditor.isFocused && + title !== titleEditor.getText() + ) { titleEditor.commands.setContent(title); } }, [pageId, title, titleEditor]);