summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-12 10:00:37 -0600
committerAdam <[email protected]>2026-02-12 10:00:58 -0600
commita82ca860089afde16afdcb1cff0592c6ac0f4aa4 (patch)
treea2aecc1172a907e7fb311371484a4311e0a5e3bd
parented472d8a6789c882dfbba7facfd987fd8dd6fb2c (diff)
downloadopencode-a82ca860089afde16afdcb1cff0592c6ac0f4aa4.tar.gz
opencode-a82ca860089afde16afdcb1cff0592c6ac0f4aa4.zip
fix(app): more defensive code component
-rw-r--r--packages/ui/src/components/code.tsx15
1 files 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<T>(props: CodeProps<T>) {
}
}
+ 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<T>(props: CodeProps<T>) {
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,
})