Skip to content

Commit ffc776a

Browse files
committed
fix: Track editor and bind actions properly
1 parent ec3bf63 commit ffc776a

File tree

1 file changed

+10
-10
lines changed
  • src/features/instance/applications/components/TextEditorView

1 file changed

+10
-10
lines changed

src/features/instance/applications/components/TextEditorView/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { curryEmitToListeners, useListener } from '@/lib/events/listener';
77
import { currySetWatchedValue } from '@/lib/events/watcher';
88
import { parseFileExtension } from '@/lib/string/parseFileExtension';
99
import { Editor, EditorProps, OnMount } from '@monaco-editor/react';
10-
import { useCallback, useEffect, useRef, useState } from 'react';
10+
import { useCallback, useEffect, useState } from 'react';
1111
import './directory-read-me.css';
1212

1313
const extensionToLanguageMap: Record<string, string> = {
@@ -35,7 +35,7 @@ export function TextEditorView() {
3535
}, []);
3636

3737
const canManageBrowseInstance = useInstanceBrowseManagePermission();
38-
const mountedRef = useRef<Parameters<OnMount> | null>(null);
38+
const [mounted, setMounted] = useState<Parameters<OnMount> | null>(null);
3939
const [language, setLanguage] = useState('javascript');
4040

4141
useEffect(() => {
@@ -45,14 +45,14 @@ export function TextEditorView() {
4545
}, [openedEntry]);
4646

4747
const handleEditorDidMount: EditorProps['onMount'] = useCallback<OnMount>((editor, monaco) => {
48-
mountedRef.current = [editor, monaco];
49-
}, [mountedRef]);
48+
setMounted([editor, monaco]);
49+
}, []);
5050

5151
useEffect(() => {
52-
if (!mountedRef.current || !canManageBrowseInstance || !!openedEntry?.package || restrictPackageModification) {
52+
if (!mounted || !canManageBrowseInstance || !!openedEntry?.package || restrictPackageModification) {
5353
return;
5454
}
55-
const [editor, monaco] = mountedRef.current;
55+
const [editor, monaco] = mounted;
5656
const disposables = [
5757
editor.addAction({
5858
id: 'new-file',
@@ -94,7 +94,7 @@ export function TextEditorView() {
9494
disposable?.dispose();
9595
}
9696
};
97-
}, [mountedRef, canManageBrowseInstance, openedEntry, restrictPackageModification]);
97+
}, [mounted, canManageBrowseInstance, openedEntry, restrictPackageModification]);
9898

9999
useListener(
100100
'SaveFile',
@@ -117,13 +117,13 @@ export function TextEditorView() {
117117
useListener(
118118
'RevertChanges',
119119
() => {
120-
if (openedEntryContents !== undefined && mountedRef.current) {
121-
const [editor] = mountedRef.current;
120+
if (openedEntryContents !== undefined && mounted) {
121+
const [editor] = mounted;
122122
setUpdatedFileContent(undefined);
123123
editor.setValue(openedEntryContents);
124124
}
125125
},
126-
[openedEntryContents, mountedRef],
126+
[openedEntryContents, mounted],
127127
);
128128

129129
if (!openedEntry) {

0 commit comments

Comments
 (0)