dsh-per-message-model 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +23 -8
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -231,7 +231,9 @@ window.__ModuleLoader__.load({
|
|
|
231
231
|
React.useEffect(() => {
|
|
232
232
|
if (typeof document === "undefined" || typeof MutationObserver === "undefined") return;
|
|
233
233
|
let observer = null;
|
|
234
|
+
let timer = 0;
|
|
234
235
|
const tryInsert = () => {
|
|
236
|
+
let remaining = 0;
|
|
235
237
|
for (const sw of switches) {
|
|
236
238
|
if (sw.to === null || typeof sw.to !== "object" ||
|
|
237
239
|
typeof sw.to.provider !== "string" || typeof sw.to.model !== "string") continue;
|
|
@@ -247,22 +249,35 @@ window.__ModuleLoader__.load({
|
|
|
247
249
|
const fromAnchor = document.querySelector('[data-chat-anchor-key="' + fromKey + '"]');
|
|
248
250
|
const toAnchor = toKey !== null ? document.querySelector('[data-chat-anchor-key="' + toKey + '"]') : null;
|
|
249
251
|
const anchor = fromAnchor !== null ? fromAnchor : toAnchor;
|
|
250
|
-
if (anchor === null) continue;
|
|
252
|
+
if (anchor === null) { remaining += 1; continue; }
|
|
251
253
|
const node = buildDividerNode(sw);
|
|
252
254
|
node.setAttribute("data-from-seq", String(seqKey));
|
|
253
255
|
if (fromAnchor !== null) fromAnchor.insertAdjacentElement("afterend", node);
|
|
254
256
|
else toAnchor.insertAdjacentElement("beforebegin", node);
|
|
255
257
|
}
|
|
258
|
+
return remaining;
|
|
256
259
|
};
|
|
257
|
-
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
// Insert what is already rendered; watch (debounced) only while some
|
|
261
|
+
// anchors are still missing (windowed history loads them on scroll),
|
|
262
|
+
// and disconnect the moment everything is in place so a live
|
|
263
|
+
// session's continuous DOM churn can never re-trigger work.
|
|
264
|
+
const schedule = () => {
|
|
265
|
+
if (timer !== 0) return;
|
|
266
|
+
timer = setTimeout(() => {
|
|
267
|
+
timer = 0;
|
|
268
|
+
if (tryInsert() === 0 && observer !== null) {
|
|
269
|
+
observer.disconnect();
|
|
270
|
+
observer = null;
|
|
271
|
+
}
|
|
272
|
+
}, 150);
|
|
273
|
+
};
|
|
274
|
+
if (tryInsert() > 0) {
|
|
275
|
+
observer = new MutationObserver(schedule);
|
|
276
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
277
|
+
}
|
|
264
278
|
return () => {
|
|
265
279
|
if (observer !== null) observer.disconnect();
|
|
280
|
+
if (timer !== 0) clearTimeout(timer);
|
|
266
281
|
};
|
|
267
282
|
}, [switches]);
|
|
268
283
|
return null;
|