{"version":3,"file":"Transitioner.cjs","names":["Solid","getLocationChangeInfo","handleHashScroll","trimPathRight","isServer","useRouter","Transitioner","router","mountLoadForRouter","mounted","isLoading","createMemo","stores","state","isSolidTransitioning","startSolidTransition","useTransition","hasPendingMatches","isAnyPending","isPagePending","startTransition","fn","Promise","onMount","unsub","history","subscribe","load","nextLocation","buildLocation","to","latestLocation","pathname","search","params","hash","_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","setState","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.state)\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 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.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.state,\n          router.stores.resolvedLocation.state,\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.state,\n          router.stores.resolvedLocation.state,\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.state,\n        router.stores.resolvedLocation.state,\n      )\n      router.emit({\n        type: 'onResolved',\n        ...changeInfo,\n      })\n\n      Solid.batch(() => {\n        router.stores.status.setState(() => 'idle')\n        router.stores.resolvedLocation.setState(\n          () => router.stores.location.state,\n        )\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,MAAMC,SAASF,kBAAAA,WAAW;CAC1B,IAAIG,qBAAqB;EAAED;EAAQE,SAAS;EAAO;CACnD,MAAMC,YAAYV,SAAMW,iBAAiBJ,OAAOK,OAAOF,UAAUG,MAAM;AAEvE,KAAIT,+BAAAA,YAAYG,OAAOH,SACrB,QAAO;CAGT,MAAM,CAACU,sBAAsBC,wBAAwBf,SAAMgB,eAAe;CAG1E,MAAMC,oBAAoBjB,SAAMW,iBACxBJ,OAAOK,OAAOK,kBAAkBJ,MACvC;CAED,MAAMK,eAAelB,SAAMW,iBACnBD,WAAW,IAAII,sBAAsB,IAAIG,mBACjD,CAAC;CAED,MAAME,gBAAgBnB,SAAMW,iBACpBD,WAAW,IAAIO,mBACvB,CAAC;AAEDV,QAAOa,mBAAmBC,OAAmC;AAC3DrB,WAAMoB,sBAAsB;AAC1BL,wBAAqBM,GAAG;IACxB;;AAKJrB,UAAMuB,cAAc;EAClB,MAAMC,QAAQjB,OAAOkB,QAAQC,UAAUnB,OAAOoB,KAAK;EAEnD,MAAMC,eAAerB,OAAOsB,cAAc;GACxCC,IAAIvB,OAAOwB,eAAeC;GAC1BC,QAAQ;GACRC,QAAQ;GACRC,MAAM;GACNtB,OAAO;GACPuB,wBAAwB;GACzB,CAAC;AAKF,OAAA,GAAA,sBAAA,eACgB7B,OAAOwB,eAAeM,WAAW,MAAA,GAAA,sBAAA,eACjCT,aAAaS,WAAW,CAEtC9B,QAAO+B,eAAe;GAAE,GAAGV;GAAcW,SAAS;GAAM,CAAC;AAG3DvC,WAAMwC,gBAAgB;AACpBhB,UAAO;IACP;GACF;AAGFxB,UAAMyC,yBAAyB;AAC7BzC,WAAM0C,cAAc;AAClB,OAEG,OAAOC,WAAW,eAAepC,OAAOqC,OACxCpC,mBAAmBD,WAAWA,UAAUC,mB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