()
| 10 | import { usePrevious } from './utils' |
| 11 | |
| 12 | export function Transitioner() { |
| 13 | const router = useRouter() |
| 14 | let mountLoadForRouter = { router, mounted: false } |
| 15 | const isLoading = useRouterState({ |
| 16 | select: ({ isLoading }) => isLoading, |
| 17 | }) |
| 18 | |
| 19 | if (isServer ?? router.isServer) { |
| 20 | return null |
| 21 | } |
| 22 | |
| 23 | const [isSolidTransitioning, startSolidTransition] = Solid.useTransition() |
| 24 | |
| 25 | // Track pending state changes |
| 26 | const hasPendingMatches = useRouterState({ |
| 27 | select: (s) => s.matches.some((d) => d.status === 'pending'), |
| 28 | }) |
| 29 | |
| 30 | const previousIsLoading = usePrevious(isLoading) |
| 31 | |
| 32 | const isAnyPending = () => |
| 33 | isLoading() || isSolidTransitioning() || hasPendingMatches() |
| 34 | const previousIsAnyPending = usePrevious(isAnyPending) |
| 35 | |
| 36 | const isPagePending = () => isLoading() || hasPendingMatches() |
| 37 | const previousIsPagePending = usePrevious(isPagePending) |
| 38 | |
| 39 | router.startTransition = (fn: () => void | Promise<void>) => { |
| 40 | Solid.startTransition(() => { |
| 41 | startSolidTransition(fn) |
| 42 | }) |
| 43 | } |
| 44 | |
| 45 | // Subscribe to location changes |
| 46 | // and try to load the new location |
| 47 | Solid.onMount(() => { |
| 48 | const unsub = router.history.subscribe(router.load) |
| 49 | |
| 50 | const nextLocation = router.buildLocation({ |
| 51 | to: router.latestLocation.pathname, |
| 52 | search: true, |
| 53 | params: true, |
| 54 | hash: true, |
| 55 | state: true, |
| 56 | _includeValidateSearch: true, |
| 57 | }) |
| 58 | |
| 59 | // Check if the current URL matches the canonical form. |
| 60 | // Compare publicHref (browser-facing URL) for consistency with |
| 61 | // the server-side redirect check in router.beforeLoad. |
| 62 | if ( |
| 63 | trimPathRight(router.latestLocation.publicHref) !== |
| 64 | trimPathRight(nextLocation.publicHref) |
| 65 | ) { |
| 66 | router.commitLocation({ ...nextLocation, replace: true }) |
| 67 | } |
| 68 | |
| 69 | Solid.onCleanup(() => { |
nothing calls this directly
no test coverage detected