fix: guard undefined contents in diff renderer to fix share viewer SSR crash#21763
Merged
Brendonovich merged 3 commits intoanomalyco:devfrom May 7, 2026
Merged
Conversation
…nderer When edit tool results lack filediff.before/after or input oldString/newString, contents was passed as undefined to parseDiffFromFile (via FileDiff.hydrate or preloadMultiFileDiff), causing a crash in createTwoFilesPatch → LineDiff.tokenize. - file-ssr.tsx: normalize before/after contents to "" in DiffSSRViewer.hydrate, matching the guard already present in file.tsx (lines 1056-1057) - message-part.tsx: default edit tool before/after contents to "" when both metadata filediff and input string fields are absent Fixes anomalyco#21694
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
leohenon
pushed a commit
to leohenon/opencode-vim
that referenced
this pull request
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #21694
Type of change
What does this PR do?
Certain shared sessions crash the share viewer with
Cannot read properties of undefined (reading 'split')in the@pierre/diffsdiff renderer. The crash happens becauseparseDiffFromFilecallscreateTwoFilesPatch(oldFile.name, newFile.name, oldFile.contents, newFile.contents, ...)— whencontentsisundefined,LineDiff.tokenizecrashes calling.split()on it.This occurs in two related places:
packages/ui/src/components/file-ssr.tsx—DiffSSRViewer.hydratewas passinglocal.before/local.afterdirectly toFileDiff.hydratewithout guardingcontents. Added the sametypeof x.contents === "string" ? x.contents : ""normalization already present infile.tsx(lines 1056–1057 and 1090–1091).packages/ui/src/components/message-part.tsx— Theedittool renderer constructsbefore/afterasprops.metadata?.filediff?.before || props.input.oldString. When both fields are absent (e.g. new-file creation, or edit results where metadata omits content),contentswasundefined. Added|| ""fallback so the diff renders the file as fully added/removed instead of crashing.An empty-string
contentsis the correct representation for "no prior content".How did you verify your code works?
bun turbo typecheck --filter=@opencode-ai/ui --filter=@opencode-ai/enterprise— both packages pass cleanly.FileDiff.jsin@pierre/diffsto confirm thatparseDiffFromFileis not called whencontentsis""(empty string is valid input tocreateTwoFilesPatch).file.tsxlines 1056–1057.Screenshots / recordings
No UI change — the fix prevents a crash rather than changing visible output.
Checklist