Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { CodeView, DEFAULT_THEMES, parsePatchFiles, preloadHighlighter } from "@pierre/diffs";
import { expect, it, vi } from "vite-plus/test";

const OLD_LINES = Array.from({ length: 60 }, (_, index) => `line ${index + 1}`);
const NEW_LINES = OLD_LINES.with(0, "changed 1").with(59, "changed 60");
const PATCH = `diff --git a/notes.txt b/notes.txt
--- a/notes.txt
+++ b/notes.txt
@@ -1,4 +1,4 @@
-line 1
+changed 1
line 2
line 3
line 4
@@ -57,4 +57,4 @@
line 57
line 58
line 59
-line 60
+changed 60
`;

function parsePartialDiff() {
return parsePatchFiles(PATCH, { cacheKeyPrefix: "notes" })[0]!.files[0]!;
}

// A diff refresh re-parses an unchanged patch into a new object with the same cacheKey.
// Upstream keeps rendering the old object and then discards the file contents loaded for it.
it("expands hidden context after the host re-supplies an unchanged partial diff", async () => {
await preloadHighlighter({ themes: Object.values(DEFAULT_THEMES), langs: ["text"] });
const root = document.createElement("div");
root.style.cssText = "width: 800px; height: 600px; overflow: auto;";
document.body.append(root);
const view = new CodeView<undefined>({
diffStyle: "unified",
loadDiffFiles: async () => ({
oldFile: { name: "notes.txt", contents: `${OLD_LINES.join("\n")}\n` },
newFile: { name: "notes.txt", contents: `${NEW_LINES.join("\n")}\n` },
}),
});
using _view = {
[Symbol.dispose]: () => {
view.cleanUp();
root.remove();
},
};
view.setup(root);
const shadowRoot = () => root.querySelector("diffs-container")?.shadowRoot;
const lines = () =>
Array.from(shadowRoot()?.querySelectorAll("[data-line]") ?? [], (line) => line.textContent);

view.setItems([{ id: "notes", type: "diff", fileDiff: parsePartialDiff(), version: 1 }]);
await vi.waitFor(() => expect(lines()).toContain("line 57"));
view.setItems([{ id: "notes", type: "diff", fileDiff: parsePartialDiff(), version: 2 }]);

shadowRoot()!.querySelector<HTMLElement>("[data-expand-button]")!.click();

await vi.waitFor(() => expect(lines()).toContain("line 30"));
});
16 changes: 13 additions & 3 deletions patches/@pierre__diffs@1.7.0-beta.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,20 @@ index 734ff9862cdfe65b8082599c6c221c4886436e01..f18798a3d56dd0749550b5aff62a06fb
} catch (error) {
if (disableErrorHandling) throw error;
diff --git a/dist/components/VirtualizedFileDiff.js b/dist/components/VirtualizedFileDiff.js
index 984f049ff3694dd353fa6637b0f09fc7dce74992..8f659c06b70ba603f725cccdcaebe89c21b00f6b 100644
index 984f049ff3694dd353fa6637b0f09fc7dce74992..4d6599905be0fe7b5b5c1a225c0b3ff8d810c72a 100644
--- a/dist/components/VirtualizedFileDiff.js
+++ b/dist/components/VirtualizedFileDiff.js
@@ -626,7 +626,7 @@ var VirtualizedFileDiff = class extends FileDiff {
@@ -264,7 +264,8 @@ var VirtualizedFileDiff = class extends FileDiff {
const { pendingExpansions, pendingHydratedDiff, options: { collapsed = false } } = this;
if (pendingHydratedDiff != null) {
this.pendingHydratedDiff = void 0;
- if (pendingHydratedDiff.expectedDiff === fileDiff) {
+ // T3 patch: a host may re-supply an unchanged diff as a new object; it is still this diff.
+ if (areDiffTargetsEqual(pendingHydratedDiff.expectedDiff, fileDiff)) {
Object.assign(fileDiff, pendingHydratedDiff.nextDiff);
this.setHydratedState(pendingHydratedDiff.files);
this.installHydratedDiff(fileDiff);
@@ -626,7 +627,7 @@ var VirtualizedFileDiff = class extends FileDiff {
rerender() {
if (!this.enabled || this.getInputDiff() == null && this.additionFile == null && this.deletionFile == null) return;
const workingDiff = this.getWorkingDiff();
Expand All @@ -230,7 +240,7 @@ index 984f049ff3694dd353fa6637b0f09fc7dce74992..8f659c06b70ba603f725cccdcaebe89c
if (this.isSimpleMode()) this.pendingRender = void 0;
this.forceRenderOverride = true;
if (this.isSimpleMode() && this.requestRender()) return;
@@ -790,7 +790,7 @@ var VirtualizedFileDiff = class extends FileDiff {
@@ -790,7 +791,7 @@ var VirtualizedFileDiff = class extends FileDiff {
const previousRenderedDiff = this.getRenderedDiff();
const { pendingRender } = this;
const previousLayoutDiff = pendingRender?.diff ?? previousRenderedDiff;
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading