Skip to content

fix(app): guard diffs with Array.isArray to prevent .map crash#19221

Closed
ysm-dev wants to merge 2 commits intoanomalyco:devfrom
ysm-dev:opencode/kind-wizard
Closed

fix(app): guard diffs with Array.isArray to prevent .map crash#19221
ysm-dev wants to merge 2 commits intoanomalyco:devfrom
ysm-dev:opencode/kind-wizard

Conversation

@ysm-dev
Copy link
Copy Markdown
Contributor

@ysm-dev ysm-dev commented Mar 26, 2026

Issue for this PR

Closes #19217

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

props.diffs.map in SessionReview crashes when diffs is not an array. This happens when reopening old browser sessions because the SSE event reducer passes event.properties.diff directly to reconcile() without validating it's an array. If the data is malformed or missing, reconcile(undefined, { key: "file" }) can corrupt the store value into a non-array. The existing ?? [] fallback only catches null/undefined — a truthy non-array (like {}) passes through.

The fix adds Array.isArray guards at four points:

  1. event-reducer.ts — validate props.diff before reconcile() (root cause fix, matches the pattern already used in sync.tsx)
  2. session.tsx — guard session_diff[id] read with Array.isArray instead of ?? []
  3. session.tsx — guard summary.diffs read with Array.isArray instead of ?? []
  4. session-review.tsx — guard props.diffs access in the UI component as last-resort defense

How did you verify your code works?

  • bun typecheck passes across all 13 packages
  • Traced the full data flow from backend SSE events through reconcile() to the SessionReview component to confirm all paths now guarantee an array

Screenshots / recordings

N/A — no UI changes, this is a runtime crash fix.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@ysm-dev
Copy link
Copy Markdown
Contributor Author

ysm-dev commented Mar 26, 2026

The e2e (windows) failure is a pre-existing flake unrelated to this PR. The same tests fail on every other open PR right now (openai-websocket, fix-direct-route-sidebar-project-18943, gpt-5.4-prompt). All other checks pass (typecheck, unit tests, e2e linux, storybook, nix-eval).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: e.diffs.map is not a function when reopening old browser session

1 participant