fix(recall-ui): dedupe observer/timer refresh attempts

This commit is contained in:
Youzini-afk
2026-03-29 21:08:24 +08:00
parent e09b116a71
commit 16e1427fe1
2 changed files with 17 additions and 1 deletions

View File

@@ -1486,8 +1486,13 @@ function schedulePersistedRecallMessageUiRefresh(delayMs = 0) {
const runAttempt = () => { const runAttempt = () => {
if (sessionId !== persistedRecallUiRefreshSession) return; if (sessionId !== persistedRecallUiRefreshSession) return;
persistedRecallUiRefreshTimer = null; if (persistedRecallUiRefreshTimer) {
clearTimeout(persistedRecallUiRefreshTimer);
persistedRecallUiRefreshTimer = null;
}
const summary = refreshPersistedRecallMessageUi(); const summary = refreshPersistedRecallMessageUi();
const shouldRetry = const shouldRetry =
(summary.status === "missing_chat_root" || (summary.status === "missing_chat_root" ||
summary.status === "waiting_dom" || summary.status === "waiting_dom" ||

View File

@@ -1007,13 +1007,24 @@ async function testRecallCardDelayedDomInsertionEventuallyRenders() {
]; ];
const harness = await createRecallUiHarness({ chat }); const harness = await createRecallUiHarness({ chat });
try { try {
let updateCalls = 0;
const originalUpdateRecallCardData = harness.context.updateRecallCardData;
harness.context.updateRecallCardData = (...args) => {
updateCalls += 1;
return originalUpdateRecallCardData(...args);
};
harness.api.schedulePersistedRecallMessageUiRefresh(); harness.api.schedulePersistedRecallMessageUiRefresh();
await waitForTick(); await waitForTick();
const messageElement = createMessageElement(harness.document, 0, { stableId: true, withMesBlock: true, isUser: true }); const messageElement = createMessageElement(harness.document, 0, { stableId: true, withMesBlock: true, isUser: true });
harness.chatRoot.appendChild(messageElement); harness.chatRoot.appendChild(messageElement);
await waitForTick(); await waitForTick();
await waitForTick(); await waitForTick();
await new Promise((resolve) => setTimeout(resolve, 35));
await waitForTick();
assert.equal(harness.chatRoot.querySelectorAll(".bme-recall-card").length, 1); assert.equal(harness.chatRoot.querySelectorAll(".bme-recall-card").length, 1);
assert.equal(updateCalls, 0, "observer 先触发后不应再被旧 timeout 重复刷新");
} finally { } finally {
harness.restoreGlobals(); harness.restoreGlobals();
} }