@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
1 lines • 7.08 kB
Source Map (JSON)
{"version":3,"file":"Transitioner.cjs","names":["Solid","getLocationChangeInfo","handleHashScroll","trimPathRight","isServer","useRouter","Transitioner","router","mountLoadForRouter","mounted","isLoading","createMemo","stores","get","isSolidTransitioning","startSolidTransition","useTransition","hasPending","isAnyPending","isPagePending","startTransition","fn","Promise","onMount","unsub","history","subscribe","load","nextLocation","buildLocation","to","latestLocation","pathname","search","params","hash","state","_includeValidateSearch","publicHref","commitLocation","replace","onCleanup","createRenderEffect","untrack","window","ssr","tryLoad","err","console","error","previousIsLoading","currentIsLoading","emit","type","location","resolvedLocation","createComputed","previousIsPagePending","currentIsPagePending","previousIsAnyPending","currentIsAnyPending","changeInfo","batch","status","set","hrefChanged"],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport {\n getLocationChangeInfo,\n handleHashScroll,\n trimPathRight,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\n\nexport function Transitioner() {\n const router = useRouter()\n let mountLoadForRouter = { router, mounted: false }\n const isLoading = Solid.createMemo(() => router.stores.isLoading.get())\n\n if (isServer ?? router.isServer) {\n return null\n }\n\n const [isSolidTransitioning, startSolidTransition] = Solid.useTransition()\n\n // Track pending state changes\n const hasPending = Solid.createMemo(() => router.stores.hasPending.get())\n\n const isAnyPending = Solid.createMemo(\n () => isLoading() || isSolidTransitioning() || hasPending(),\n )\n\n const isPagePending = Solid.createMemo(() => isLoading() || hasPending())\n\n router.startTransition = (fn: () => void | Promise<void>) => {\n Solid.startTransition(() => {\n startSolidTransition(fn)\n })\n }\n\n // Subscribe to location changes\n // and try to load the new location\n Solid.onMount(() => {\n const unsub = router.history.subscribe(router.load)\n\n const nextLocation = router.buildLocation({\n to: router.latestLocation.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n\n // Check if the current URL matches the canonical form.\n // Compare publicHref (browser-facing URL) for consistency with\n // the server-side redirect check in router.beforeLoad.\n if (\n trimPathRight(router.latestLocation.publicHref) !==\n trimPathRight(nextLocation.publicHref)\n ) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n Solid.onCleanup(() => {\n unsub()\n })\n })\n\n // Try to load the initial location\n Solid.createRenderEffect(() => {\n Solid.untrack(() => {\n if (\n // if we are hydrating from SSR, loading is triggered in ssr-client\n (typeof window !== 'undefined' && router.ssr) ||\n (mountLoadForRouter.router === router && mountLoadForRouter.mounted)\n ) {\n return\n }\n mountLoadForRouter = { router, mounted: true }\n const tryLoad = async () => {\n try {\n await router.load()\n } catch (err) {\n console.error(err)\n }\n }\n tryLoad()\n })\n })\n\n Solid.createRenderEffect((previousIsLoading = false) => {\n const currentIsLoading = isLoading()\n\n if (previousIsLoading && !currentIsLoading) {\n router.emit({\n type: 'onLoad',\n ...getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n ),\n })\n }\n\n return currentIsLoading\n })\n\n Solid.createComputed((previousIsPagePending = false) => {\n const currentIsPagePending = isPagePending()\n\n if (previousIsPagePending && !currentIsPagePending) {\n router.emit({\n type: 'onBeforeRouteMount',\n ...getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n ),\n })\n }\n\n return currentIsPagePending\n })\n\n Solid.createRenderEffect((previousIsAnyPending = false) => {\n const currentIsAnyPending = isAnyPending()\n\n if (previousIsAnyPending && !currentIsAnyPending) {\n const changeInfo = getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n )\n router.emit({\n type: 'onResolved',\n ...changeInfo,\n })\n\n Solid.batch(() => {\n router.stores.status.set('idle')\n router.stores.resolvedLocation.set(router.stores.location.get())\n })\n\n if (changeInfo.hrefChanged) {\n handleHashScroll(router)\n }\n }\n\n return currentIsAnyPending\n })\n\n return null\n}\n"],"mappings":";;;;;;;AASA,SAAgBM,eAAe;CAC7B,MAA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