Fix docs editor not loading content on first file click
Add editorReady state flag to resolve race condition where Y.js sync completes before Monaco editor mounts, causing the MonacoBinding effect to skip binding creation on the initial file selection. Bunker Admin
This commit is contained in:
parent
76b87d9f3d
commit
989f1dfa34
@ -623,6 +623,7 @@ export default function DocsPage() {
|
||||
const monacoEditorRef = useRef<monacoEditor.IStandaloneCodeEditor | null>(null);
|
||||
const monacoRef = useRef<typeof import('monaco-editor') | null>(null);
|
||||
const monacoBindingRef = useRef<MonacoBinding | null>(null);
|
||||
const [editorReady, setEditorReady] = useState(false);
|
||||
|
||||
// --- Collaboration state ---
|
||||
const [collabEnabled, setCollabEnabled] = useState(false);
|
||||
@ -803,6 +804,7 @@ export default function DocsPage() {
|
||||
const handleEditorMount: OnMount = useCallback((ed, monaco) => {
|
||||
monacoEditorRef.current = ed;
|
||||
monacoRef.current = monaco;
|
||||
setEditorReady(true);
|
||||
|
||||
// Register keyboard shortcuts only (no context menu items — we use a custom menu)
|
||||
SNIPPETS.filter(s => s.keybinding).forEach(snippet => {
|
||||
@ -856,7 +858,7 @@ export default function DocsPage() {
|
||||
binding.destroy();
|
||||
monacoBindingRef.current = null;
|
||||
};
|
||||
}, [collab.active, collab.yText, collab.provider, selectedFile]);
|
||||
}, [collab.active, collab.yText, collab.provider, selectedFile, editorReady]);
|
||||
|
||||
// Auto-refresh preview when remote changes arrive in collab mode
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user