From 99f91281ea3289ac58250511c1649d938719df3d Mon Sep 17 00:00:00 2001 From: Filip Brebera Date: Thu, 8 Jan 2026 14:50:14 +0100 Subject: [PATCH 1/3] fix: sidebar state on morph-apply --- app/page.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 05817e6d..4790be8a 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -79,10 +79,8 @@ export default function Home() { : { [selectedTemplate]: templates[selectedTemplate] } const lastMessage = messages[messages.length - 1] - // Determine which API to use based on morph toggle and existing fragment - const shouldUseMorph = - useMorphApply && fragment && fragment.code && fragment.file_path - const apiEndpoint = shouldUseMorph ? '/api/morph-chat' : '/api/chat' + // Determine which API to use based on morph toggle + const apiEndpoint = useMorphApply ? '/api/morph-chat' : '/api/chat' const { object, submit, isLoading, stop, error } = useObject({ api: apiEndpoint, @@ -200,7 +198,7 @@ export default function Home() { template: currentTemplate, model: currentModel, config: languageModel, - ...(shouldUseMorph && fragment ? { currentFragment: fragment } : {}), + ...(useMorphApply && fragment?.code ? { currentFragment: fragment } : {}), }) setChatInput('') @@ -221,7 +219,7 @@ export default function Home() { template: currentTemplate, model: currentModel, config: languageModel, - ...(shouldUseMorph && fragment ? { currentFragment: fragment } : {}), + ...(useMorphApply && fragment?.code ? { currentFragment: fragment } : {}), }) } From 1d0a45c339e5ee8b4b8d4c2b4707c0f4b5d3ab6e Mon Sep 17 00:00:00 2001 From: Filip Brebera Date: Fri, 9 Jan 2026 00:43:12 +0100 Subject: [PATCH 2/3] fix: message re-rendering when changing settings --- app/page.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 4790be8a..47265501 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -126,7 +126,8 @@ export default function Home() { }) useEffect(() => { - if (object) { + // Only update messages during active streaming, not when toggling settings + if (object && isLoading) { setFragment(object) const content: Message['content'] = [ { type: 'text', text: object.commentary || '' }, @@ -148,7 +149,7 @@ export default function Home() { }) } } - }, [object]) + }, [object, isLoading]) useEffect(() => { if (error) stop() From 3855517b7959297eb58c1261056b6d717104a826 Mon Sep 17 00:00:00 2001 From: Filip Date: Mon, 12 Jan 2026 17:48:42 +0100 Subject: [PATCH 3/3] fix: morph error when fragment is missing --- app/api/morph-chat/route.ts | 8 ++++++++ app/page.tsx | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/api/morph-chat/route.ts b/app/api/morph-chat/route.ts index 83f97f11..c2042ebb 100644 --- a/app/api/morph-chat/route.ts +++ b/app/api/morph-chat/route.ts @@ -30,6 +30,14 @@ export async function POST(req: Request) { currentFragment: FragmentSchema } = await req.json() + // Validate that currentFragment exists (required for morph edits) + if (!currentFragment?.file_path || !currentFragment?.code) { + return new Response( + JSON.stringify({ error: 'currentFragment with file_path and code is required for morph edits' }), + { status: 400, headers: { 'Content-Type': 'application/json' } } + ) + } + // Rate limiting (same as chat route) const limit = !config.apiKey ? await ratelimit( diff --git a/app/page.tsx b/app/page.tsx index 47265501..261f6be5 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -79,8 +79,8 @@ export default function Home() { : { [selectedTemplate]: templates[selectedTemplate] } const lastMessage = messages[messages.length - 1] - // Determine which API to use based on morph toggle - const apiEndpoint = useMorphApply ? '/api/morph-chat' : '/api/chat' + // Determine which API to use based on morph toggle AND whether we have a fragment to edit + const apiEndpoint = useMorphApply && fragment?.code ? '/api/morph-chat' : '/api/chat' const { object, submit, isLoading, stop, error } = useObject({ api: apiEndpoint,