Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(revisions): diff long notes without overflowing the stack
Elian Doran340997456475
diff --git a/apps/client/src/services/html_diff.spec.ts b/apps/client/src/services/html_diff.spec.tsindex 52f5371df4..362f9cb6ad 100644--- a/apps/client/src/services/html_diff.spec.ts+++ b/apps/client/src/services/html_diff.spec.ts@@ -73,4 +73,10 @@ describe("diffHtml", () => {expect(diffHtml("<p>foo <strong>bar</strong></p>", "<p>foo bar</p>")).toBe("<p>foo bar</p>");});++ it("diffs a long note with a short edit", () => {+ const words = Array.from({ length: 100_000 }, (_, index) => `w${index}`).join(" ");+ expect(diffHtml(`<p>${words} old</p>`, `<p>${words} new</p>`))+ .toBe(`<p>${words} <del class="diffmod">old</del><ins class="diffmod">new</ins></p>`);+ });});diff --git a/apps/client/src/services/html_diff.ts b/apps/client/src/services/html_diff.tsindex 0a674cf5fd..ff82b86ff5 100644--- a/apps/client/src/services/html_diff.ts+++ b/apps/client/src/services/html_diff.ts@@ -43,7 +43,9 @@ export function diffHtml(oldHtml: string, newHtml: string): string {const output: string[] = [];for (const segment of mergeShortUnchangedRuns(segments)) {if ("unchanged" in segment) {- output.push(...segment.unchanged);+ for (const token of segment.unchanged) {+ output.push(token);+ }continue;}const isReplacement = segment.deleted.length > 0 && segment.inserted.length > 0;