Skip to content

fix: add defensive checks for undefined values in diff handling#19261

Open
dongjiang1989 wants to merge 5 commits intoanomalyco:devfrom
dongjiang1989:fix-replaceAll
Open

fix: add defensive checks for undefined values in diff handling#19261
dongjiang1989 wants to merge 5 commits intoanomalyco:devfrom
dongjiang1989:fix-replaceAll

Conversation

@dongjiang1989
Copy link
Copy Markdown

@dongjiang1989 dongjiang1989 commented Mar 26, 2026

Summary

  • Add nullish checks for diffs array to prevent TypeError: e.diffs.map is not a function
  • Add nullish checks for path/directory parameters before replaceAll to prevent TypeError: Cannot read properties of undefined (reading 'replaceAll')
  • Add Array.isArray validation for session_diff data from API
  • Add defensive checks for vcs.diff.git and vcs.diff.branch

Issue for this PR

Closes #19241
Closes #19222
Closes #19240
Closes #19217

Type of change

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

What does this PR do?

Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.

  • session-side-panel.tsx - Handle undefined/null diffs in diffFiles and kinds memos
  • review-tab.tsx - Handle undefined diffs in effect and render
  • session.tsx - Validate session_diff is array before use
  • file-tree.tsx - Add null check for path parameter
  • dialog-select-directory.tsx - Add null check for input
  • layout/helpers.ts - Add null check for directory parameter

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

  • bun typecheck passes across all 13 packages
  • Check in opencode web model

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

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

Why it's related: This PR appears to address the same core issue - adding defensive checks to prevent crashes when diffs are undefined or not arrays. PR #19221 specifically uses Array.isArray() to guard diffs before calling .map(), which aligns with the fixes mentioned in PR #19261.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Dredok added a commit to Dredok/opencode that referenced this pull request Mar 26, 2026
Prevents 'e.diffs.map is not a function' crash when session_diff
data from the server is undefined or not an array. Guards added at:
- event-reducer (incoming data validation)
- session.tsx (diffs and turnDiffs memos)
- session-side-panel.tsx (diffs memo)

Ref: upstream issues anomalyco#19217, anomalyco#19262, PR anomalyco#19261
- Add nullish checks for diffs array to prevent 'map is not a function' error
- Add nullish checks for path/directory parameters before replaceAll
- Add Array.isArray validation for session_diff data
- Add defensive checks for vcs.diff.git and vcs.diff.branch

Fixes: anomalyco#19241, anomalyco#19222, anomalyco#19240, anomalyco#19217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants