{"version":3,"file":"Transitioner.cjs","names":["Solid","getLocationChangeInfo","trimPathRight","useRouter","ParsedLocation","handleHashScrollWithLocation","_router","location","document","querySelector","hashScrollIntoViewOptions","state","__hashScrollIntoViewOptions","hash","el","getElementById","scrollIntoView","Transitioner","router","mountLoadForRouter","mounted","isLoading","createMemo","stores","isSolidTransitioning","hasPendingMatches","isAnyPending","isPagePending","startTransition","fn","Promise","runWithOwner","flush","onSettled","unsub","history","subscribe","queueMicrotask","load","updateLatestLocation","nextLocation","buildLocation","to","latestLocation","pathname","search","params","_includeValidateSearch","publicHref","commitLocation","replace","window","ssr","tryLoad","err","console","error","createRenderEffect","resolvedLocation","const","currentIsLoading","currentIsPagePending","currentIsAnyPending","loc","resolvedLoc","prev","previousIsLoading","previousIsPagePending","previousIsAnyPending","emit","type","changeInfo","batch","status","setState","hrefChanged"],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { getLocationChangeInfo, trimPathRight } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport type { ParsedLocation } from '@tanstack/router-core'\n\n/**\n * Inline version of handleHashScroll that accepts a pre-captured location\n * to avoid reading router.stores.location.state inside an effect callback\n * (which would trigger a Solid v2 reactive warning).\n */\nfunction handleHashScrollWithLocation(_router: any, location: ParsedLocation) {\n  if (typeof document !== 'undefined' && (document as any).querySelector) {\n    const hashScrollIntoViewOptions =\n      location.state.__hashScrollIntoViewOptions ?? true\n\n    if (hashScrollIntoViewOptions && location.hash !== '') {\n      const el = document.getElementById(location.hash)\n      if (el) {\n        el.scrollIntoView(hashScrollIntoViewOptions)\n      }\n    }\n  }\n}\n\nexport function Transitioner() {\n  const router = useRouter()\n  let mountLoadForRouter = { router, mounted: false }\n  const isLoading = Solid.createMemo(() => router.stores.isLoading.state)\n\n  const [isSolidTransitioning] = [() => false]\n\n  // Track pending state changes\n  const hasPendingMatches = Solid.createMemo(\n    () => router.stores.hasPendingMatches.state,\n  )\n\n  const isAnyPending = Solid.createMemo(\n    () => isLoading() || isSolidTransitioning() || hasPendingMatches(),\n  )\n\n  const isPagePending = Solid.createMemo(\n    () => isLoading() || hasPendingMatches(),\n  )\n\n  router.startTransition = (fn: () => void | Promise<void>) => {\n    Solid.runWithOwner(null, fn)\n    try {\n      Solid.flush()\n    } catch {\n      // flush() throws inside reactive contexts — Solid auto-flushes there\n    }\n  }\n\n  // Subscribe to location changes\n  // and try to load the new location\n  Solid.onSettled(() => {\n    const unsub = router.history.subscribe(() => {\n      queueMicrotask(() => router.load())\n    })\n\n    // Refresh latestLocation from the current browser URL before comparing.\n    // The URL may have been changed synchronously (e.g. via replaceState) after\n    // render() but before this effect ran, so we must not use the stale\n    // render-time location here.\n    router.updateLatestLocation()\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    return () => {\n      unsub()\n    }\n  })\n\n  // Try to load the initial location\n  // In Solid v2, signal updates inside onSettled cannot be flushed\n  // synchronously (flush() throws). router.load() sets signals via batch(),\n  // and the code that runs immediately after needs those values committed.\n  // By deferring to queueMicrotask, the load runs outside the reactive\n  // scheduling frame so flush() works correctly.\n  Solid.onSettled(() => {\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    queueMicrotask(() => {\n      const tryLoad = async () => {\n        try {\n          await router.load()\n        } catch (err) {\n          console.error(err)\n        }\n      }\n      tryLoad()\n    })\n  })\n  Solid.createRenderEffect(\n    () =>\n      [\n        isLoading(),\n        isPagePending(),\n        isAnyPending(),\n        router.stores.location.state,\n        router.stores.resolvedLocation.state,\n      ] as const,\n    (\n      [\n        currentIsLoading,\n        currentIsPagePending,\n        currentIsAnyPending,\n        loc,\n        resolvedLoc,\n      ],\n      prev,\n    ) => {\n      // Guard: if location state isn't available yet, skip all event emissions\n      if (!loc) return\n\n      const previousIsLoading = prev?.[0]\n      const previousIsPagePending = prev?.[1]\n      const previousIsAnyPending = prev?.[2]\n\n      // onLoad: when the router finishes loading\n      if (previousIsLoading && !currentIsLoading) {\n        router.emit({\n          type: 'onLoad',\n          ...getLocationChangeInfo(loc, resolvedLoc),\n        })\n      }\n\n      // onBeforeRouteMount: must fire before onResolved\n      if (previousIsPagePending && !currentIsPagePending) {\n        router.emit({\n          type: 'onBeforeRouteMount',\n          ...getLocationChangeInfo(loc, resolvedLoc),\n        })\n      }\n\n      // onResolved: fires after onBeforeRouteMount\n      if (previousIsAnyPending && !currentIsAnyPending) {\n        const changeInfo = getLocationChangeInfo(loc, resolvedLoc)\n        router.emit({\n          type: 'onResolved',\n          ...changeInfo,\n        })\n\n        Solid.runWithOwner(null, () => {\n          router.batch(() => {\n            router.stores.status.setState(() => 'idle')\n            // Use `loc` from the source tuple to avoid reading\n            // router.stores.location.state inside the effect callback\n            router.stores.resolvedLocation.setState(() => loc)\n          })\n        })\n\n        if (changeInfo.hrefChanged) {\n          // Pass the already-captured location to avoid a reactive read\n          // inside the effect callback (handleHashScroll would otherwise\n          // read router.stores.location.state which triggers a warning)\n          handleHashScrollWithLocation(router, loc)\n        }\n      }\n    },\n  )\n\n  return null\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAASK,6BAA6BC,SAAcC,UAA0B;AAC5E,KAAI,OAAOC,aAAa,eAAgBA,SAAiBC,eAAe;EACtE,MAAMC,4BACJH,SAASI,MAAMC,+BAA+B;AAEhD,MAAIF,6BAA6BH,SAASM,SAAS,IAAI;GACrD,MAAMC,KAAKN,SAASO,eAAeR,S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