mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
fix(recall-ui): dedupe observer/timer refresh attempts
This commit is contained in:
7
index.js
7
index.js
@@ -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" ||
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user