fix(code-review): 修復頁面空白的 race condition
All checks were successful
CD Pipeline / deploy (push) Successful in 1m24s

loadHistory() 完成後才是自動載入最新記錄的正確時機;
原本放在 poll() 的觸發點在 _historyData 還未填充時就已執行,
導致條件永遠不成立,頁面一直顯示佔位符。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-22 09:22:10 +08:00
parent 28acdc19ae
commit 1cc8190bfc

View File

@@ -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/ 30sidle
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 = '<div class="empty"><div>載入失敗</div></div>';
}