nodebb-plugin-ezoic-infinite 1.4.17 → 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 +22 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.17",
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,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
- // CRITICAL: Vérifier qu'aucun placeholder avec cet ID n'existe déjà dans le DOM
225
- // (peut arriver si deux scheduleRun concurrents recyclent le même ID)
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
- // Un placeholder avec cet ID existe déjà - ne pas créer de doublon
229
- return null;
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() {