From 73bdef41f93ad9ea0ec10d8dadb6daa2ebaaa8d4 Mon Sep 17 00:00:00 2001 From: Narutama Aurum Date: Wed, 10 Jun 2026 03:49:58 +0800 Subject: [PATCH] fix: memoize updateEditorLanguage and fix useEffect dependency --- modules/playground/components/playground-editor.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/playground/components/playground-editor.tsx b/modules/playground/components/playground-editor.tsx index 1434060a..6d4735b5 100644 --- a/modules/playground/components/playground-editor.tsx +++ b/modules/playground/components/playground-editor.tsx @@ -1,7 +1,7 @@ "use client"; import { EDITOR_CONFIG } from "@/lib/constants/config"; -import { useRef, useEffect, useState } from "react"; +import { useRef, useEffect, useState, useCallback } from "react"; import Editor, { type Monaco } from "@monaco-editor/react"; import type { editor as MonacoEditor } from "monaco-editor"; import { @@ -253,7 +253,7 @@ const PlaygroundEditor = ({ ); }; - const updateEditorLanguage = () => { + const updateEditorLanguage = useCallback(() => { if (!activeFile || !monacoRef.current || !editorRef.current) return; const model = editorRef.current.getModel(); if (!model) return; @@ -264,12 +264,11 @@ const PlaygroundEditor = ({ } catch (error) { console.warn("Failed to set editor language:", error); } - }; + }, [activeFile]); useEffect(() => { updateEditorLanguage(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [activeFile]); + }, [updateEditorLanguage]); // Bind Yjs to Monaco useEffect(() => {