fix: 详情页滚动与多余背景 — 对齐原站路由级 canvas 生命周期
- HeroScene/LoadingOverlay 仅在 "/" 渲染(原 canvas/set:详情页 reveal 后 卸载 canvas;entry 幕布是主页专属流程)——详情页不再有贴纸/背景 FX/玻璃 模型等"多余背景",也没有 loading 幕布 - 详情页滚动容器改为常规文档流:我们的 Lenis 是 window 级,原版的嵌套 overflow-y-auto 容器会吞掉滚轮导致页面不能滚动;窗口原生滚动接管 - SmoothScroller 按路由启停 Lenis(原 95212:主页 ReactLenis、详情页原生 滚动),路由切换时滚动复位到顶部(转场遮罩盖住跳变) - CDP 实测:详情页 wheel/End 滚动 ✅、canvas=0、幕布=0;返回主页后 canvas/Lenis/滚动条恢复、wheel 平滑滚动 ✅
This commit is contained in:
+15
-15
@@ -124,9 +124,8 @@ function Article({ slug }: { slug: string }) {
|
|||||||
const article = WORK_ARTICLES[slug];
|
const article = WORK_ARTICLES[slug];
|
||||||
if (!article) {
|
if (!article) {
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 w-full h-full">
|
<>
|
||||||
<div className="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
|
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1">
|
||||||
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1">
|
|
||||||
<header className="pt-[10vh]">
|
<header className="pt-[10vh]">
|
||||||
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight">
|
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight">
|
||||||
404
|
404
|
||||||
@@ -141,18 +140,20 @@ function Article({ slug }: { slug: string }) {
|
|||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 w-full h-full">
|
<>
|
||||||
<div className="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
|
{/* The window (Lenis) is the scroller — the original nests its own
|
||||||
<article
|
overflow container per route because its Lenis wraps <main>; our
|
||||||
data-mdx-article="true"
|
Lenis is window-level, so a nested overflow div would swallow the
|
||||||
className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1"
|
wheel and kill scrolling. */}
|
||||||
>
|
<article
|
||||||
|
data-mdx-article="true"
|
||||||
|
className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1"
|
||||||
|
>
|
||||||
<header className="pt-[10vh]">
|
<header className="pt-[10vh]">
|
||||||
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight" style={{ fontVariationSettings: '"wdth" 120' }}>
|
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight" style={{ fontVariationSettings: '"wdth" 120' }}>
|
||||||
{article.title}
|
{article.title}
|
||||||
@@ -222,9 +223,8 @@ function Article({ slug }: { slug: string }) {
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
)}
|
)}
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
import { Canvas, useThree } from "@react-three/fiber";
|
import { Canvas, useThree } from "@react-three/fiber";
|
||||||
import { PerspectiveCamera } from "@react-three/drei";
|
import { PerspectiveCamera } from "@react-three/drei";
|
||||||
|
|
||||||
@@ -76,6 +77,13 @@ export function HeroScene() {
|
|||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const ready = useAppReady();
|
const ready = useAppReady();
|
||||||
const hostRef = useRef<HTMLDivElement>(null);
|
const hostRef = useRef<HTMLDivElement>(null);
|
||||||
|
// Original canvas lifecycle (module 34841 `canvas/set`): the canvas is
|
||||||
|
// mounted for the home page and the fullscreen transitions; on detail
|
||||||
|
// routes it is unmounted once the route reveal completes. Our DOM-based
|
||||||
|
// transition overlay covers navigation, so the canvas simply renders
|
||||||
|
// home-only — no background FX / stickers / models leak onto detail pages.
|
||||||
|
const pathname = usePathname();
|
||||||
|
const home = pathname === "/";
|
||||||
|
|
||||||
// Watchdog (outside the Canvas so it runs even before R3F configures):
|
// Watchdog (outside the Canvas so it runs even before R3F configures):
|
||||||
// R3F's react-use-measure can capture a stale intrinsic-size measurement
|
// R3F's react-use-measure can capture a stale intrinsic-size measurement
|
||||||
@@ -111,6 +119,8 @@ export function HeroScene() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if (!home) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// 1:1 original stacking: z-auto fixed host BEFORE the grid/main in DOM.
|
// 1:1 original stacking: z-auto fixed host BEFORE the grid/main in DOM.
|
||||||
// The z-20 BackgroundGrid (rendered after this element) paints above the
|
// The z-20 BackgroundGrid (rendered after this element) paints above the
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {
|
import { useEffect, useState, useSyncExternalStore } from "react";
|
||||||
useEffect,
|
import { usePathname } from "next/navigation";
|
||||||
useState,
|
|
||||||
useSyncExternalStore,
|
|
||||||
} from "react";
|
|
||||||
import { loadingBus } from "@/lib/loadingBus";
|
import { loadingBus } from "@/lib/loadingBus";
|
||||||
import LoadingCurtain from "@/components/canvas/LoadingCurtain";
|
import LoadingCurtain from "@/components/canvas/LoadingCurtain";
|
||||||
|
|
||||||
@@ -71,6 +68,9 @@ export function useAppReady(): boolean {
|
|||||||
export function LoadingOverlay() {
|
export function LoadingOverlay() {
|
||||||
const heavy = useHeavyLoad();
|
const heavy = useHeavyLoad();
|
||||||
const fontsReady = useFontsReady();
|
const fontsReady = useFontsReady();
|
||||||
|
// Original useHomeLoadingGate: the entry curtain is a "/"-only flow —
|
||||||
|
// detail routes render with no loading curtain at all.
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
// wait → fading → reveal → (unmount when reveal completes)
|
// wait → fading → reveal → (unmount when reveal completes)
|
||||||
const [phase, setPhase] = useState<"wait" | "fading" | "reveal">("wait");
|
const [phase, setPhase] = useState<"wait" | "fading" | "reveal">("wait");
|
||||||
@@ -92,7 +92,7 @@ export function LoadingOverlay() {
|
|||||||
return () => window.clearTimeout(t2);
|
return () => window.clearTimeout(t2);
|
||||||
}, [phase]);
|
}, [phase]);
|
||||||
|
|
||||||
if (!mounted) return null;
|
if (!mounted || pathname !== "/") return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
import { usePathname } from 'next/navigation';
|
||||||
import Lenis from 'lenis';
|
import Lenis from 'lenis';
|
||||||
import { scrollBus, notifyScroll } from '@/lib/scrollBus';
|
import { scrollBus, notifyScroll } from '@/lib/scrollBus';
|
||||||
import { scrollEnv } from '@/lib/scrollEnv';
|
import { scrollEnv } from '@/lib/scrollEnv';
|
||||||
@@ -21,7 +22,29 @@ const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
|
|||||||
* camera pull-back).
|
* camera pull-back).
|
||||||
*/
|
*/
|
||||||
export default function SmoothScroller() {
|
export default function SmoothScroller() {
|
||||||
|
// Original route wiring (chunk 3c6cc5b2 module 95212): the home route is
|
||||||
|
// wrapped in ReactLenis; every other route scrolls its container
|
||||||
|
// natively. Our Lenis is window-level, so on detail routes we destroy it
|
||||||
|
// entirely (native window scroll) and reset the scroll to the top — the
|
||||||
|
// transition overlay covers the jump.
|
||||||
|
const pathname = usePathname();
|
||||||
|
const isHome = pathname === '/';
|
||||||
|
|
||||||
|
// Scroll reset per route (original scrolls its per-route container to
|
||||||
|
// top on mount; the transition cover hides the jump).
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (window.location.hash) return;
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
requestAnimationFrame(() => window.scrollTo(0, 0));
|
||||||
|
}, [isHome]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isHome) {
|
||||||
|
scrollEnv.setLenis(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let disposed = false;
|
||||||
|
let rafId = 0;
|
||||||
// Refresh must always start at the top (original behavior: no anchor
|
// Refresh must always start at the top (original behavior: no anchor
|
||||||
// → scroll to 0; also re-asserted on bfcache pageshow).
|
// → scroll to 0; also re-asserted on bfcache pageshow).
|
||||||
if ('scrollRestoration' in window.history) {
|
if ('scrollRestoration' in window.history) {
|
||||||
@@ -73,19 +96,22 @@ export default function SmoothScroller() {
|
|||||||
updateCameraProgress();
|
updateCameraProgress();
|
||||||
|
|
||||||
function raf(time: number) {
|
function raf(time: number) {
|
||||||
|
if (disposed) return;
|
||||||
lenis.raf(time);
|
lenis.raf(time);
|
||||||
requestAnimationFrame(raf);
|
rafId = requestAnimationFrame(raf);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestAnimationFrame(raf);
|
rafId = requestAnimationFrame(raf);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
disposed = true;
|
||||||
|
cancelAnimationFrame(rafId);
|
||||||
window.removeEventListener('resize', updateCameraProgress);
|
window.removeEventListener('resize', updateCameraProgress);
|
||||||
window.removeEventListener('pageshow', onPageShow);
|
window.removeEventListener('pageshow', onPageShow);
|
||||||
scrollEnv.setLenis(null);
|
scrollEnv.setLenis(null);
|
||||||
lenis.destroy();
|
lenis.destroy();
|
||||||
};
|
};
|
||||||
}, []);
|
}, [isHome]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user