fix(docs): place cursor after document content is loaded, not at WASM ready

This commit is contained in:
David Langley 2026-03-05 19:35:33 +00:00
parent 93f2a2af3c
commit d23a768a5f

View File

@ -480,11 +480,6 @@ export const DocumentView = memo(function DocumentView({ room }: DocumentViewPro
// LiveKit real-time transport (falls back gracefully if unavailable).
const rtc = useDocumentRTC(room, client);
// Place the cursor at the end and focus the editor once the WASM model is
// ready. Without this the editor is enabled but has no selection, so no
// cursor appears even after the element receives focus.
useSetCursorPosition(!isWysiwygReady, ref);
// Track whether the editor has content so we can hide the placeholder.
const [hasContent, setHasContent] = useState(false);
@ -503,6 +498,13 @@ export const DocumentView = memo(function DocumentView({ room }: DocumentViewPro
rtc,
);
// Place the cursor at the end and focus the editor only after BOTH the WASM
// model is ready AND the document content has been written to the DOM.
// Waiting for isLoaded prevents the cursor being placed into the empty editor
// before innerHTML is populated, which would leave it one position short on
// the first keypress.
useSetCursorPosition(!isWysiwygReady || !isLoaded, ref);
const handleInput = useCallback(() => {
notifyContentChangedRef.current();
scheduleDeltaSend();