fix(app): guard against non-array diffs in session review#19250
fix(app): guard against non-array diffs in session review#19250jackblackbla wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #19221: Why it's related: This PR appears to address the exact same issue - preventing |
The SessionReview component crashes with `TypeError: e.diffs.map is not a function` when `props.diffs` is not an array. This can happen when the `session.diff` SSE event delivers malformed properties that bypass the unsafe `as` cast in the event reducer, causing `reconcile` to store a non-array value. - Add `Array.isArray` guard in event-reducer before passing to reconcile - Add `safeDiffs()` accessor in session-review.tsx to normalize props - Add tests for undefined and non-array diff payloads Fixes the common `e.diffs.map is not a function` crash reported by multiple users in the session review UI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a77e44c to
16f5bc2
Compare
|
Closing as duplicate of #19221 which covers the same fix with broader scope. Arrived at the same root cause independently — the unsafe cast + reconcile path in event-reducer.ts. |
Summary
Array.isArrayguard in event-reducer before passing diff data toreconcile(), preventing non-array values from being stored insession_diffsafeDiffs()accessor inSessionReviewcomponent to normalizeprops.diffs, preventing.map()crash on non-array valuessession.diffevent handling: normal array,undefined, and non-array object payloadsProblem
Users are seeing a common crash in the session review UI:
The root cause is in
event-reducer.tswheresession.diffevent properties are cast withas { sessionID: string; diff: FileDiff[] }— an unsafe cast with no runtime validation. If the SSE event delivers malformeddiffdata (e.g.,undefinedor an object instead of an array),reconcile()stores a non-array value in thesession_diffstore. The?? []fallback in the memo doesn't catch truthy non-array values like{}, so theSessionReviewcomponent crashes when calling.map()on it.Test plan
session.diffevent edge cases (undefined, non-array)🤖 Generated with Claude Code