fix: guard undefined contents in diff renderer to fix share viewer SSR crash (#21763)

This commit is contained in:
YGoetschel
2026-05-07 12:55:40 +02:00
committed by GitHub
parent 30c4fcb1a5
commit fea9a0bd4c
2 changed files with 8 additions and 4 deletions

View File

@@ -128,8 +128,12 @@ function DiffSSRViewer<T>(props: SSRDiffFileProps<T>) {
prerenderedHTML: local.preloadedDiff.prerenderedHTML,
}
: {
oldFile: local.before,
newFile: local.after,
oldFile: local.before
? { ...local.before, contents: typeof local.before.contents === "string" ? local.before.contents : "" }
: local.before,
newFile: local.after
? { ...local.after, contents: typeof local.after.contents === "string" ? local.after.contents : "" }
: local.after,
lineAnnotations: annotations,
fileContainer: fileDiffRef,
containerWrapper: container,

View File

@@ -1906,11 +1906,11 @@ ToolRegistry.register({
mode="diff"
before={{
name: props.metadata?.filediff?.file || props.input.filePath,
contents: props.metadata?.filediff?.before || props.input.oldString,
contents: props.metadata?.filediff?.before || props.input.oldString || "",
}}
after={{
name: props.metadata?.filediff?.file || props.input.filePath,
contents: props.metadata?.filediff?.after || props.input.newString,
contents: props.metadata?.filediff?.after || props.input.newString || "",
}}
/>
</div>