From 3ef54adb3eb8b3e50629805ed7ef9b53b10f8976 Mon Sep 17 00:00:00 2001 From: Fringg Date: Fri, 24 Apr 2026 08:22:16 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20info=20page=20editor=20=E2=80=94=20local?= =?UTF-8?q?e=20switch=20no=20longer=20resets=20user=20edits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split the form population effect into two: 1. Form fields (slug, icon, active, titles, contents) — populated once when pageData loads, never re-run on locale switch 2. Editor content — set once when editor instance is ready Previously activeLocale was in the deps array, causing every tab switch to overwrite all in-memory edits with original server data. --- src/pages/AdminInfoPageEditor.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/pages/AdminInfoPageEditor.tsx b/src/pages/AdminInfoPageEditor.tsx index c4e7281..7be6149 100644 --- a/src/pages/AdminInfoPageEditor.tsx +++ b/src/pages/AdminInfoPageEditor.tsx @@ -411,10 +411,11 @@ export default function AdminInfoPageEditor() { refetchOnWindowFocus: false, }); - // Populate form when page data loads + // Populate form when page data loads (once only — not on locale switch) const editorPopulated = useRef(false); + const formPopulated = useRef(false); useEffect(() => { - if (!pageData) return; + if (!pageData || formPopulated.current) return; setSlug(pageData.slug); setSlugManuallyEdited(true); setIcon(pageData.icon ?? ''); @@ -422,11 +423,16 @@ export default function AdminInfoPageEditor() { setSortOrder(pageData.sort_order); setTitles(pageData.title); setContents(pageData.content); - if (editor && pageData.content[activeLocale] && !editorPopulated.current) { - editor.commands.setContent(pageData.content[activeLocale] ?? ''); - editorPopulated.current = true; - } - }, [pageData, editor, activeLocale]); + formPopulated.current = true; + }, [pageData]); + + // Set editor content once when editor is ready + useEffect(() => { + if (!pageData || !editor || editorPopulated.current) return; + const initialContent = pageData.content[activeLocale] ?? pageData.content['ru'] ?? ''; + editor.commands.setContent(initialContent); + editorPopulated.current = true; + }, [pageData, editor]); // activeLocale intentionally omitted // Auto-generate slug from Russian title useEffect(() => {