nodebb-plugin-ezoic-infinite 1.4.37 → 1.4.39

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 +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.37",
3
+ "version": "1.4.39",
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
@@ -352,12 +352,22 @@
352
352
  if (state.pageKey !== startPageKey) return;
353
353
  // Abort if another concurrent call is already handling this id
354
354
  if (state.pendingById.has(id)) return;
355
+
355
356
  attempts += 1;
356
357
  const el = document.getElementById(phId);
357
358
  if (el && el.isConnected) {
358
359
  if (window.location.pathname !== '/') {
359
360
  console.log('[TIMING] Placeholder', id, 'trouvé dans DOM, appel showAds');
360
361
  }
362
+
363
+ // Double-check pageKey juste avant doCall (au cas où cleanup appelé entre-temps)
364
+ if (state.pageKey !== startPageKey) {
365
+ if (window.location.pathname !== '/') {
366
+ console.log('[TIMING] ABORT ID', id, '- navigation détectée avant showAds');
367
+ }
368
+ return;
369
+ }
370
+
361
371
  // Si doCall() réussit, Ezoic est chargé et showAds a été appelé → sortir
362
372
  if (doCall()) {
363
373
  state.pendingById.delete(id); // nettoyage au cas où
@@ -537,6 +547,8 @@
537
547
  state.liveCategory = [];
538
548
 
539
549
  state.lastShowById.clear();
550
+ // CRITIQUE: Vider pendingById pour annuler tous les showAds en cours
551
+ // Sinon Ezoic essaie d'accéder aux placeholders pendant que NodeBB vide le DOM
540
552
  state.pendingById.clear();
541
553
  state.definedIds.clear();
542
554
 
@@ -545,6 +557,7 @@
545
557
  // Les supprimer manuellement cause des problèmes avec l'état interne d'Ezoic
546
558
 
547
559
  if (state.obs) { state.obs.disconnect(); state.obs = null; }
560
+ state.canInsert = false;
548
561
  state.scheduled = false;
549
562
  clearTimeout(state.timer);
550
563
  state.timer = null;
@@ -557,6 +570,11 @@
557
570
  }
558
571
 
559
572
  async function runCore() {
573
+ // Attendre que canInsert soit true (protection race condition navigation)
574
+ if (!state.canInsert) {
575
+ return;
576
+ }
577
+
560
578
  patchShowAds();
561
579
 
562
580
  const cfg = await fetchConfig();
@@ -646,6 +664,14 @@
646
664
  $(window).on('action:ajaxify.end.ezoicInfinite', () => {
647
665
  state.pageKey = getPageKey();
648
666
  ensureObserver();
667
+
668
+ // CRITIQUE: Attendre 300ms avant de permettre l'insertion de nouveaux placeholders
669
+ // pour laisser les anciens showAds() (en cours) se terminer ou échouer proprement
670
+ // Sinon race condition: NodeBB vide le DOM pendant que Ezoic essaie d'accéder aux placeholders
671
+ state.canInsert = false;
672
+ setTimeout(() => {
673
+ state.canInsert = true;
674
+ }, 300);
649
675
  });
650
676
 
651
677
  $(window).on('action:category.loaded.ezoicInfinite', () => {