Skip to content

The open-source app everyone uses to manage agents at work

fix(ui): prevent infinite re-render loop on agent configure page

Dotta69ba77f3340f
diff --git a/ui/src/components/AgentConfigForm.tsx b/ui/src/components/AgentConfigForm.tsx
index 391c3af856..3eb345ff93 100644
--- a/ui/src/components/AgentConfigForm.tsx
+++ b/ui/src/components/AgentConfigForm.tsx
@@ -85,6 +85,9 @@ const emptyOverlay: Overlay = {
runtime: {},
};
+/** Stable empty object used as fallback for missing env config to avoid new-object-per-render. */
+const EMPTY_ENV: Record<string, EnvBinding> = {};
+
function isOverlayDirty(o: Overlay): boolean {
return (
Object.keys(o.identity).length > 0 ||
@@ -617,8 +620,8 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
<EnvVarEditor
value={
isCreate
- ? ((val!.envBindings ?? {}) as Record<string, EnvBinding>)
- : ((eff("adapterConfig", "env", config.env ?? {}) as Record<string, EnvBinding>)
+ ? ((val!.envBindings ?? EMPTY_ENV) as Record<string, EnvBinding>)
+ : ((eff("adapterConfig", "env", (config.env ?? EMPTY_ENV) as Record<string, EnvBinding>))
)
}
secrets={availableSecrets}
diff --git a/ui/src/components/MarkdownEditor.tsx b/ui/src/components/MarkdownEditor.tsx
index d9ec6fe7bd..c68face2a7 100644
--- a/ui/src/components/MarkdownEditor.tsx
+++ b/ui/src/components/MarkdownEditor.tsx
@@ -208,6 +208,10 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
const [isDragOver, setIsDragOver] = useState(false);
const dragDepthRef = useRef(0);
+ // Stable ref for imageUploadHandler so plugins don't recreate on every render
+ const imageUploadHandlerRef = useRef(imageUploadHandler);
+ imageUploadHandlerRef.current = imageUploadHandler;
+
// Mention state (ref kept in sync so callbacks always see the latest value)
const [mentionState, setMentionState] = useState<MentionState | null>(null);
const mentionStateRef = useRef<MentionState | null>(null);
@@ -235,11 +239,17 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
},
}), []);
+ // Whether the image plugin should be included (boolean is stable across renders
+ // as long as the handler presence doesn't toggle)
+ const hasImageUpload = Boolean(imageUploadHandler);
+
const plugins = useMemo<RealmPlugin[]>(() => {
- const imageHandler = imageUploadHandler
+ const imageHandler = hasImageUpload
? async (file: File) => {
+ const handler = imageUploadHandlerRef.current;
+ if (!handler) throw new Error("No image upload handler");
try {
- const src = await imageUploadHandler(file);
+ const src = await handler(file);
setUploadError(null);
return src;
} catch (err) {
@@ -268,7 +278,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
all.push(imagePlugin({ imageUploadHandler: imageHandler }));
}
return all;
- }, [imageUploadHandler]);
+ }, [hasImageUpload]);
useEffect(() => {
if (value !== latestValueRef.current) {