Skip to content

Commit 9f9e3cb

Browse files
committed
refactored code to solve build warning
1 parent 6ac1c56 commit 9f9e3cb

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/components/flow/CodeEditorModal.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ export function CodeEditorModal({
105105
// Derived: whether the editor has unsaved changes
106106
const hasUnsavedChanges = code !== savedCode;
107107

108+
const closeWebSocket = useCallback(() => {
109+
if (webSocketRef.current) {
110+
console.log('🧹 Component unmounting - closing WebSocket cleanly');
111+
if (
112+
webSocketRef.current.readyState === WebSocket.OPEN ||
113+
webSocketRef.current.readyState === WebSocket.CONNECTING
114+
) {
115+
webSocketRef.current.close(1000, 'Editor closed');
116+
}
117+
webSocketRef.current = null;
118+
}
119+
setLspReadyBoth(false);
120+
lspInitialized.current = false;
121+
setLspConnected(false);
122+
}, []);
123+
108124
useEffect(() => {
109125
setCode(initialCode);
110126
setSavedCode(initialCode);
@@ -129,14 +145,13 @@ export function CodeEditorModal({
129145
return () => {
130146
closeWebSocket();
131147
};
132-
}, []);
148+
}, [closeWebSocket]);
133149

134-
// Cleanup on browser close/refresh
135150
useEffect(() => {
136151
const handleBeforeUnload = () => closeWebSocket();
137152
window.addEventListener('beforeunload', handleBeforeUnload);
138153
return () => window.removeEventListener('beforeunload', handleBeforeUnload);
139-
}, []);
154+
}, [closeWebSocket]);
140155

141156
// ── Ctrl+S Shortcut ────────────────────────────────────────────────────────
142157
useEffect(() => {
@@ -152,22 +167,6 @@ export function CodeEditorModal({
152167
// eslint-disable-next-line react-hooks/exhaustive-deps
153168
}, [isOpen, code, saving]);
154169

155-
const closeWebSocket = () => {
156-
if (webSocketRef.current) {
157-
console.log('🧹 Component unmounting - closing WebSocket cleanly');
158-
if (
159-
webSocketRef.current.readyState === WebSocket.OPEN ||
160-
webSocketRef.current.readyState === WebSocket.CONNECTING
161-
) {
162-
webSocketRef.current.close(1000, 'Editor closed');
163-
}
164-
webSocketRef.current = null;
165-
}
166-
setLspReadyBoth(false);
167-
lspInitialized.current = false;
168-
setLspConnected(false);
169-
};
170-
171170
// Close with unsaved-changes guard
172171
const handleClose = useCallback(() => {
173172
if (hasUnsavedChanges) {

0 commit comments

Comments
 (0)