fix: info page editor — locale switch no longer resets user edits

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.
This commit is contained in:
Fringg
2026-04-24 08:22:16 +03:00
parent 7d6d0ba344
commit 3ef54adb3e

View File

@@ -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] ?? '');
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]);
}, [pageData, editor]); // activeLocale intentionally omitted
// Auto-generate slug from Russian title
useEffect(() => {