Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(landing): invalid isMounted judgment #1238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions website/landing/components/Hero/HeroDesktop/HeroDesktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const HeroDesktop: React.FC = () => {
const [scrollPosition, setScrollPosition] = useState(scrollY.get());
const scrollHeight = useMemo(() => sectionHeight / 3, [sectionHeight]);
const [animationComplete, setAnimationComplete] = useState(false);
const isMounted = useRef(false);
const isMountedRef = useRef(false);

scrollY.onChange((updatedScroll) => setScrollPosition(updatedScroll));

Expand Down Expand Up @@ -102,9 +102,9 @@ export const HeroDesktop: React.FC = () => {
}, [sectionRef]);

useLayoutEffect(() => {
if (isMounted.current) return;
if (isMountedRef.current) return;

isMounted.current = !!sectionRef.current;
isMountedRef.current = !!sectionRef.current;
}, [sectionRef]);

useEffect(() => {
Expand Down Expand Up @@ -154,6 +154,8 @@ export const HeroDesktop: React.FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [animationComplete]);

const isMounted = isMountedRef.current;

return (
<AnimatedBox
ref={sectionRef}
Expand All @@ -180,7 +182,7 @@ export const HeroDesktop: React.FC = () => {
position: "sticky",
top: 0,
transform: "scale($container-scale)",
opacity: isMounted.current ? 1 : 0,
opacity: isMounted ? 1 : 0,
transition: "opacity 300ms linear",

display: "flex",
Expand Down