From 70cefe9dc066dcd92eca066be1e1c6feaaeda73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=9D=D0=B0=D0=B4=D0=B5?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Tue, 13 Jan 2026 09:37:27 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=84=D0=BB=D0=B0=D0=B3=20=5FisInitializing=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=8B=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20Observer=20=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - проблема: Observer срабатывал сразу после setup даже с проверкой isNearBottom - isNearBottom() возвращает false когда scrollTop=0 (пользователь вверху) - решение: игнорируем события Observer в течение 500ms после init - флаг _isInitializing снимается через setTimeout - это гарантирует что автозагрузка не произойдет при первом рендере --- backend/static/js/managers/scrollManagerV2.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/static/js/managers/scrollManagerV2.js b/backend/static/js/managers/scrollManagerV2.js index 453e435a..0940d192 100644 --- a/backend/static/js/managers/scrollManagerV2.js +++ b/backend/static/js/managers/scrollManagerV2.js @@ -74,6 +74,7 @@ export class ScrollManagerV2 { this._historyObserver = null; this._isLoadingHistory = false; this._destroyed = false; + this._isInitializing = true; // ✅ Флаг инициализации // Bound handlers для cleanup this._boundScrollHandler = null; @@ -116,6 +117,13 @@ export class ScrollManagerV2 { this._setupScrollListener(); this._setupResizeListener(); + // Снимаем флаг инициализации после небольшой задержки + // чтобы Observer не сработал сразу + setTimeout(() => { + this._isInitializing = false; + console.log('[ScrollManagerV2] ✅ Initialization flag cleared'); + }, 500); + console.log('[ScrollManagerV2] 🟢 INIT COMPLETE'); } @@ -460,7 +468,8 @@ export class ScrollManagerV2 { entriesCount: entries.length, scrollTop: this.scrollEl.scrollTop, scrollHeight: this.scrollEl.scrollHeight, - isNearBottom: this.isNearBottom() + isNearBottom: this.isNearBottom(), + isInitializing: this._isInitializing }); entries.forEach(entry => { @@ -470,11 +479,17 @@ export class ScrollManagerV2 { intersectionRatio: entry.intersectionRatio, isLoadingHistory: this._isLoadingHistory, isNearBottom: this.isNearBottom(), - willLoadHistory: entry.isIntersecting && !this._isLoadingHistory && !this.isNearBottom() + isInitializing: this._isInitializing, + willLoadHistory: entry.isIntersecting && !this._isLoadingHistory && !this.isNearBottom() && !this._isInitializing }); - // ✅ ВАЖНО: НЕ загружаем историю если пользователь внизу! - // Это предотвращает ложное срабатывание при инициализации + // ✅ ВАЖНО: Игнорируем события во время инициализации + if (this._isInitializing) { + console.log('[ScrollManagerV2] 🚫 Initializing, ignoring observer event'); + return; + } + + // ✅ НЕ загружаем историю если пользователь внизу if (entry.isIntersecting && !this._isLoadingHistory && !this.isNearBottom()) { console.log('[ScrollManagerV2] 🚀 Triggering debounced history load...'); this._debouncedLoadHistory();