{"version":3,"file":"Transitioner.cjs","names":["Solid","getLocationChangeInfo","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"],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { getLocationChangeInfo, trimPathRight } 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\n    return currentIsAnyPending\n  })\n\n  return null\n}\n"],"mappings":";;;;;;;AAKA,SAAgBK,eAAe;CAC7B,MAAMC,SAASF,kBA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