Просмотр исходного кода

Fix(app): @pierre/diffs will crash when a diff has undefined text (#7059)

Eric Guo 1 месяц назад
Родитель
Сommit
4ecb305820
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      packages/ui/src/components/diff.tsx

+ 6 - 2
packages/ui/src/components/diff.tsx

@@ -19,6 +19,8 @@ export function Diff<T>(props: DiffProps<T>) {
     const opts = options()
     const workerPool = getWorkerPool(props.diffStyle)
     const annotations = local.annotations
+    const beforeContents = typeof local.before?.contents === "string" ? local.before.contents : ""
+    const afterContents = typeof local.after?.contents === "string" ? local.after.contents : ""
 
     instance?.cleanUp()
     instance = new FileDiff<T>(opts, workerPool)
@@ -27,11 +29,13 @@ export function Diff<T>(props: DiffProps<T>) {
     instance.render({
       oldFile: {
         ...local.before,
-        cacheKey: checksum(local.before.contents),
+        contents: beforeContents,
+        cacheKey: checksum(beforeContents),
       },
       newFile: {
         ...local.after,
-        cacheKey: checksum(local.after.contents),
+        contents: afterContents,
+        cacheKey: checksum(afterContents),
       },
       lineAnnotations: annotations,
       containerWrapper: container,