From 73c11b4c49addd13da665ef90f2e9ff59891e353 Mon Sep 17 00:00:00 2001 From: whereareiam Date: Sat, 14 Nov 2026 12:24:33 +0100 Subject: [PATCH] fix(diff): load more files at a steady pace and run the tree divider to the footer Each page of a large pull request loaded slower than the one before: Forgejo removes the loader and appends the next one after the diff, and the element before a changed last child is restyled with everything inside it, so every page restyled all files loaded so far. An empty element now stands between the diff and the loader. Every page also pushed the whole file list into the tree's data again; only files not listed yet are added now. In a 360 file pull request a page now takes about 300ms instead of growing to almost 2s. The next page starts loading four screens before the end, and a load that finds the link busy is retried shortly instead of after five seconds. The divider between the file tree and the files ends at the footer, as on GitHub, instead of above the page's bottom margin. Co-Authored-By: Claude Opus 5.5 --- public/assets/js/diff-view.js | 15 +++++++++------ styles/components/issues/pull_review.ts | 5 +++++ templates/repo/diff/box.tmpl | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/public/assets/js/diff-view.js b/public/assets/js/diff-view.js index 45fc2c6e..bf7a2b7a 100644 --- a/public/assets/js/diff-view.js +++ b/public/assets/js/diff-view.js @@ -237,9 +237,10 @@ attributeFilter: ["data-folded", "data-tree-filtered"], }); updateFoldLabels(); - // GitHub loads the next files while scrolling. Press Forgejo's hidden "Show more" link before the end comes into - // view; its handler swaps in a new #diff-incomplete for each page. A loader still there after a while failed or is - // slow, so it is watched again and retried once in view. + // GitHub loads the next files while scrolling. Press Forgejo's hidden "Show more" link while the end is still four + // screens away, so a page is usually loaded before it is reached; its handler swaps in a new #diff-incomplete for + // each page. A link that is busy with another load is tried again shortly; a loader still there after a while failed + // or is slow, so it is watched again and retried once in view. const content = document.getElementById("diff-content-container"); if (content && "IntersectionObserver" in window) { const loader = new IntersectionObserver( @@ -247,11 +248,13 @@ for (const entry of entries) { if (!entry.isIntersecting) continue; loader.unobserve(entry.target); - entry.target.querySelector("#diff-show-more-files:not(.disabled)")?.click(); - setTimeout(() => entry.target.isConnected && loader.observe(entry.target), 5000); + const link = entry.target.querySelector("#diff-show-more-files"); + const busy = link?.classList.contains("disabled"); + if (link && !busy) link.click(); + setTimeout(() => entry.target.isConnected && loader.observe(entry.target), busy ? 300 : 5000); } }, - { rootMargin: "0px 0px 2000px 0px" } + { rootMargin: "0px 0px 400% 0px" } ); const watchIncomplete = () => { const incomplete = document.getElementById("diff-incomplete"); diff --git a/styles/components/issues/pull_review.ts b/styles/components/issues/pull_review.ts index 4ab15975..364a18d2 100644 --- a/styles/components/issues/pull_review.ts +++ b/styles/components/issues/pull_review.ts @@ -40,6 +40,9 @@ const mergeButton = ` `; export default css` + .full.height:has(> .page-content.github-pull-review.files) { + padding-bottom: 0; + } .page-content.repository.view.issue.github-pull-review { & > .ui.container { width: calc(100% - 64px) !important; @@ -50,6 +53,8 @@ export default css` &.files > .ui.container { width: 100% !important; max-width: none !important; + /* GitHub's divider between the file tree and the files runs down to the footer. */ + margin-bottom: 0 !important; } /* GitHub's files tab is full width: title, tabs and diff share a 24px side margin. */ &.files > .ui.container > .issue-title-header, diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 9606009e..2f6da468 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -33,7 +33,10 @@ selectedItem: '', }; diffFileInfo = Object.assign(diffFileInfo, diffData); - diffFileInfo.files.push(...diffDataFiles); + // Every page lists all files of the diff, so a loaded page adds only the files not listed yet. Pushing the + // whole list again grew the tree's data with each page and slowed every later page down. + const knownFiles = new Set(diffFileInfo.files.map(file => file.NameHash)); + diffFileInfo.files.push(...diffDataFiles.filter(file => !knownFiles.has(file.NameHash))); window.config.pageData.diffFileInfo = diffFileInfo; {{end}} @@ -199,16 +202,20 @@ {{end}} - {{if .DiffMetadata.HasNext}} - {{/* GitHub loads the next files while scrolling: diff-view.js presses the hidden "Show more" link. */}} -
- - {{ctx.Locale.Tr "loading"}} - {{ctx.Locale.Tr "repo.diff.show_more"}} -
- {{end}} {{end}} + {{/* Forgejo removes #diff-incomplete and appends the next one to #diff-content-container after every page. The + element before a removed or added last child is restyled with everything inside it, so without this empty + element every page restyled all files loaded so far, and each page loaded slower than the one before. */}} + + {{if and (not .DiffNotAvailable) .DiffMetadata.HasNext}} + {{/* GitHub loads the next files while scrolling: diff-view.js presses the hidden "Show more" link. */}} +
+ + {{ctx.Locale.Tr "loading"}} + {{ctx.Locale.Tr "repo.diff.show_more"}} +
+ {{end}}