From a82ca860089afde16afdcb1cff0592c6ac0f4aa4 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Thu, 12 Feb 2026 10:00:37 -0600 Subject: [PATCH] fix(app): more defensive code component --- packages/ui/src/components/code.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/components/code.tsx b/packages/ui/src/components/code.tsx index 2fe0e0352..abe0d7ca9 100644 --- a/packages/ui/src/components/code.tsx +++ b/packages/ui/src/components/code.tsx @@ -562,9 +562,17 @@ export function Code(props: CodeProps) { } } + const text = () => { + const value = local.file.contents as unknown + if (typeof value === "string") return value + if (Array.isArray(value)) return value.join("\n") + if (value == null) return "" + return String(value) + } + const lineCount = () => { - const text = local.file.contents - const total = text.split("\n").length - (text.endsWith("\n") ? 1 : 0) + const value = text() + const total = value.split("\n").length - (value.endsWith("\n") ? 1 : 0) return Math.max(1, total) } @@ -848,8 +856,9 @@ export function Code(props: CodeProps) { observer = undefined container.innerHTML = "" + const value = text() file().render({ - file: local.file, + file: typeof local.file.contents === "string" ? local.file : { ...local.file, contents: value }, lineAnnotations: local.annotations, containerWrapper: container, })