From 811b5958e5077a3508fd07ed6fb891bc4085968c Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Fri, 3 Apr 2026 00:49:33 +0800 Subject: [PATCH] perf(page-transition): stabilize layer context --- src/components/common/PageTransition.tsx | 10 ++++++++-- src/components/common/PageTransitionLayer.ts | 10 ++++++++-- src/components/common/SecondaryScreenShell.tsx | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/common/PageTransition.tsx b/src/components/common/PageTransition.tsx index 8f625411..452d56a1 100644 --- a/src/components/common/PageTransition.tsx +++ b/src/components/common/PageTransition.tsx @@ -2,7 +2,11 @@ import { ReactNode, useCallback, useLayoutEffect, useRef, useState } from 'react import { useLocation, type Location } from 'react-router-dom'; import { animate } from 'motion/mini'; import type { AnimationPlaybackControlsWithThen } from 'motion-dom'; -import { PageTransitionLayerContext, type LayerStatus } from './PageTransitionLayer'; +import { + PAGE_TRANSITION_LAYER_CONTEXT_VALUES, + PageTransitionLayerContext, + type LayerStatus, +} from './PageTransitionLayer'; import './PageTransition.scss'; interface PageTransitionProps { @@ -386,7 +390,9 @@ export function PageTransition({ : undefined } > - + {render(layer.location)} diff --git a/src/components/common/PageTransitionLayer.ts b/src/components/common/PageTransitionLayer.ts index 3e33e869..98f58987 100644 --- a/src/components/common/PageTransitionLayer.ts +++ b/src/components/common/PageTransitionLayer.ts @@ -2,14 +2,20 @@ import { createContext, useContext } from 'react'; export type LayerStatus = 'current' | 'exiting' | 'stacked'; -type PageTransitionLayerContextValue = { +export type PageTransitionLayerContextValue = { status: LayerStatus; + isCurrentLayer: boolean; }; export const PageTransitionLayerContext = createContext(null); +export const PAGE_TRANSITION_LAYER_CONTEXT_VALUES: Record = { + current: { status: 'current', isCurrentLayer: true }, + stacked: { status: 'stacked', isCurrentLayer: false }, + exiting: { status: 'exiting', isCurrentLayer: false }, +}; + export function usePageTransitionLayer() { return useContext(PageTransitionLayerContext); } - diff --git a/src/components/common/SecondaryScreenShell.tsx b/src/components/common/SecondaryScreenShell.tsx index f14e3f22..8d8a485d 100644 --- a/src/components/common/SecondaryScreenShell.tsx +++ b/src/components/common/SecondaryScreenShell.tsx @@ -52,7 +52,7 @@ export const SecondaryScreenShell = forwardRef(null);