From c8b2dcde09dffe8a54486b14741a1e8749ada30b Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 18 Feb 2026 07:39:00 +0100 Subject: [PATCH] Compress code and add error handling for fetchBlobExcerpt Co-Authored-By: Claude Opus 4.6 --- web_src/js/features/repo-diff.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts index 9a824adb31..1c5ae24cf9 100644 --- a/web_src/js/features/repo-diff.ts +++ b/web_src/js/features/repo-diff.ts @@ -258,9 +258,7 @@ async function onLocationHashChange() { const attrAutoLoadClicked = 'data-auto-load-clicked'; if (expandButton.hasAttribute(attrAutoLoadClicked)) return; expandButton.setAttribute(attrAutoLoadClicked, 'true'); - const tr = expandButton.closest('tr')!; - const url = expandButton.getAttribute('data-url')!; - await fetchBlobExcerpt(tr, url); + await fetchBlobExcerpt(expandButton.closest('tr')!, expandButton.getAttribute('data-url')!); continue; // Try again to find the element } } @@ -285,13 +283,13 @@ function initRepoDiffHashChangeListener() { const expandAllSavedState = new Map(); async function fetchBlobExcerpt(tr: Element, url: string): Promise { - const resp = await GET(url); - const text = await resp.text(); - // Parse elements in proper table context - const tempTbody = document.createElement('tbody'); - tempTbody.innerHTML = text; - const nodes = Array.from(tempTbody.children); - tr.replaceWith(...nodes); + try { + const tempTbody = document.createElement('tbody'); + tempTbody.innerHTML = await (await GET(url)).text(); + tr.replaceWith(...tempTbody.children); + } catch (error) { + console.error('Error:', error); + } } async function expandAllLines(btn: HTMLElement, fileBox: HTMLElement) { @@ -377,9 +375,7 @@ function initDiffExpandAllLines() { }); registerGlobalEventFunc('click', 'onExpanderButtonClick', (btn: HTMLElement) => { - const tr = btn.closest('tr')!; - const url = btn.getAttribute('data-url')!; - fetchBlobExcerpt(tr, url); + fetchBlobExcerpt(btn.closest('tr')!, btn.getAttribute('data-url')!); }); }