nodebb-plugin-ezoic-infinite 1.4.16 → 1.4.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +28 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.16",
3
+ "version": "1.4.18",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
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,10 +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
- const wrap = buildWrap(id, kindClass, afterPos);
225
- target.insertAdjacentElement('afterend', wrap);
226
- attachFillObserver(wrap, id);
227
- return wrap;
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
233
+ const existingPh = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
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);
247
+ }
228
248
  }
229
249
 
230
250
  function destroyUsedPlaceholders() {
@@ -339,6 +359,10 @@
339
359
  if (!id) return;
340
360
  if (state.badIds && state.badIds.has(id)) return;
341
361
  if (state.retryQueueSet.has(id)) return;
362
+ // Ne pas enqueue si showAds a été appelé récemment (< 2s) pour éviter "already been defined"
363
+ const now = Date.now();
364
+ const last = state.lastShowById.get(id) || 0;
365
+ if (now - last < 2000) return;
342
366
  state.retryQueueSet.add(id);
343
367
  state.retryQueue.push(id);
344
368
  processRetryQueue();