You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@tanstack/router

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1-beta.53 to 0.0.1-beta.55

5

build/cjs/router.js

@@ -109,6 +109,7 @@ /**

this.history = this.options.history ?? (isServer ? history.createMemoryHistory() : history.createBrowserHistory());
const parsedLocation = this.#parseLocation();
this.store.setState(s => ({
...s,
latestLocation: this.#parseLocation(),
currentLocation: s.latestLocation
latestLocation: parsedLocation,
currentLocation: parsedLocation
}));

@@ -115,0 +116,0 @@ this.#unsubHistory = this.history.listen(() => {

@@ -792,6 +792,7 @@ /**

this.history = this.options.history ?? (isServer ? createMemoryHistory() : createBrowserHistory());
const parsedLocation = this.#parseLocation();
this.store.setState(s => ({
...s,
latestLocation: this.#parseLocation(),
currentLocation: s.latestLocation
latestLocation: parsedLocation,
currentLocation: parsedLocation
}));

@@ -798,0 +799,0 @@ this.#unsubHistory = this.history.listen(() => {

234

build/stats-react.json

@@ -11,3 +11,3 @@ {

"name": "node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
"uid": "da8f-250"
"uid": "33c2-32"
},

@@ -21,39 +21,39 @@ {

{
"uid": "da8f-252",
"uid": "33c2-34",
"name": "history.ts"
},
{
"uid": "da8f-254",
"uid": "33c2-36",
"name": "utils.ts"
},
{
"uid": "da8f-256",
"uid": "33c2-38",
"name": "path.ts"
},
{
"uid": "da8f-258",
"uid": "33c2-40",
"name": "qss.ts"
},
{
"uid": "da8f-260",
"uid": "33c2-42",
"name": "route.ts"
},
{
"uid": "da8f-262",
"uid": "33c2-44",
"name": "routeConfig.ts"
},
{
"uid": "da8f-266",
"uid": "33c2-48",
"name": "routeMatch.ts"
},
{
"uid": "da8f-268",
"uid": "33c2-50",
"name": "searchParams.ts"
},
{
"uid": "da8f-270",
"uid": "33c2-52",
"name": "router.ts"
},
{
"uid": "da8f-272",
"uid": "33c2-54",
"name": "index.ts"

@@ -65,3 +65,3 @@ }

"name": "store/build/esm/index.js",
"uid": "da8f-264"
"uid": "33c2-46"
}

@@ -76,80 +76,80 @@ ]

"nodeParts": {
"da8f-250": {
"33c2-32": {
"renderedLength": 199,
"gzipLength": 134,
"brotliLength": 0,
"mainUid": "da8f-249"
"mainUid": "33c2-31"
},
"da8f-252": {
"33c2-34": {
"renderedLength": 4236,
"gzipLength": 1085,
"brotliLength": 0,
"mainUid": "da8f-251"
"mainUid": "33c2-33"
},
"da8f-254": {
"33c2-36": {
"renderedLength": 2572,
"gzipLength": 950,
"brotliLength": 0,
"mainUid": "da8f-253"
"mainUid": "33c2-35"
},
"da8f-256": {
"33c2-38": {
"renderedLength": 5601,
"gzipLength": 1328,
"brotliLength": 0,
"mainUid": "da8f-255"
"mainUid": "33c2-37"
},
"da8f-258": {
"33c2-40": {
"renderedLength": 1395,
"gzipLength": 558,
"brotliLength": 0,
"mainUid": "da8f-257"
"mainUid": "33c2-39"
},
"da8f-260": {
"33c2-42": {
"renderedLength": 415,
"gzipLength": 208,
"brotliLength": 0,
"mainUid": "da8f-259"
"mainUid": "33c2-41"
},
"da8f-262": {
"33c2-44": {
"renderedLength": 1261,
"gzipLength": 478,
"brotliLength": 0,
"mainUid": "da8f-261"
"mainUid": "33c2-43"
},
"da8f-264": {
"33c2-46": {
"renderedLength": 1341,
"gzipLength": 493,
"brotliLength": 0,
"mainUid": "da8f-263"
"mainUid": "33c2-45"
},
"da8f-266": {
"33c2-48": {
"renderedLength": 4823,
"gzipLength": 1337,
"brotliLength": 0,
"mainUid": "da8f-265"
"mainUid": "33c2-47"
},
"da8f-268": {
"33c2-50": {
"renderedLength": 1387,
"gzipLength": 483,
"brotliLength": 0,
"mainUid": "da8f-267"
"mainUid": "33c2-49"
},
"da8f-270": {
"renderedLength": 24107,
"gzipLength": 5633,
"33c2-52": {
"renderedLength": 24154,
"gzipLength": 5637,
"brotliLength": 0,
"mainUid": "da8f-269"
"mainUid": "33c2-51"
},
"da8f-272": {
"33c2-54": {
"renderedLength": 0,
"gzipLength": 0,
"brotliLength": 0,
"mainUid": "da8f-271"
"mainUid": "33c2-53"
}
},
"nodeMetas": {
"da8f-249": {
"33c2-31": {
"id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
"moduleParts": {
"index.production.js": "da8f-250"
"index.production.js": "33c2-32"
},

@@ -159,16 +159,16 @@ "imported": [],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-261"
"uid": "33c2-43"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-251": {
"33c2-33": {
"id": "/packages/router/src/history.ts",
"moduleParts": {
"index.production.js": "da8f-252"
"index.production.js": "33c2-34"
},

@@ -178,13 +178,13 @@ "imported": [],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-253": {
"33c2-35": {
"id": "/packages/router/src/utils.ts",
"moduleParts": {
"index.production.js": "da8f-254"
"index.production.js": "33c2-36"
},

@@ -194,20 +194,20 @@ "imported": [],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-255"
"uid": "33c2-37"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-255": {
"33c2-37": {
"id": "/packages/router/src/path.ts",
"moduleParts": {
"index.production.js": "da8f-256"
"index.production.js": "33c2-38"
},
"imported": [
{
"uid": "da8f-253"
"uid": "33c2-35"
}

@@ -217,16 +217,16 @@ ],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-261"
"uid": "33c2-43"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-257": {
"33c2-39": {
"id": "/packages/router/src/qss.ts",
"moduleParts": {
"index.production.js": "da8f-258"
"index.production.js": "33c2-40"
},

@@ -236,13 +236,13 @@ "imported": [],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-267"
"uid": "33c2-49"
}
]
},
"da8f-259": {
"33c2-41": {
"id": "/packages/router/src/route.ts",
"moduleParts": {
"index.production.js": "da8f-260"
"index.production.js": "33c2-42"
},

@@ -252,20 +252,20 @@ "imported": [],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-261": {
"33c2-43": {
"id": "/packages/router/src/routeConfig.ts",
"moduleParts": {
"index.production.js": "da8f-262"
"index.production.js": "33c2-44"
},
"imported": [
{
"uid": "da8f-249"
"uid": "33c2-31"
},
{
"uid": "da8f-255"
"uid": "33c2-37"
}

@@ -275,10 +275,10 @@ ],

{
"uid": "da8f-271"
"uid": "33c2-53"
}
]
},
"da8f-263": {
"33c2-45": {
"id": "/packages/store/build/esm/index.js",
"moduleParts": {
"index.production.js": "da8f-264"
"index.production.js": "33c2-46"
},

@@ -288,17 +288,17 @@ "imported": [],

{
"uid": "da8f-265"
"uid": "33c2-47"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-265": {
"33c2-47": {
"id": "/packages/router/src/routeMatch.ts",
"moduleParts": {
"index.production.js": "da8f-266"
"index.production.js": "33c2-48"
},
"imported": [
{
"uid": "da8f-263"
"uid": "33c2-45"
}

@@ -308,17 +308,17 @@ ],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-267": {
"33c2-49": {
"id": "/packages/router/src/searchParams.ts",
"moduleParts": {
"index.production.js": "da8f-268"
"index.production.js": "33c2-50"
},
"imported": [
{
"uid": "da8f-257"
"uid": "33c2-39"
}

@@ -328,38 +328,38 @@ ],

{
"uid": "da8f-271"
"uid": "33c2-53"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
}
]
},
"da8f-269": {
"33c2-51": {
"id": "/packages/router/src/router.ts",
"moduleParts": {
"index.production.js": "da8f-270"
"index.production.js": "33c2-52"
},
"imported": [
{
"uid": "da8f-263"
"uid": "33c2-45"
},
{
"uid": "da8f-249"
"uid": "33c2-31"
},
{
"uid": "da8f-255"
"uid": "33c2-37"
},
{
"uid": "da8f-259"
"uid": "33c2-41"
},
{
"uid": "da8f-265"
"uid": "33c2-47"
},
{
"uid": "da8f-267"
"uid": "33c2-49"
},
{
"uid": "da8f-253"
"uid": "33c2-35"
},
{
"uid": "da8f-251"
"uid": "33c2-33"
}

@@ -369,50 +369,50 @@ ],

{
"uid": "da8f-271"
"uid": "33c2-53"
}
]
},
"da8f-271": {
"33c2-53": {
"id": "/packages/router/src/index.ts",
"moduleParts": {
"index.production.js": "da8f-272"
"index.production.js": "33c2-54"
},
"imported": [
{
"uid": "da8f-249"
"uid": "33c2-31"
},
{
"uid": "da8f-251"
"uid": "33c2-33"
},
{
"uid": "da8f-273"
"uid": "33c2-55"
},
{
"uid": "da8f-274"
"uid": "33c2-56"
},
{
"uid": "da8f-255"
"uid": "33c2-37"
},
{
"uid": "da8f-257"
"uid": "33c2-39"
},
{
"uid": "da8f-259"
"uid": "33c2-41"
},
{
"uid": "da8f-261"
"uid": "33c2-43"
},
{
"uid": "da8f-275"
"uid": "33c2-57"
},
{
"uid": "da8f-265"
"uid": "33c2-47"
},
{
"uid": "da8f-269"
"uid": "33c2-51"
},
{
"uid": "da8f-267"
"uid": "33c2-49"
},
{
"uid": "da8f-253"
"uid": "33c2-35"
}

@@ -423,3 +423,3 @@ ],

},
"da8f-273": {
"33c2-55": {
"id": "/packages/router/src/frameworks.ts",

@@ -430,7 +430,7 @@ "moduleParts": {},

{
"uid": "da8f-271"
"uid": "33c2-53"
}
]
},
"da8f-274": {
"33c2-56": {
"id": "/packages/router/src/link.ts",

@@ -441,7 +441,7 @@ "moduleParts": {},

{
"uid": "da8f-271"
"uid": "33c2-53"
}
]
},
"da8f-275": {
"33c2-57": {
"id": "/packages/router/src/routeInfo.ts",

@@ -452,3 +452,3 @@ "moduleParts": {},

{
"uid": "da8f-271"
"uid": "33c2-53"
}

@@ -455,0 +455,0 @@ ]

@@ -852,6 +852,7 @@ /**

this.history = this.options.history ?? (isServer ? createMemoryHistory() : createBrowserHistory());
const parsedLocation = this.#parseLocation();
this.store.setState(s => ({
...s,
latestLocation: this.#parseLocation(),
currentLocation: s.latestLocation
latestLocation: parsedLocation,
currentLocation: parsedLocation
}));

@@ -858,0 +859,0 @@ this.#unsubHistory = this.history.listen(() => {

@@ -22,3 +22,3 @@ /**

*/
class C{listeners=new Set;batching=!1;queue=[];constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=t=>{const e=this.state;this.state=this.options?.updateFn?this.options.updateFn(e)(t):t(e),this.queue.push((()=>{this.listeners.forEach((t=>t(this.state,e))),this.options?.onUpdate?.(this.state,e)})),this.#t()};#t=()=>{this.batching||(this.queue.forEach((t=>t())),this.queue=[])};batch=t=>{this.batching=!0,t(),this.batching=!1,this.#t()}}const A=["component","errorComponent","pendingComponent"];class I{abortController=new AbortController;onLoaderDataListeners=new Set;constructor(t,e,s){Object.assign(this,{route:e,router:t,id:s.id,pathname:s.pathname,params:s.params,store:new C({updatedAt:0,routeSearch:{},search:{},status:"idle"})}),this.#e()||this.store.setState((t=>({...t,status:"success"})))}cancel=()=>{this.abortController?.abort()};load=async()=>{"pending"!==this.store.state.status&&await this.fetch()};#s="";fetch=async()=>(this.__loadPromise=Promise.resolve().then((async()=>{const t=""+Date.now()+Math.random();this.#s=t;const e=()=>t!==this.#s?this.__loadPromise:void 0;let s;this.store.batch((()=>{"idle"===this.store.state.status&&this.store.setState((t=>({...t,status:"pending"})))}));const a=(async()=>{await Promise.all(A.map((async t=>{const e=this.route.options[t];this[t]?.preload&&(this[t]=await this.router.options.loadComponent(e))})))})(),o=Promise.resolve().then((()=>{if(this.route.options.onLoad)return this.route.options.onLoad({params:this.params,search:this.store.state.search,signal:this.abortController.signal})}));try{if(await a,await o,s=e())return await s;this.store.setState((t=>({...t,error:void 0,status:"success",updatedAt:Date.now()})))}catch(t){this.store.setState((e=>({...e,error:t,status:"error",updatedAt:Date.now()})))}finally{delete this.__loadPromise}})),this.__loadPromise);#e=()=>!(!this.route.options.onLoad&&!A.some((t=>this.route.options[t]?.preload)));__setParentMatch=t=>{!this.parentMatch&&t&&(this.parentMatch=t)};__validate=()=>{const t=this.parentMatch?.store.state.search??this.router.store.state.latestLocation.search;try{let e=("object"==typeof this.route.options.validateSearch?this.route.options.validateSearch.parse:this.route.options.validateSearch)?.(t)??{};this.store.setState((s=>({...s,routeSearch:e,search:{...t,...e}}))),A.map((async t=>{const e=this.route.options[t];"function"!=typeof this[t]&&(this[t]=e)}))}catch(t){console.error(t);const e=new Error("Invalid search params found",{cause:t});return e.code="INVALID_SEARCH_PARAMS",void this.store.setState((t=>({...t,status:"error",error:e})))}}}const F=T(JSON.parse),k=j(JSON.stringify);function T(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let s=E(e);for(let e in s){const a=s[e];if("string"==typeof a)try{s[e]=t(a)}catch(t){}}return s}}function j(t){return e=>{(e={...e})&&Object.keys(e).forEach((s=>{const a=e[s];if(void 0===a||void 0===a)delete e[s];else if(a&&"object"==typeof a&&null!==a)try{e[s]=t(a)}catch(t){}}));const s=P(e).toString();return s?`?${s}`:""}}const O=async({router:t,routeMatch:e})=>{const s=t.buildNext({to:".",search:t=>({...t??{},__data:{matchId:e.id}})}),a=await fetch(s.href,{method:"GET",signal:e.abortController.signal});if(a.ok)return a.json();throw new Error("Failed to fetch match data")};const D="undefined"==typeof window||!window.document.createElement;function H(){return{status:"idle",latestLocation:null,currentLocation:null,currentMatches:[],lastUpdated:Date.now()}}t.Route=M,t.RouteMatch=I,t.Router=class{#a;startedLoadingAt=Date.now();resolveNavigation=()=>{};constructor(t){this.options={defaultPreloadDelay:50,context:void 0,...t,stringifySearch:t?.stringifySearch??k,parseSearch:t?.parseSearch??F,fetchServerDataFn:t?.fetchServerDataFn??O},this.store=new C(H()),this.basepath="",this.update(t),this.options.Router?.(this)}reset=()=>{this.store.setState((t=>Object.assign(t,H())))};mount=()=>{if(!D){this.store.state.currentMatches.length||this.load();const t="visibilitychange",e="focus";return window.addEventListener&&(window.addEventListener(t,this.#o,!1),window.addEventListener(e,this.#o,!1)),()=>{window.removeEventListener&&(window.removeEventListener(t,this.#o),window.removeEventListener(e,this.#o))}}return()=>{}};update=t=>{Object.assign(this.options,t),(!this.history||this.options.history&&this.options.history!==this.history)&&(this.#a&&this.#a(),this.history=this.options.history??(D?r():o()),this.store.setState((t=>({...t,latestLocation:this.#r(),currentLocation:t.latestLocation}))),this.#a=this.history.listen((()=>{this.load(this.#r(this.store.state.latestLocation))})));const{basepath:e,routeConfig:s}=this.options;return this.basepath=`/${w(e??"")??""}`,s&&(this.routesById={},this.routeTree=this.#i(s)),this};buildNext=t=>{const e=this.#n(t),s=this.matchRoutes(e.pathname),a=s.map((t=>t.route.options.preSearchFilters??[])).flat().filter(Boolean),o=s.map((t=>t.route.options.postSearchFilters??[])).flat().filter(Boolean);return this.#n({...t,__preSearchFilters:a,__postSearchFilters:o})};cancelMatches=()=>{[...this.store.state.currentMatches,...this.store.state.pendingMatches||[]].forEach((t=>{t.cancel()}))};load=async t=>{let s=Date.now();const a=s;let o;this.startedLoadingAt=a,this.cancelMatches(),this.store.batch((()=>{t&&this.store.setState((e=>({...e,latestLocation:t}))),o=this.matchRoutes(this.store.state.latestLocation.pathname,{strictParseParams:!0}),this.store.setState((t=>({...t,status:"pending",pendingMatches:o,pendingLocation:this.store.state.latestLocation})))}));try{await this.loadMatches(o)}catch(t){console.warn(t),e(!1)}if(this.startedLoadingAt!==a)return this.navigationPromise;const r=this.store.state.currentMatches,i=[],n=[];r.forEach((t=>{o.find((e=>e.id===t.id))?n.push(t):i.push(t)}));const h=o.filter((t=>!r.find((e=>e.id===t.id))));s=Date.now(),i.forEach((t=>{t.__onExit?.({params:t.params,search:t.store.state.routeSearch}),"error"===t.store.state.status&&this.store.setState((t=>({...t,status:"idle",error:void 0})))})),n.forEach((t=>{t.route.options.onTransition?.({params:t.params,search:t.store.state.routeSearch})})),h.forEach((t=>{t.__onExit=t.route.options.onLoaded?.({params:t.params,search:t.store.state.search})})),this.store.setState((t=>({...t,status:"idle",currentLocation:this.store.state.latestLocation,currentMatches:o,pendingLocation:void 0,pendingMatches:void 0}))),this.options.onRouteChange?.(),this.resolveNavigation()};getRoute=t=>{const s=this.routesById[t];return e(s),s};loadRoute=async(t=this.store.state.latestLocation)=>{const e=this.buildNext(t),s=this.matchRoutes(e.pathname,{strictParseParams:!0});return await this.loadMatches(s),s};preloadRoute=async(t=this.store.state.latestLocation)=>{const e=this.buildNext(t),s=this.matchRoutes(e.pathname,{strictParseParams:!0});return await this.loadMatches(s,{preload:!0}),s};matchRoutes=(t,e)=>{const s=[];if(!this.routeTree)return s;const a=[...this.store.state.currentMatches,...this.store.state.pendingMatches??[]],o=async r=>{let i=h(s)?.params??{};const n=this.options.filterRoutes?.(r)??r;let c=[];const u=(s,a)=>(a.some((a=>{if(!a.path&&a.childRoutes?.length)return u([...c,a],a.childRoutes);const o=!("/"===a.path&&!a.childRoutes?.length),r=S(this.basepath,t,{to:a.fullPath,fuzzy:o,caseSensitive:a.options.caseSensitive??this.options.caseSensitive});if(r){let t;try{t=a.options.parseParams?.(r)??r}catch(t){if(e?.strictParseParams)throw t}i={...i,...t}}return r&&(c=[...s,a]),!!c.length})),!!c.length);if(u([],n),!c.length)return;c.forEach((t=>{const e=L(t.path,i),o=L(t.id,i,!0),r=a.find((t=>t.id===o))||new I(this,t,{id:o,params:i,pathname:f([this.basepath,e])});s.push(r)}));const l=h(c);l.childRoutes?.length&&o(l.childRoutes)};return o([this.routeTree]),function(t){t.forEach(((e,s)=>{const a=t[s-1];a&&e.__setParentMatch(a)}))}(s),s};loadMatches=async(t,e)=>{t.forEach((async t=>{t.__validate()})),await Promise.all(t.map((async t=>{try{await(t.route.options.beforeLoad?.({router:this,match:t}))}catch(s){throw e?.preload||t.route.options.onLoadError?.(s),s}})));const s=t.map((async(e,s)=>{const a=t[1],o=e.store.state.search;o.__data?.matchId&&o.__data.matchId!==e.id||(e.load(),"success"!==e.store.state.status&&e.__loadPromise&&await e.__loadPromise,a&&await a.__loadPromise)}));await Promise.all(s)};reload=()=>{this.navigate({fromCurrent:!0,replace:!0,search:!0})};resolvePath=(t,e)=>v(this.basepath,t,m(e));navigate=async({from:t,to:s=".",search:a,hash:o,replace:r,params:i})=>{const n=String(s),h=void 0===t?t:String(t);let c;try{new URL(`${n}`),c=!0}catch(t){}return e(!c),this.#h({from:h,to:n,search:a,hash:o,replace:r,params:i})};matchRoute=(t,e)=>{t={...t,to:t.to?this.resolvePath(t.from??"",t.to):void 0};const s=this.buildNext(t);return e?.pending?!!this.store.state.pendingLocation&&S(this.basepath,this.store.state.pendingLocation.pathname,{...e,to:s.pathname}):S(this.basepath,this.store.state.currentLocation.pathname,{...e,to:s.pathname})};buildLink=({from:t,to:e=".",search:s,params:a,hash:o,target:r,replace:i,activeOptions:n,preload:h,preloadMaxAge:c,preloadGcMaxAge:u,preloadDelay:l,disabled:p})=>{try{return new URL(`${e}`),{type:"external",href:e}}catch(t){}const d={from:t,to:e,search:s,params:a,hash:o,replace:i},f=this.buildNext(d);h=h??this.options.defaultPreload;const m=l??this.options.defaultPreloadDelay??0,g=this.store.state.currentLocation.pathname===f.pathname,y=this.store.state.currentLocation.pathname.split("/"),w=f.pathname.split("/").every(((t,e)=>t===y[e])),v=this.store.state.currentLocation.hash===f.hash;return{type:"internal",next:f,handleFocus:t=>{h&&this.preloadRoute(d).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))},handleClick:t=>{p||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||r&&"_self"!==r||0!==t.button||(t.preventDefault(),this.#h(d))},handleEnter:t=>{const e=t.target||{};if(h){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,this.preloadRoute(d).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))}),m)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},isActive:(n?.exact?g:w)&&(!n?.includeHash||v),disabled:p}};dehydrate=()=>({state:{...u(this.store.state,["latestLocation","currentLocation","status","lastUpdated"]),currentMatches:this.store.state.currentMatches.map((t=>({id:t.id,state:{...u(t.store.state,["status"])}})))},context:this.options.context});hydrate=t=>{this.store.setState((s=>{this.options.context=t.context;const a=this.matchRoutes(t.state.latestLocation.pathname,{strictParseParams:!0});return a.forEach(((s,a)=>{const o=t.state.currentMatches[a];e(o&&o.id===s.id),s.store.setState((t=>({...t,...o.state})))})),a.forEach((t=>t.__validate())),{...s,...t.state,currentMatches:a}}))};#i=t=>{const e=(t,s)=>t.map(((t,a)=>{const o=t.options,r=new M(t,o,a,s,this);if(this.routesById[r.id])throw new Error;this.routesById[r.id]=r;const i=t.children;return r.childRoutes=i.length?e(i,r):void 0,r}));return e([t])[0]};#r=t=>{let{pathname:e,search:s,hash:a,state:o}=this.history.location;const r=this.options.parseSearch(s);return{pathname:e,searchStr:s,search:l(t?.search,r),hash:a.split("#").reverse()[0]??"",href:`${e}${s}${a}`,state:o,key:o?.key||"__init__"}};#o=()=>{this.load()};#n=(t={})=>{const e=t.fromCurrent?this.store.state.latestLocation.pathname:t.from??this.store.state.latestLocation.pathname;let s=v(this.basepath??"/",e,`${t.to??"."}`);const a=this.matchRoutes(this.store.state.latestLocation.pathname,{strictParseParams:!0}),o=this.matchRoutes(s),r={...h(a)?.params};let i=!0===(t.params??!0)?r:c(t.params,r);i&&o.map((t=>t.route.options.stringifyParams)).filter(Boolean).forEach((t=>{Object.assign({},i,t(i))})),s=L(s,i??{});const n=t.__preSearchFilters?.length?t.__preSearchFilters?.reduce(((t,e)=>e(t)),this.store.state.latestLocation.search):this.store.state.latestLocation.search,u=!0===t.search?n:t.search?c(t.search,n)??{}:t.__preSearchFilters?.length?n:{},p=t.__postSearchFilters?.length?t.__postSearchFilters.reduce(((t,e)=>e(t)),u):u,d=l(this.store.state.latestLocation.search,p),f=this.options.stringifySearch(d);let m=!0===t.hash?this.store.state.latestLocation.hash:c(t.hash,this.store.state.latestLocation.hash);return m=m?`#${m}`:"",{pathname:s,search:d,searchStr:f,state:this.store.state.latestLocation.state,hash:m,href:`${s}${f}${m}`,key:t.key}};#h=t=>{const e=this.buildNext(t),s=""+Date.now()+Math.random();this.navigateTimeout&&clearTimeout(this.navigateTimeout);let a="replace";t.replace||(a="push");this.store.state.latestLocation.href===e.href&&!e.key&&(a="replace");const o=`${e.pathname}${e.searchStr}${e.hash?`#${e.hash}`:""}`;return this.history["push"===a?"push":"replace"](o,{id:s,...e.state}),this.navigationPromise=new Promise((t=>{const e=this.resolveNavigation;this.resolveNavigation=()=>{e(),t()}}))}},t.cleanPath=m,t.createBrowserHistory=o,t.createHashHistory=function(){return o({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=r,t.createRouteConfig=$,t.decode=E,t.defaultFetchServerDataFn=O,t.defaultParseSearch=F,t.defaultStringifySearch=k,t.encode=P,t.functionalUpdate=c,t.interpolatePath=L,t.invariant=e,t.isPlainObject=p,t.joinPaths=f,t.last=h,t.matchByPath=_,t.matchPathname=S,t.parsePathname=b,t.parseSearchWith=T,t.pick=u,t.replaceEqualDeep=l,t.resolvePath=v,t.rootRouteId=x,t.stringifySearchWith=j,t.trimPath=w,t.trimPathLeft=g,t.trimPathRight=y,t.warning=function(t,e){if(t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch{}}return!0},Object.defineProperty(t,"__esModule",{value:!0})}));
class C{listeners=new Set;batching=!1;queue=[];constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=t=>{const e=this.state;this.state=this.options?.updateFn?this.options.updateFn(e)(t):t(e),this.queue.push((()=>{this.listeners.forEach((t=>t(this.state,e))),this.options?.onUpdate?.(this.state,e)})),this.#t()};#t=()=>{this.batching||(this.queue.forEach((t=>t())),this.queue=[])};batch=t=>{this.batching=!0,t(),this.batching=!1,this.#t()}}const A=["component","errorComponent","pendingComponent"];class I{abortController=new AbortController;onLoaderDataListeners=new Set;constructor(t,e,s){Object.assign(this,{route:e,router:t,id:s.id,pathname:s.pathname,params:s.params,store:new C({updatedAt:0,routeSearch:{},search:{},status:"idle"})}),this.#e()||this.store.setState((t=>({...t,status:"success"})))}cancel=()=>{this.abortController?.abort()};load=async()=>{"pending"!==this.store.state.status&&await this.fetch()};#s="";fetch=async()=>(this.__loadPromise=Promise.resolve().then((async()=>{const t=""+Date.now()+Math.random();this.#s=t;const e=()=>t!==this.#s?this.__loadPromise:void 0;let s;this.store.batch((()=>{"idle"===this.store.state.status&&this.store.setState((t=>({...t,status:"pending"})))}));const a=(async()=>{await Promise.all(A.map((async t=>{const e=this.route.options[t];this[t]?.preload&&(this[t]=await this.router.options.loadComponent(e))})))})(),o=Promise.resolve().then((()=>{if(this.route.options.onLoad)return this.route.options.onLoad({params:this.params,search:this.store.state.search,signal:this.abortController.signal})}));try{if(await a,await o,s=e())return await s;this.store.setState((t=>({...t,error:void 0,status:"success",updatedAt:Date.now()})))}catch(t){this.store.setState((e=>({...e,error:t,status:"error",updatedAt:Date.now()})))}finally{delete this.__loadPromise}})),this.__loadPromise);#e=()=>!(!this.route.options.onLoad&&!A.some((t=>this.route.options[t]?.preload)));__setParentMatch=t=>{!this.parentMatch&&t&&(this.parentMatch=t)};__validate=()=>{const t=this.parentMatch?.store.state.search??this.router.store.state.latestLocation.search;try{let e=("object"==typeof this.route.options.validateSearch?this.route.options.validateSearch.parse:this.route.options.validateSearch)?.(t)??{};this.store.setState((s=>({...s,routeSearch:e,search:{...t,...e}}))),A.map((async t=>{const e=this.route.options[t];"function"!=typeof this[t]&&(this[t]=e)}))}catch(t){console.error(t);const e=new Error("Invalid search params found",{cause:t});return e.code="INVALID_SEARCH_PARAMS",void this.store.setState((t=>({...t,status:"error",error:e})))}}}const F=T(JSON.parse),k=j(JSON.stringify);function T(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let s=E(e);for(let e in s){const a=s[e];if("string"==typeof a)try{s[e]=t(a)}catch(t){}}return s}}function j(t){return e=>{(e={...e})&&Object.keys(e).forEach((s=>{const a=e[s];if(void 0===a||void 0===a)delete e[s];else if(a&&"object"==typeof a&&null!==a)try{e[s]=t(a)}catch(t){}}));const s=P(e).toString();return s?`?${s}`:""}}const O=async({router:t,routeMatch:e})=>{const s=t.buildNext({to:".",search:t=>({...t??{},__data:{matchId:e.id}})}),a=await fetch(s.href,{method:"GET",signal:e.abortController.signal});if(a.ok)return a.json();throw new Error("Failed to fetch match data")};const D="undefined"==typeof window||!window.document.createElement;function H(){return{status:"idle",latestLocation:null,currentLocation:null,currentMatches:[],lastUpdated:Date.now()}}t.Route=M,t.RouteMatch=I,t.Router=class{#a;startedLoadingAt=Date.now();resolveNavigation=()=>{};constructor(t){this.options={defaultPreloadDelay:50,context:void 0,...t,stringifySearch:t?.stringifySearch??k,parseSearch:t?.parseSearch??F,fetchServerDataFn:t?.fetchServerDataFn??O},this.store=new C(H()),this.basepath="",this.update(t),this.options.Router?.(this)}reset=()=>{this.store.setState((t=>Object.assign(t,H())))};mount=()=>{if(!D){this.store.state.currentMatches.length||this.load();const t="visibilitychange",e="focus";return window.addEventListener&&(window.addEventListener(t,this.#o,!1),window.addEventListener(e,this.#o,!1)),()=>{window.removeEventListener&&(window.removeEventListener(t,this.#o),window.removeEventListener(e,this.#o))}}return()=>{}};update=t=>{if(Object.assign(this.options,t),!this.history||this.options.history&&this.options.history!==this.history){this.#a&&this.#a(),this.history=this.options.history??(D?r():o());const t=this.#r();this.store.setState((e=>({...e,latestLocation:t,currentLocation:t}))),this.#a=this.history.listen((()=>{this.load(this.#r(this.store.state.latestLocation))}))}const{basepath:e,routeConfig:s}=this.options;return this.basepath=`/${w(e??"")??""}`,s&&(this.routesById={},this.routeTree=this.#i(s)),this};buildNext=t=>{const e=this.#n(t),s=this.matchRoutes(e.pathname),a=s.map((t=>t.route.options.preSearchFilters??[])).flat().filter(Boolean),o=s.map((t=>t.route.options.postSearchFilters??[])).flat().filter(Boolean);return this.#n({...t,__preSearchFilters:a,__postSearchFilters:o})};cancelMatches=()=>{[...this.store.state.currentMatches,...this.store.state.pendingMatches||[]].forEach((t=>{t.cancel()}))};load=async t=>{let s=Date.now();const a=s;let o;this.startedLoadingAt=a,this.cancelMatches(),this.store.batch((()=>{t&&this.store.setState((e=>({...e,latestLocation:t}))),o=this.matchRoutes(this.store.state.latestLocation.pathname,{strictParseParams:!0}),this.store.setState((t=>({...t,status:"pending",pendingMatches:o,pendingLocation:this.store.state.latestLocation})))}));try{await this.loadMatches(o)}catch(t){console.warn(t),e(!1)}if(this.startedLoadingAt!==a)return this.navigationPromise;const r=this.store.state.currentMatches,i=[],n=[];r.forEach((t=>{o.find((e=>e.id===t.id))?n.push(t):i.push(t)}));const h=o.filter((t=>!r.find((e=>e.id===t.id))));s=Date.now(),i.forEach((t=>{t.__onExit?.({params:t.params,search:t.store.state.routeSearch}),"error"===t.store.state.status&&this.store.setState((t=>({...t,status:"idle",error:void 0})))})),n.forEach((t=>{t.route.options.onTransition?.({params:t.params,search:t.store.state.routeSearch})})),h.forEach((t=>{t.__onExit=t.route.options.onLoaded?.({params:t.params,search:t.store.state.search})})),this.store.setState((t=>({...t,status:"idle",currentLocation:this.store.state.latestLocation,currentMatches:o,pendingLocation:void 0,pendingMatches:void 0}))),this.options.onRouteChange?.(),this.resolveNavigation()};getRoute=t=>{const s=this.routesById[t];return e(s),s};loadRoute=async(t=this.store.state.latestLocation)=>{const e=this.buildNext(t),s=this.matchRoutes(e.pathname,{strictParseParams:!0});return await this.loadMatches(s),s};preloadRoute=async(t=this.store.state.latestLocation)=>{const e=this.buildNext(t),s=this.matchRoutes(e.pathname,{strictParseParams:!0});return await this.loadMatches(s,{preload:!0}),s};matchRoutes=(t,e)=>{const s=[];if(!this.routeTree)return s;const a=[...this.store.state.currentMatches,...this.store.state.pendingMatches??[]],o=async r=>{let i=h(s)?.params??{};const n=this.options.filterRoutes?.(r)??r;let c=[];const u=(s,a)=>(a.some((a=>{if(!a.path&&a.childRoutes?.length)return u([...c,a],a.childRoutes);const o=!("/"===a.path&&!a.childRoutes?.length),r=S(this.basepath,t,{to:a.fullPath,fuzzy:o,caseSensitive:a.options.caseSensitive??this.options.caseSensitive});if(r){let t;try{t=a.options.parseParams?.(r)??r}catch(t){if(e?.strictParseParams)throw t}i={...i,...t}}return r&&(c=[...s,a]),!!c.length})),!!c.length);if(u([],n),!c.length)return;c.forEach((t=>{const e=L(t.path,i),o=L(t.id,i,!0),r=a.find((t=>t.id===o))||new I(this,t,{id:o,params:i,pathname:f([this.basepath,e])});s.push(r)}));const l=h(c);l.childRoutes?.length&&o(l.childRoutes)};return o([this.routeTree]),function(t){t.forEach(((e,s)=>{const a=t[s-1];a&&e.__setParentMatch(a)}))}(s),s};loadMatches=async(t,e)=>{t.forEach((async t=>{t.__validate()})),await Promise.all(t.map((async t=>{try{await(t.route.options.beforeLoad?.({router:this,match:t}))}catch(s){throw e?.preload||t.route.options.onLoadError?.(s),s}})));const s=t.map((async(e,s)=>{const a=t[1],o=e.store.state.search;o.__data?.matchId&&o.__data.matchId!==e.id||(e.load(),"success"!==e.store.state.status&&e.__loadPromise&&await e.__loadPromise,a&&await a.__loadPromise)}));await Promise.all(s)};reload=()=>{this.navigate({fromCurrent:!0,replace:!0,search:!0})};resolvePath=(t,e)=>v(this.basepath,t,m(e));navigate=async({from:t,to:s=".",search:a,hash:o,replace:r,params:i})=>{const n=String(s),h=void 0===t?t:String(t);let c;try{new URL(`${n}`),c=!0}catch(t){}return e(!c),this.#h({from:h,to:n,search:a,hash:o,replace:r,params:i})};matchRoute=(t,e)=>{t={...t,to:t.to?this.resolvePath(t.from??"",t.to):void 0};const s=this.buildNext(t);return e?.pending?!!this.store.state.pendingLocation&&S(this.basepath,this.store.state.pendingLocation.pathname,{...e,to:s.pathname}):S(this.basepath,this.store.state.currentLocation.pathname,{...e,to:s.pathname})};buildLink=({from:t,to:e=".",search:s,params:a,hash:o,target:r,replace:i,activeOptions:n,preload:h,preloadMaxAge:c,preloadGcMaxAge:u,preloadDelay:l,disabled:p})=>{try{return new URL(`${e}`),{type:"external",href:e}}catch(t){}const d={from:t,to:e,search:s,params:a,hash:o,replace:i},f=this.buildNext(d);h=h??this.options.defaultPreload;const m=l??this.options.defaultPreloadDelay??0,g=this.store.state.currentLocation.pathname===f.pathname,y=this.store.state.currentLocation.pathname.split("/"),w=f.pathname.split("/").every(((t,e)=>t===y[e])),v=this.store.state.currentLocation.hash===f.hash;return{type:"internal",next:f,handleFocus:t=>{h&&this.preloadRoute(d).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))},handleClick:t=>{p||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||r&&"_self"!==r||0!==t.button||(t.preventDefault(),this.#h(d))},handleEnter:t=>{const e=t.target||{};if(h){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,this.preloadRoute(d).catch((t=>{console.warn(t),console.warn("Error preloading route! ☝️")}))}),m)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},isActive:(n?.exact?g:w)&&(!n?.includeHash||v),disabled:p}};dehydrate=()=>({state:{...u(this.store.state,["latestLocation","currentLocation","status","lastUpdated"]),currentMatches:this.store.state.currentMatches.map((t=>({id:t.id,state:{...u(t.store.state,["status"])}})))},context:this.options.context});hydrate=t=>{this.store.setState((s=>{this.options.context=t.context;const a=this.matchRoutes(t.state.latestLocation.pathname,{strictParseParams:!0});return a.forEach(((s,a)=>{const o=t.state.currentMatches[a];e(o&&o.id===s.id),s.store.setState((t=>({...t,...o.state})))})),a.forEach((t=>t.__validate())),{...s,...t.state,currentMatches:a}}))};#i=t=>{const e=(t,s)=>t.map(((t,a)=>{const o=t.options,r=new M(t,o,a,s,this);if(this.routesById[r.id])throw new Error;this.routesById[r.id]=r;const i=t.children;return r.childRoutes=i.length?e(i,r):void 0,r}));return e([t])[0]};#r=t=>{let{pathname:e,search:s,hash:a,state:o}=this.history.location;const r=this.options.parseSearch(s);return{pathname:e,searchStr:s,search:l(t?.search,r),hash:a.split("#").reverse()[0]??"",href:`${e}${s}${a}`,state:o,key:o?.key||"__init__"}};#o=()=>{this.load()};#n=(t={})=>{const e=t.fromCurrent?this.store.state.latestLocation.pathname:t.from??this.store.state.latestLocation.pathname;let s=v(this.basepath??"/",e,`${t.to??"."}`);const a=this.matchRoutes(this.store.state.latestLocation.pathname,{strictParseParams:!0}),o=this.matchRoutes(s),r={...h(a)?.params};let i=!0===(t.params??!0)?r:c(t.params,r);i&&o.map((t=>t.route.options.stringifyParams)).filter(Boolean).forEach((t=>{Object.assign({},i,t(i))})),s=L(s,i??{});const n=t.__preSearchFilters?.length?t.__preSearchFilters?.reduce(((t,e)=>e(t)),this.store.state.latestLocation.search):this.store.state.latestLocation.search,u=!0===t.search?n:t.search?c(t.search,n)??{}:t.__preSearchFilters?.length?n:{},p=t.__postSearchFilters?.length?t.__postSearchFilters.reduce(((t,e)=>e(t)),u):u,d=l(this.store.state.latestLocation.search,p),f=this.options.stringifySearch(d);let m=!0===t.hash?this.store.state.latestLocation.hash:c(t.hash,this.store.state.latestLocation.hash);return m=m?`#${m}`:"",{pathname:s,search:d,searchStr:f,state:this.store.state.latestLocation.state,hash:m,href:`${s}${f}${m}`,key:t.key}};#h=t=>{const e=this.buildNext(t),s=""+Date.now()+Math.random();this.navigateTimeout&&clearTimeout(this.navigateTimeout);let a="replace";t.replace||(a="push");this.store.state.latestLocation.href===e.href&&!e.key&&(a="replace");const o=`${e.pathname}${e.searchStr}${e.hash?`#${e.hash}`:""}`;return this.history["push"===a?"push":"replace"](o,{id:s,...e.state}),this.navigationPromise=new Promise((t=>{const e=this.resolveNavigation;this.resolveNavigation=()=>{e(),t()}}))}},t.cleanPath=m,t.createBrowserHistory=o,t.createHashHistory=function(){return o({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=r,t.createRouteConfig=$,t.decode=E,t.defaultFetchServerDataFn=O,t.defaultParseSearch=F,t.defaultStringifySearch=k,t.encode=P,t.functionalUpdate=c,t.interpolatePath=L,t.invariant=e,t.isPlainObject=p,t.joinPaths=f,t.last=h,t.matchByPath=_,t.matchPathname=S,t.parsePathname=b,t.parseSearchWith=T,t.pick=u,t.replaceEqualDeep=l,t.resolvePath=v,t.rootRouteId=x,t.stringifySearchWith=j,t.trimPath=w,t.trimPathLeft=g,t.trimPathRight=y,t.warning=function(t,e){if(t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch{}}return!0},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@tanstack/router",
"author": "Tanner Linsley",
"version": "0.0.1-beta.53",
"version": "0.0.1-beta.55",
"license": "MIT",

@@ -40,4 +40,4 @@ "repository": "tanstack/router",

"tiny-invariant": "^1.3.1",
"@tanstack/store": "0.0.1-beta.52"
"@tanstack/store": "0.0.1-beta.55"
}
}

@@ -351,6 +351,8 @@ import { Store } from '@tanstack/store'

const parsedLocation = this.#parseLocation()
this.store.setState((s) => ({
...s,
latestLocation: this.#parseLocation(),
currentLocation: s.latestLocation,
latestLocation: parsedLocation,
currentLocation: parsedLocation,
}))

@@ -357,0 +359,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc