From 3e587865e063a382fb7410974d302ff8f9a62633 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Fri, 11 Jul 2025 10:55:51 +0200 Subject: [PATCH 1/2] refactor: replace useEffect with useMount for initialization in VariablesEditor --- src/modules/EditorView/VariablesEditor.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/EditorView/VariablesEditor.tsx b/src/modules/EditorView/VariablesEditor.tsx index 144b7135..b5881888 100644 --- a/src/modules/EditorView/VariablesEditor.tsx +++ b/src/modules/EditorView/VariablesEditor.tsx @@ -29,6 +29,7 @@ import { drawSelection, dropCursor, EditorView, highlightSpecialChars, keymap, l import { dracula, tomorrow } from "@mjfwebb/thememirror"; import { Button } from "@neo4j-ndl/react"; import classNames from "classnames"; +import { useMount } from "react-use"; import type { Extension } from "../../components/Filename"; import { FileName } from "../../components/Filename"; @@ -106,7 +107,7 @@ export const VariablesEditor = ({ id, loading, fileExtension, fileName, borderRa [formatTheCode, theme.theme, updateListener] ); - useEffect(() => { + useMount(() => { if (elementRef.current === null) { return; } @@ -123,7 +124,7 @@ export const VariablesEditor = ({ id, loading, fileExtension, fileName, borderRa view.destroy(); setEditorView(null); }; - }, [value]); + }); useEffect(() => { if (editorView) { From 0096a1d13dba9746545e2f73769b4e66ca6e85ba Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Fri, 11 Jul 2025 14:53:43 +0200 Subject: [PATCH 2/2] test: add tests for VariablesEditor --- src/modules/EditorView/VariablesEditor.tsx | 1 + tests/pages/Editor.ts | 23 ++++++++ tests/queryeditortabs.test.ts | 22 +++++++ tests/variableseditor.test.ts | 69 ++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 tests/variableseditor.test.ts diff --git a/src/modules/EditorView/VariablesEditor.tsx b/src/modules/EditorView/VariablesEditor.tsx index b5881888..a79f95be 100644 --- a/src/modules/EditorView/VariablesEditor.tsx +++ b/src/modules/EditorView/VariablesEditor.tsx @@ -164,6 +164,7 @@ export const VariablesEditor = ({ id, loading, fileExtension, fileName, borderRa rightButtons={