From 1cc8190bfce7bee3f59b9d8181bd1520f89392a7 Mon Sep 17 00:00:00 2001 From: ogt Date: Wed, 22 Apr 2026 09:22:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(code-review):=20=E4=BF=AE=E5=BE=A9=E9=A0=81?= =?UTF-8?q?=E9=9D=A2=E7=A9=BA=E7=99=BD=E7=9A=84=20race=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit loadHistory() 完成後才是自動載入最新記錄的正確時機; 原本放在 poll() 的觸發點在 _historyData 還未填充時就已執行, 導致條件永遠不成立,頁面一直顯示佔位符。 Co-Authored-By: Claude Sonnet 4.6 --- templates/code_review.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/code_review.html b/templates/code_review.html index 68bf6fd..bbbac21 100644 --- a/templates/code_review.html +++ b/templates/code_review.html @@ -439,11 +439,6 @@ async function poll() { renderCommitInfo(state); document.getElementById('pipelineId').textContent = (state.pipeline_id||'').slice(-14); - // 無 active pipeline 時,自動顯示最新歷史記錄 - if (!state.status && _historyData.length && !_lastPipelineId) { - loadHistoryItem(0); - } - // 每 3s 輪詢(running)/ 30s(idle) const interval = state.status === 'running' ? 3000 : 30000; _polling = setTimeout(poll, interval); @@ -455,7 +450,12 @@ async function poll() { async function loadHistory() { try { const r = await fetch('/code-review/api/history?limit=15'); - renderHistory(await r.json()); + const items = await r.json(); + renderHistory(items); + // 無 active pipeline 且尚未顯示任何 pipeline 內容時,自動展示最新一筆 + if (items.length && !_lastPipelineId) { + loadHistoryItem(0); + } } catch(e) { document.getElementById('historyList').innerHTML = '
載入失敗
'; }