Skip to content

Commit 1cb5f9f

Browse files
committed
fix(web): make diffs optional in UserMessage summary to prevent TypeError
The web UI was crashing with 'TypeError: e.diffs.map is not a function' when accessing sessions without diffs data. This was caused by: 1. The backend Zod schema marking diffs as required in UserMessage.summary 2. The frontend calling .map() on potentially undefined diffs Changes: - Make diffs optional in message-v2.ts User schema (adds .optional()) - Regenerate TypeScript SDK to reflect the optional type - Add defensive null-coalescing (props.diffs ?? []) in session-review.tsx Fixes anomalyco#19270
1 parent 41c77cc commit 1cb5f9f

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎packages/opencode/src/session/message-v2.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export namespace MessageV2 {
358358
.object({
359359
title: z.string().optional(),
360360
body: z.string().optional(),
361-
diffs: Snapshot.FileDiff.array(),
361+
diffs: Snapshot.FileDiff.array().optional(),
362362
})
363363
.optional(),
364364
agent: z.string(),

‎packages/sdk/js/src/v2/gen/types.gen.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export type UserMessage = {
126126
summary?: {
127127
title?: string
128128
body?: string
129-
diffs: Array<FileDiff>
129+
diffs?: Array<FileDiff>
130130
}
131131
agent: string
132132
model: {

‎packages/ui/src/components/session-review.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export const SessionReview = (props: SessionReviewProps) => {
150150
const opened = () => store.opened
151151

152152
const open = () => props.open ?? store.open
153-
const files = createMemo(() => props.diffs.map((diff) => diff.file))
154-
const diffs = createMemo(() => new Map(props.diffs.map((diff) => [diff.file, diff] as const)))
153+
const files = createMemo(() => (props.diffs ?? []).map((diff) => diff.file))
154+
const diffs = createMemo(() => new Map((props.diffs ?? []).map((diff) => [diff.file, diff] as const)))
155155
const diffStyle = () => props.diffStyle ?? (props.split ? "split" : "unified")
156156
const hasDiffs = () => files().length > 0
157157

0 commit comments

Comments
 (0)