fix(lesson): scroll к вопросу вместо прыжка вверх

- LessonViewPage: scrollIntoView → window.scrollTo с расчётом позиции
- App.tsx: skip глобального скролла на /lessons/* (GLOBAL_SCROLL_BREAKS_LESSON_NAV)
- translations: 16 ключей lesson* × 4 языка (уже в предыдущем коммите)
This commit is contained in:
2026-10-04 15:28:53 +03:00
parent ea40976578
commit 8ed822d30e
2 changed files with 33 additions and 12 deletions
+6 -1
View File
@@ -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;
+27 -11
View File
@@ -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 работает.
}}>
<div style={{ position: 'fixed', top: '-80px', right: '-60px', width: '260px', height: '260px', borderRadius: '50%', background: brandColor, opacity: 0.18, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />