diff --git a/packages/plugins/plugin-workspace-diff/src/ui/index.tsx b/packages/plugins/plugin-workspace-diff/src/ui/index.tsx index ddcda75319a..cf7ca1e9c12 100644 --- a/packages/plugins/plugin-workspace-diff/src/ui/index.tsx +++ b/packages/plugins/plugin-workspace-diff/src/ui/index.tsx @@ -1,8 +1,10 @@ import type { PluginDetailTabProps } from "@paperclipai/plugin-sdk/ui"; import { usePluginData, usePluginToast } from "@paperclipai/plugin-sdk/ui"; import type { WorkspaceDiffResponse } from "@paperclipai/plugin-sdk"; -import { PatchDiff } from "@pierre/diffs/react"; -import { useEffect, useMemo, useState } from "react"; +import { DIFFS_TAG_NAME, getSingularPatch } from "@pierre/diffs"; +import type { PatchDiffProps } from "@pierre/diffs/react"; +import { useFileDiffInstance } from "@pierre/diffs/react"; +import { createElement, useEffect, useMemo, useState } from "react"; import { diffSummary, fileName, @@ -15,6 +17,7 @@ import { } from "../diff-model.js"; type WorkspaceDiffData = WorkspaceDiffResponse; +type WorkspacePatchDiffOptions = PatchDiffProps["options"]; function buttonClass(active = false) { return [ @@ -117,14 +120,39 @@ function FileRow({
{statusLabel(file.status)} - +{file.additions} - -{file.deletions} + {`+${file.additions}`} + {`-${file.deletions}`} {warning ? {warning} : null}
); } +// The upstream React wrapper emits React 19 key warnings for its internal slot array. +// This mounts the same Diffs custom element through the exported imperative hook. +function WorkspacePatchDiff({ + patch, + options, +}: { + patch: string; + options: WorkspacePatchDiffOptions; +}) { + const fileDiff = useMemo(() => getSingularPatch(patch), [patch]); + const { ref } = useFileDiffInstance({ + fileDiff, + options, + metrics: undefined, + lineAnnotations: undefined, + selectedLines: undefined, + prerenderedHTML: undefined, + hasGutterRenderUtility: false, + hasCustomHeader: false, + disableWorkerPool: false, + }); + + return createElement(DIFFS_TAG_NAME, { ref }); +} + function EmptyState() { return (
@@ -177,8 +205,8 @@ function FileDiffPanel({ {file.patches.length > 1 ? (
{patchKindLabel(patch.kind)} - +{patch.additions} - -{patch.deletions} + {`+${patch.additions}`} + {`-${patch.deletions}`}
) : null} {patchWarning || !patch.patch ? ( @@ -186,7 +214,7 @@ function FileDiffPanel({ {patchWarning ?? "No renderable patch is available for this file."}
) : ( -
- {files.map((file) => ( - expandedFiles.has(file.path) ? ( + {files + .filter((file) => expandedFiles.has(file.path)) + .map((file) => (
- ) : null - ))} + ))}
)}