Memoize compactAdvancedJson and update deps

Wrap compactAdvancedJson in useCallback (dependent on messageApi) and add it to the dependency array of applyAdvancedJsonToBasic. This ensures a stable function reference for correct dependency tracking and avoids stale closures/unnecessary re-renders in InboundFormModal.tsx.
This commit is contained in:
MHSanaei 2026-05-22 03:49:05 +02:00
parent 489a199fd4
commit cb45febdc2
No known key found for this signature in database
GPG key ID: 7E4060F2FBE5AB7A

View file

@ -659,14 +659,14 @@ export default function InboundFormModal({
} }
}, [messageApi]); }, [messageApi]);
const compactAdvancedJson = (raw: string, fallback: string, label: string) => { const compactAdvancedJson = useCallback((raw: string, fallback: string, label: string) => {
try { try {
return JSON.stringify(JSON.parse(raw || fallback)); return JSON.stringify(JSON.parse(raw || fallback));
} catch (e) { } catch (e) {
messageApi.error(`${label} JSON invalid: ${(e as Error).message}`); messageApi.error(`${label} JSON invalid: ${(e as Error).message}`);
throw e; throw e;
} }
}; }, [messageApi]);
const applyAdvancedJsonToBasic = useCallback((): boolean => { const applyAdvancedJsonToBasic = useCallback((): boolean => {
const ib = inboundRef.current; const ib = inboundRef.current;
@ -888,7 +888,7 @@ export default function InboundFormModal({
} finally { } finally {
setSaving(false); setSaving(false);
} }
}, [canEnableStream, t, mode, dbInbound, isFallbackHost, saveFallbacks, onSaved, onClose]); }, [canEnableStream, compactAdvancedJson, t, mode, dbInbound, isFallbackHost, saveFallbacks, onSaved, onClose]);
const protocolSnapshot = inboundRef.current?.protocol; const protocolSnapshot = inboundRef.current?.protocol;
const streamSnapshot = JSON.stringify(inboundRef.current?.stream?.toJson?.() || {}); const streamSnapshot = JSON.stringify(inboundRef.current?.stream?.toJson?.() || {});