{"version":3,"file":"Transitioner.cjs","names":[],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { getLocationChangeInfo, trimPathRight } from '@tanstack/router-core'\nimport { useLayoutEffect } from './utils'\nimport { useRouter } from './useRouter'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport function settleOwner(\n  owner: NonNullable<AnyRouter['_rendered']>,\n  rendered: boolean,\n) {\n  const settle = owner[1 /* settle */]\n  owner.length = 0\n  settle?.(rendered)\n}\n\nexport function Transitioner({\n  t,\n}: {\n  t: React.Dispatch<React.SetStateAction<AnyRouter | undefined>>\n}) {\n  const router = useRouter()\n  const acknowledgement = (router._rendered ??= [])\n  const mounted =\n    process.env.NODE_ENV !== 'production'\n      ? // eslint-disable-next-line react-hooks/rules-of-hooks\n        React.useRef(false)\n      : undefined\n\n  router.startTransition = (fn, expected) =>\n    new Promise((resolve) => {\n      settleOwner(acknowledgement, false)\n      acknowledgement.push(expected, resolve)\n      t(router)\n      React.startTransition(fn)\n    })\n\n  // Subscribe before canonicalizing so the initial URL has exactly one load.\n  useLayoutEffect(() => {\n    const unsub = router.history.subscribe(router.load)\n\n    if (mounted?.current) {\n      return unsub\n    }\n    if (mounted) {\n      mounted.current = true\n    }\n\n    router.updateLatestLocation()\n    const location = router.latestLocation\n    const nextLocation = router.buildLocation({\n      to: location.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) consistently with server\n    // canonicalization.\n    if (\n      trimPathRight(location.publicHref) !==\n      trimPathRight(nextLocation.publicHref)\n    ) {\n      router.commitLocation({\n        ...nextLocation,\n        replace: true,\n        ignoreBlocker: true,\n      })\n      return unsub\n    }\n\n    const resolvedLocation = router.stores.resolvedLocation.get()\n    if (\n      resolvedLocation?.href === location.href &&\n      resolvedLocation.state.__TSR_key === location.state.__TSR_key\n    ) {\n      acknowledgement.push(router.stores.matches.get(), (rendered) => {\n        if (rendered) {\n          router.emit({\n            type: 'onRendered',\n            ...getLocationChangeInfo(resolvedLocation, resolvedLocation),\n          })\n        }\n      })\n    } else if (!router._tx) {\n      router.load({ sync: true }).catch(console.error)\n    }\n\n    return unsub\n    // `mounted` exists only in development and is a stable ref when present.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [router, router.history])\n\n  return null\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,YACd,OACA,UACA;CACA,MAAM,SAAS,MAAM;CACrB,MAAM,SAAS;CACf,SAAS,QAAQ;AACnB;AAEA,SAAgB,aAAa,EAC3B,KAGC;CACD,MAAM,SAAS,kBAAA,UAAU;CACzB,MAAM,kBAAmB,OAAO,cAAc,CAAC;CAC/C,MAAM,UAAA,QAAA,IAAA,aACqB,eAErB,MAAM,OAAO,KAAK,IAClB,KAAA;CAEN,OAAO,mBAAmB,IAAI,aAC5B,IAAI,SAAS,YAAY;EACvB,YAAY,iBAAiB,KAAK;EAClC,gBAAgB,KAAK,UAAU,OAAO;EACtC,EAAE,MAAM;EACR,MAAM,gBAAgB,EAAE;CAC1B,CAAC;CAGH,cAAA,sBAAsB;EACpB,MAAM,QAAQ,OAAO,QAAQ,UAAU,OAAO,IAAI;EAElD,IAAI,SAAS,SACX,OAAO;EAET,IAAI,SACF,QAAQ,UAAU;EAGpB,OAAO,qBAAqB;EAC5B,MAAM,WAAW,OAAO;EACxB,MAAM,eAAe,OAAO,cAAc;GACxC,IAAI,SAAS;GACb,QAAQ;GACR,QAAQ;GACR,MAAM;GACN,OAAO;GACP,wBAAwB;EAC1B,CAAC;EAKD,KAAA,GAAA,sBAAA,eACgB,SAAS,UAAU,OAAA,GAAA,sBAAA,eACnB,aAAa,UAAU,GACrC;GACA,OAAO,eAAe;IACpB,GAAG;IACH,SAAS;IACT,eAAe;GACjB,CAAC;GACD,OAAO;EACT;EAEA,MAAM,mBAAmB,OAAO,OAAO,iBAAiB,IAAI;EAC5D,IACE,kBA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