修复切换query进度条不消失
This commit is contained in:
parent
386a28709f
commit
b7579c5947
@ -8,10 +8,11 @@ import {
|
|||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
|
Suspense,
|
||||||
type MutableRefObject,
|
type MutableRefObject,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
const SHOW_DELAY_MS = 120;
|
const SHOW_DELAY_MS = 120;
|
||||||
const MIN_VISIBLE_MS = 180;
|
const MIN_VISIBLE_MS = 180;
|
||||||
@ -32,12 +33,22 @@ function clearTimer(timerRef: MutableRefObject<number | null>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function NavigationProgressComplete({ onComplete }: { onComplete: () => void }) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onComplete();
|
||||||
|
}, [pathname, searchParams, onComplete]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function NavigationProgressProvider({
|
export function NavigationProgressProvider({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const pathname = usePathname();
|
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const visibleRef = useRef(false);
|
const visibleRef = useRef(false);
|
||||||
const shownAtRef = useRef(0);
|
const shownAtRef = useRef(0);
|
||||||
@ -93,10 +104,6 @@ export function NavigationProgressProvider({
|
|||||||
}, remainingVisibleMs);
|
}, remainingVisibleMs);
|
||||||
}, [setProgressVisible]);
|
}, [setProgressVisible]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
endNavigationProgress();
|
|
||||||
}, [pathname, endNavigationProgress]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function handleDocumentClick(event: MouseEvent) {
|
function handleDocumentClick(event: MouseEvent) {
|
||||||
if (
|
if (
|
||||||
@ -181,6 +188,9 @@ export function NavigationProgressProvider({
|
|||||||
return (
|
return (
|
||||||
<NavigationProgressContext.Provider value={contextValue}>
|
<NavigationProgressContext.Provider value={contextValue}>
|
||||||
{children}
|
{children}
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<NavigationProgressComplete onComplete={endNavigationProgress} />
|
||||||
|
</Suspense>
|
||||||
<div
|
<div
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
className={`pointer-events-none fixed inset-x-0 top-0 z-[100] transition-opacity duration-150 ${
|
className={`pointer-events-none fixed inset-x-0 top-0 z-[100] transition-opacity duration-150 ${
|
||||||
@ -204,4 +214,4 @@ export function useNavigationProgress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user