From 8ed822d30ed2c435500e21386a798b0924478cba Mon Sep 17 00:00:00 2001 From: Drobysh Date: Sun, 4 Oct 2026 15:28:53 +0300 Subject: [PATCH] =?UTF-8?q?fix(lesson):=20scroll=20=D0=BA=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=83=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D1=8B=D0=B6=D0=BA=D0=B0=20=D0=B2=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - LessonViewPage: scrollIntoView → window.scrollTo с расчётом позиции - App.tsx: skip глобального скролла на /lessons/* (GLOBAL_SCROLL_BREAKS_LESSON_NAV) - translations: 16 ключей lesson* × 4 языка (уже в предыдущем коммите) --- src/App.tsx | 7 ++++++- src/pages/LessonViewPage.tsx | 38 +++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d834dd3..8b304ef 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -212,7 +212,12 @@ function AppContent() { // Оставляем глобальный сброс только при реальной смене route. useEffect(() => { // Пропускаем, если мы на странице урока — там свой scrollIntoView. - if (location.pathname.includes('/lessons/')) return; + // 🔧 ДИАГНОСТИКА (04.10.2026): логирование на 1 минуту для проверки. + if (location.pathname.includes('/lessons/')) { + console.log('[App] skip scroll for lesson route'); + return; + } + console.log('[App] scrolling to top for', location.pathname); window.scrollTo(0, 0); document.documentElement.scrollTop = 0; diff --git a/src/pages/LessonViewPage.tsx b/src/pages/LessonViewPage.tsx index 002da94..ddb72fb 100644 --- a/src/pages/LessonViewPage.tsx +++ b/src/pages/LessonViewPage.tsx @@ -134,18 +134,30 @@ const LessonViewPage: React.FC = () => { } }, [lessonId, topicId]); - // 🔧 НОВОЕ (04.10.2026): при смене вопроса скроллим к блоку вопроса, - // а не в начало страницы. + // 🔧 ФИКС (04.10.2026): SCROLL_TO_QUESTION_VIA_WINDOW — + // scrollIntoView не работал при overflow:hidden на корне, + // потому что скроллил внутренний контейнер, а не window. + // Считаем позицию блока вручную и скроллим window. + // Задержка 100мс — ждём, пока браузер пересчитает layout после + // исчезновения explanation (страница становится короче). useEffect(() => { - if (questionBlockRef.current && !showIntermediate) { - // requestAnimationFrame — даём React отрендерить новый контент - requestAnimationFrame(() => { - questionBlockRef.current?.scrollIntoView({ - behavior: 'smooth', - block: 'center', - }); + if (showIntermediate || !questionBlockRef.current) return; + + const timer = setTimeout(() => { + const el = questionBlockRef.current; + if (!el) return; + + const rect = el.getBoundingClientRect(); + const absoluteTop = window.scrollY + rect.top; + + // Отступ 80px сверху — чтобы вопрос был виден, но не прилипал к краю + window.scrollTo({ + top: Math.max(0, absoluteTop - 80), + behavior: 'smooth', }); - } + }, 100); + + return () => clearTimeout(timer); }, [currentQuestionIndex, retryMode, showIntermediate]); const saveAnswer = async ( @@ -541,7 +553,11 @@ const LessonViewPage: React.FC = () => { minHeight: '100vh', background: bgColor, color: textColor, fontFamily: fonts.main, padding: '24px', display: 'flex', flexDirection: 'column', - position: 'relative', overflow: 'hidden', + position: 'relative', + // 🔧 ФИКС (04.10.2026): LESSON_OVERFLOW_HIDDEN_BREAKS_SCROLL — + // overflow:hidden на корне заставлял браузер сбрасывать скролл + // родителя к 0 при ре-рендере (когда explanation исчезал). + // Убрали — теперь scrollIntoView работает. }}>