{"version":3,"file":"Transitioner.cjs","names":[],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { getLocationChangeInfo, trimPathRight } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\n\nfunction getResolvedLocation(router: ReturnType<typeof useRouter>) {\n  const resolvedLocation = router.stores.resolvedLocation.get()\n  if (\n    resolvedLocation?.href === router.latestLocation.href &&\n    resolvedLocation.state.__TSR_key === router.latestLocation.state.__TSR_key\n  ) {\n    return resolvedLocation\n  }\n  return\n}\n\nexport function Transitioner() {\n  const router = useRouter()\n\n  // No server early-return here: Solid 2 derives hydration keys from the\n  // reactive owner tree, so the server must register the same `onSettled`\n  // slot as the client or every key after this component shifts by one.\n  // The callback itself never runs on the server.\n  router.startTransition = async (fn) => {\n    const result = Solid.runWithOwner(null, fn)\n    try {\n      Solid.flush()\n    } catch {\n      // Solid auto-flushes when this is called from a reactive context.\n    }\n    await result\n    await new Promise<void>((resolve) => queueMicrotask(resolve))\n    return true\n  }\n\n  Solid.onSettled(() => {\n    const unsub = router.history.subscribe(() => {\n      queueMicrotask(() => router.load().catch(console.error))\n    })\n\n    // The URL may have changed synchronously between render and settlement.\n    router.updateLatestLocation()\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    if (\n      trimPathRight(router.latestLocation.publicHref) !==\n      trimPathRight(nextLocation.publicHref)\n    ) {\n      router.commitLocation({\n        ...nextLocation,\n        replace: true,\n        ignoreBlocker: true,\n      })\n      return unsub\n    }\n\n    if (!getResolvedLocation(router) && !router._tx) {\n      queueMicrotask(() => router.load().catch(console.error))\n    }\n\n    return unsub\n  })\n\n  return null\n}\n\nexport function Rendered() {\n  const router = useRouter()\n  Solid.onSettled(() => {\n    const resolvedLocation = getResolvedLocation(router)\n    if (resolvedLocation) {\n      router.emit({\n        type: 'onRendered',\n        ...getLocationChangeInfo(resolvedLocation, res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