Files
SnowLuma/.pnpm-store/v11/files/0c/20d2d58bc7771f4bda530206ac9befa35a8d9a86a711514456b315f98b88808a51efdfaa717f8cb53c0692b6298c96330b0d9a5d2da5d692d1c1e8057ab4a1
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Skipped
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

105 lines
3.1 KiB
Plaintext

"use client";
import { useLayoutEffect, usePrevious } from "./utils.js";
import { useRouter } from "./useRouter.js";
import { getLocationChangeInfo, handleHashScroll, trimPathRight } from "@tanstack/router-core";
import * as React$1 from "react";
import { batch, useStore } from "@tanstack/react-store";
//#region src/Transitioner.tsx
function Transitioner() {
const router = useRouter();
const mountLoadForRouter = React$1.useRef({
router,
mounted: false
});
const [isTransitioning, setIsTransitioning] = React$1.useState(false);
const isLoading = useStore(router.stores.isLoading, (value) => value);
const hasPending = useStore(router.stores.hasPending, (value) => value);
const previousIsLoading = usePrevious(isLoading);
const isAnyPending = isLoading || isTransitioning || hasPending;
const previousIsAnyPending = usePrevious(isAnyPending);
const isPagePending = isLoading || hasPending;
const previousIsPagePending = usePrevious(isPagePending);
router.startTransition = (fn) => {
setIsTransitioning(true);
React$1.startTransition(() => {
fn();
setIsTransitioning(false);
});
};
React$1.useEffect(() => {
const unsub = router.history.subscribe(router.load);
const nextLocation = router.buildLocation({
to: router.latestLocation.pathname,
search: true,
params: true,
hash: true,
state: true,
_includeValidateSearch: true
});
if (trimPathRight(router.latestLocation.publicHref) !== trimPathRight(nextLocation.publicHref)) router.commitLocation({
...nextLocation,
replace: true
});
return () => {
unsub();
};
}, [router, router.history]);
useLayoutEffect(() => {
if (typeof window !== "undefined" && router.ssr || mountLoadForRouter.current.router === router && mountLoadForRouter.current.mounted) return;
mountLoadForRouter.current = {
router,
mounted: true
};
const tryLoad = async () => {
try {
await router.load();
} catch (err) {
console.error(err);
}
};
tryLoad();
}, [router]);
useLayoutEffect(() => {
if (previousIsLoading && !isLoading) router.emit({
type: "onLoad",
...getLocationChangeInfo(router.stores.location.get(), router.stores.resolvedLocation.get())
});
}, [
previousIsLoading,
router,
isLoading
]);
useLayoutEffect(() => {
if (previousIsPagePending && !isPagePending) router.emit({
type: "onBeforeRouteMount",
...getLocationChangeInfo(router.stores.location.get(), router.stores.resolvedLocation.get())
});
}, [
isPagePending,
previousIsPagePending,
router
]);
useLayoutEffect(() => {
if (previousIsAnyPending && !isAnyPending) {
const changeInfo = getLocationChangeInfo(router.stores.location.get(), router.stores.resolvedLocation.get());
router.emit({
type: "onResolved",
...changeInfo
});
batch(() => {
router.stores.status.set("idle");
router.stores.resolvedLocation.set(router.stores.location.get());
});
if (changeInfo.hrefChanged) handleHashScroll(router);
}
}, [
isAnyPending,
previousIsAnyPending,
router
]);
return null;
}
//#endregion
export { Transitioner };
//# sourceMappingURL=Transitioner.js.map