@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
1 lines • 5.11 kB
Source Map (JSON)
{"version":3,"file":"Transitioner.cjs","names":["Solid","getLocationChangeInfo","trimPathRight","isServer","useRouter","getResolvedLocation","router","ReturnType","resolvedLocation","stores","get","href","latestLocation","state","__TSR_key","Transitioner","settleCurrent","rendered","startTransition","fn","Promise","resolve","reject","settle","undefined","fail","cause","then","onCleanup","onMount","history","subscribe","load","nextLocation","buildLocation","to","pathname","search","params","hash","_includeValidateSearch","publicHref","commitLocation","replace","ignoreBlocker","_tx","catch","console","error","Rendered","emit","type"],"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\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 if (isServer ?? router.isServer) {\n return null\n }\n\n let settleCurrent: ((rendered: boolean) => void) | undefined\n router.startTransition = (fn) => {\n settleCurrent?.(false)\n\n return new Promise((resolve, reject) => {\n const settle = (rendered: boolean) => {\n if (settleCurrent !== settle) {\n return\n }\n settleCurrent = undefined\n resolve(rendered)\n }\n const fail = (cause: unknown) => {\n if (settleCurrent !== settle) {\n return\n }\n settleCurrent = undefined\n reject(cause)\n }\n settleCurrent = settle\n\n void Solid.startTransition(() => {\n // A newer publication may supersede this deferred callback.\n if (settleCurrent === settle) {\n try {\n fn()\n } catch (cause) {\n fail(cause)\n }\n }\n }).then(() => settle(true), fail)\n })\n }\n\n Solid.onCleanup(() => {\n settleCurrent?.(false)\n })\n\n // Subscribe to location changes\n // and try to load the new location\n Solid.onMount(() => {\n Solid.onCleanup(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) consistently with server\n // canonicalization.\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\n }\n\n if (!getResolvedLocation(router) && !router._tx) {\n router.load().catch(console.error)\n }\n })\n\n return null\n}\n\nexport function Rendered() {\n const router = useRouter()\n Solid.onMount(() => {\n const resolvedLocation = getResolvedLocation(router)\n if (resolvedLocation) {\n router.emit({\n type: 'onRendered',\n ...getLocationChangeInfo(resolvedLocation, resolvedLocation),\n })\n }\n })\n return null\n}\n"],"mappings":";;;;;;;AAKA,SAASK,oBAAoBC,QAAsC;CACjE,MAAME,mBAAmBF,OAAOG,OAAOD,iBAAiBE,IAAI;CAC5D,IACEF,kBAAkBG,SAASL,OAAOM,eAAeD,QACjDH,iBAAiBK,MAAMC,cAAcR,OAAOM,eAAeC,MAAMC,WAEjE,OAAON;AAGX;AAEA,SAAgBO,eAAe;CAC7B,MAAMT,SAASF,kBAAAA,UAAU;CAEzB,IAAID,+BAAAA,YAAYG,OAAOH,UACrB,OAAO;CAGT,IAAIa;CACJV,OAAOY,mBAAmBC,OAAO;EAC/BH,gBAAgB,KAAK;EAErB,OAAO,IAAII,SAASC,SAASC,WAAW;GACtC,MAAMC,UAAUN,aAAsB;IACpC,IAAID,kBAAkBO,QACpB;IAEFP,gBAAgBQ,KAAAA;IAChBH,QAAQJ,QAAQ;GAClB;GACA,MAAMQ,QAAQC,UAAmB;IAC/B,IAAIV,kBAAkBO,QACpB;IAEFP,gBAAgBQ,KAAAA;IAChBF,OAAOI,KAAK;GACd;GACAV,gBAAgBO;GAEhB,SAAWL,sBAAsB;IAE/B,IAAIF,kBAAkBO,QACpB,IAAI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