nodebb-plugin-ezoic-infinite 1.4.17 → 1.4.19
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/package.json +1 -1
- package/public/client.js +32 -11
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
// Survit aux navigations ajaxify (contrairement à state.definedIds remis à zéro dans cleanup).
|
|
19
19
|
// Nécessaire pour savoir si on doit appeler destroyPlaceholders avant recyclage.
|
|
20
20
|
const sessionDefinedIds = new Set();
|
|
21
|
+
|
|
22
|
+
// IDs actuellement en cours d'insertion (lock pour éviter les doublons de race condition)
|
|
23
|
+
const insertingIds = new Set();
|
|
21
24
|
|
|
22
25
|
const state = {
|
|
23
26
|
pageKey: null,
|
|
@@ -221,17 +224,27 @@
|
|
|
221
224
|
function insertAfter(target, id, kindClass, afterPos) {
|
|
222
225
|
if (!target || !target.insertAdjacentElement) return null;
|
|
223
226
|
if (findWrap(kindClass, afterPos)) return null;
|
|
224
|
-
|
|
225
|
-
//
|
|
227
|
+
|
|
228
|
+
// CRITICAL: Double-lock pour éviter race conditions sur les doublons
|
|
229
|
+
// 1. Vérifier qu'aucun autre thread n'est en train d'insérer cet ID
|
|
230
|
+
if (insertingIds.has(id)) return null;
|
|
231
|
+
|
|
232
|
+
// 2. Vérifier qu'aucun placeholder avec cet ID n'existe déjà dans le DOM
|
|
226
233
|
const existingPh = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
|
|
227
|
-
if (existingPh && existingPh.isConnected)
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
if (existingPh && existingPh.isConnected) return null;
|
|
235
|
+
|
|
236
|
+
// Acquérir le lock
|
|
237
|
+
insertingIds.add(id);
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
const wrap = buildWrap(id, kindClass, afterPos);
|
|
241
|
+
target.insertAdjacentElement('afterend', wrap);
|
|
242
|
+
attachFillObserver(wrap, id);
|
|
243
|
+
return wrap;
|
|
244
|
+
} finally {
|
|
245
|
+
// Libérer le lock après 100ms (le temps que le DOM soit stable)
|
|
246
|
+
setTimeout(() => insertingIds.delete(id), 100);
|
|
230
247
|
}
|
|
231
|
-
const wrap = buildWrap(id, kindClass, afterPos);
|
|
232
|
-
target.insertAdjacentElement('afterend', wrap);
|
|
233
|
-
attachFillObserver(wrap, id);
|
|
234
|
-
return wrap;
|
|
235
248
|
}
|
|
236
249
|
|
|
237
250
|
function destroyUsedPlaceholders() {
|
|
@@ -389,6 +402,14 @@
|
|
|
389
402
|
|
|
390
403
|
|
|
391
404
|
function refillUnfilled() {
|
|
405
|
+
// Si tous les IDs disponibles sont blacklistés, ne pas réessayer
|
|
406
|
+
const totalPoolSize = state.poolTopics.length + state.poolPosts.length + state.poolCategories.length +
|
|
407
|
+
state.usedTopics.size + state.usedPosts.size + state.usedCategories.size;
|
|
408
|
+
if (totalPoolSize > 0 && state.badIds.size >= totalPoolSize) {
|
|
409
|
+
// Tous les IDs disponibles sont blacklistés - arrêter les retry
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
392
413
|
const wraps = Array.from(document.querySelectorAll(`.${WRAP_CLASS}`));
|
|
393
414
|
let scheduledAny = false;
|
|
394
415
|
|
|
@@ -409,7 +430,7 @@
|
|
|
409
430
|
}
|
|
410
431
|
|
|
411
432
|
const tries = (state.retryById.get(id) || 0);
|
|
412
|
-
if (tries >=
|
|
433
|
+
if (tries >= 3) { state.badIds && state.badIds.add(id); continue; }
|
|
413
434
|
|
|
414
435
|
const r = safeRect(wrap);
|
|
415
436
|
if (r && (r.top > window.innerHeight + 1200 || r.bottom < -1200)) continue;
|
|
@@ -786,7 +807,7 @@
|
|
|
786
807
|
// Réinitialiser le compteur d'attente de recyclage à chaque reprise de scroll
|
|
787
808
|
state.poolWaitAttempts = 0;
|
|
788
809
|
enforceNoAdjacentAds();
|
|
789
|
-
scheduleRefill(
|
|
810
|
+
scheduleRefill(2000);
|
|
790
811
|
// Tenter aussi d'insérer de nouvelles pubs si de nouveaux items sont apparus
|
|
791
812
|
scheduleRun();
|
|
792
813
|
});
|