@tanstack/router-core 0.0.1-beta.2 → 0.0.1-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,6 @@ exports.trimPathLeft = path.trimPathLeft;
41
41
  exports.trimPathRight = path.trimPathRight;
42
42
  exports.decode = qss.decode;
43
43
  exports.encode = qss.encode;
44
- exports.cascadeLoaderData = route.cascadeLoaderData;
45
44
  exports.createRoute = route.createRoute;
46
45
  exports.createRouteConfig = routeConfig.createRouteConfig;
47
46
  exports.rootRouteId = routeConfig.rootRouteId;
@@ -53,6 +52,7 @@ exports.parseSearchWith = searchParams.parseSearchWith;
53
52
  exports.stringifySearchWith = searchParams.stringifySearchWith;
54
53
  exports.functionalUpdate = utils.functionalUpdate;
55
54
  exports.last = utils.last;
55
+ exports.pick = utils.pick;
56
56
  exports.replaceEqualDeep = utils.replaceEqualDeep;
57
57
  exports.warning = utils.warning;
58
58
  //# sourceMappingURL=index.js.map
@@ -42,6 +42,7 @@ function toValue(mix) {
42
42
  var str = decodeURIComponent(mix);
43
43
  if (str === 'false') return false;
44
44
  if (str === 'true') return true;
45
+ if (str.charAt(0) === '0') return str;
45
46
  return +str * 0 === 0 ? +str : str;
46
47
  }
47
48
 
@@ -1 +1 @@
1
- {"version":3,"file":"qss.js","sources":["../../../../../src/qss.ts"],"sourcesContent":["// @ts-nocheck\n\n// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.\n\nexport function encode(obj, pfx?: string) {\n var k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\nfunction toValue(mix) {\n if (!mix) return ''\n var str = decodeURIComponent(mix)\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 ? +str : str\n}\n\nexport function decode(str) {\n var tmp,\n k,\n out = {},\n arr = str.split('&')\n\n while ((tmp = arr.shift())) {\n tmp = tmp.split('=')\n k = tmp.shift()\n if (out[k] !== void 0) {\n out[k] = [].concat(out[k], toValue(tmp.shift()))\n } else {\n out[k] = toValue(tmp.shift())\n }\n }\n\n return out\n}\n"],"names":["encode","obj","pfx","k","i","tmp","str","Array","isArray","length","encodeURIComponent","toValue","mix","decodeURIComponent","decode","out","arr","split","shift","concat"],"mappings":";;;;;;;;;;;;;;AAAA;AAEA;AAEO,SAASA,MAAT,CAAgBC,GAAhB,EAAqBC,GAArB,EAAmC;AACxC,EAAA,IAAIC,CAAJ;AAAA,MACEC,CADF;AAAA,MAEEC,GAFF;MAGEC,GAAG,GAAG,EAHR,CAAA;;EAKA,KAAKH,CAAL,IAAUF,GAAV,EAAe;IACb,IAAI,CAACI,GAAG,GAAGJ,GAAG,CAACE,CAAD,CAAV,MAAmB,KAAK,CAA5B,EAA+B;AAC7B,MAAA,IAAII,KAAK,CAACC,OAAN,CAAcH,GAAd,CAAJ,EAAwB;AACtB,QAAA,KAAKD,CAAC,GAAG,CAAT,EAAYA,CAAC,GAAGC,GAAG,CAACI,MAApB,EAA4BL,CAAC,EAA7B,EAAiC;AAC/BE,UAAAA,GAAG,KAAKA,GAAG,IAAI,GAAZ,CAAH,CAAA;AACAA,UAAAA,GAAG,IAAII,kBAAkB,CAACP,CAAD,CAAlB,GAAwB,GAAxB,GAA8BO,kBAAkB,CAACL,GAAG,CAACD,CAAD,CAAJ,CAAvD,CAAA;AACD,SAAA;AACF,OALD,MAKO;AACLE,QAAAA,GAAG,KAAKA,GAAG,IAAI,GAAZ,CAAH,CAAA;QACAA,GAAG,IAAII,kBAAkB,CAACP,CAAD,CAAlB,GAAwB,GAAxB,GAA8BO,kBAAkB,CAACL,GAAD,CAAvD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A;AACF,GAAA;;AAED,EAAA,OAAOH,GAAP,CAAA;AACD;;;;;"}
1
+ {"version":3,"file":"qss.js","sources":["../../../../../src/qss.ts"],"sourcesContent":["// @ts-nocheck\n\n// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.\n\nexport function encode(obj, pfx?: string) {\n var k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\nfunction toValue(mix) {\n if (!mix) return ''\n var str = decodeURIComponent(mix)\n if (str === 'false') return false\n if (str === 'true') return true\n if (str.charAt(0) === '0') return str\n return +str * 0 === 0 ? +str : str\n}\n\nexport function decode(str) {\n var tmp,\n k,\n out = {},\n arr = str.split('&')\n\n while ((tmp = arr.shift())) {\n tmp = tmp.split('=')\n k = tmp.shift()\n if (out[k] !== void 0) {\n out[k] = [].concat(out[k], toValue(tmp.shift()))\n } else {\n out[k] = toValue(tmp.shift())\n }\n }\n\n return out\n}\n"],"names":["encode","obj","pfx","k","i","tmp","str","Array","isArray","length","encodeURIComponent","toValue","mix","decodeURIComponent","charAt","decode","out","arr","split","shift","concat"],"mappings":";;;;;;;;;;;;;;AAAA;AAEA;AAEO,SAASA,MAAT,CAAgBC,GAAhB,EAAqBC,GAArB,EAAmC;AACxC,EAAA,IAAIC,CAAJ;AAAA,MACEC,CADF;AAAA,MAEEC,GAFF;MAGEC,GAAG,GAAG,EAHR,CAAA;;EAKA,KAAKH,CAAL,IAAUF,GAAV,EAAe;IACb,IAAI,CAACI,GAAG,GAAGJ,GAAG,CAACE,CAAD,CAAV,MAAmB,KAAK,CAA5B,EAA+B;AAC7B,MAAA,IAAII,KAAK,C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G,GAAGX,GAAG,CAACY,KAAJ,CAAU,GAAV,CAHR,CAAA;;AAKA,EAAA,OAAQb,GAAG,GAAGY,GAAG,CAACE,KAAJ,EAAd,EAA4B;AAC1Bd,IAAAA,GAAG,GAAGA,GAAG,CAACa,KAAJ,CAAU,GAAV,CAAN,CAAA;AACAf,IAAAA,CAAC,GAAGE,GAAG,CAACc,KAAJ,EAAJ,CAAA;;AACA,IAAA,IAAIH,GAAG,CAACb,CAAD,CAAH,KAAW,KAAK,CAApB,EAAuB;AACrBa,MAAAA,GAAG,CAACb,CAAD,CAAH,GAAS,EAAGiB,CAAAA,MAAH,CAAUJ,GAAG,CAACb,CAAD,CAAb,EAAkBQ,OAAO,CAACN,GAAG,CAACc,KAAJ,EAAD,CAAzB,CAAT,CAAA;AACD,KAFD,MAEO;MACLH,GAAG,CAACb,CAAD,CAAH,GAASQ,OAAO,CAACN,GAAG,CAACc,KAAJ,EAAD,CAAhB,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAA,OAAOH,GAAP,CAAA;AACD;;;;;"}
@@ -13,7 +13,6 @@
13
13
  Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
15
  var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
16
- var utils = require('./utils.js');
17
16
 
18
17
  function createRoute(routeConfig, options, parent, router) {
19
18
  const {
@@ -25,7 +24,7 @@ function createRoute(routeConfig, options, parent, router) {
25
24
 
26
25
  const action = router.state.actions[id] || (() => {
27
26
  router.state.actions[id] = {
28
- pending: [],
27
+ submissions: [],
29
28
  submit: async (submission, actionOpts) => {
30
29
  var _actionOpts$invalidat;
31
30
 
@@ -34,18 +33,20 @@ function createRoute(routeConfig, options, parent, router) {
34
33
  }
35
34
 
36
35
  const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
36
+
37
+ if (!(actionOpts != null && actionOpts.multi)) {
38
+ action.submissions = action.submissions.filter(d => d.isMulti);
39
+ }
40
+
37
41
  const actionState = {
38
42
  submittedAt: Date.now(),
39
43
  status: 'pending',
40
- submission
44
+ submission,
45
+ isMulti: !!(actionOpts != null && actionOpts.multi)
41
46
  };
42
47
  action.current = actionState;
43
48
  action.latest = actionState;
44
- action.pending.push(actionState);
45
- router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
46
- currentAction: actionState,
47
- latestAction: actionState
48
- });
49
+ action.submissions.push(actionState);
49
50
  router.notify();
50
51
 
51
52
  try {
@@ -67,11 +68,6 @@ function createRoute(routeConfig, options, parent, router) {
67
68
  actionState.error = err;
68
69
  actionState.status = 'error';
69
70
  } finally {
70
- action.pending = action.pending.filter(d => d !== actionState);
71
- router.removeActionQueue.push({
72
- action,
73
- actionState
74
- });
75
71
  router.notify();
76
72
  }
77
73
  }
@@ -146,16 +142,6 @@ function createRoute(routeConfig, options, parent, router) {
146
142
  });
147
143
  return route;
148
144
  }
149
- function cascadeLoaderData(matches) {
150
- matches.forEach((match, index) => {
151
- const parent = matches[index - 1];
152
-
153
- if (parent) {
154
- match.loaderData = utils.replaceEqualDeep(match.loaderData, _rollupPluginBabelHelpers["extends"]({}, parent.loaderData, match.routeLoaderData));
155
- }
156
- });
157
- }
158
145
 
159
- exports.cascadeLoaderData = cascadeLoaderData;
160
146
  exports.createRoute = createRoute;
161
147
  //# sourceMappingURL=route.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sources":["../../../../../src/route.ts"],"sourcesContent":["import {\n CheckRelativePath,\n LinkInfo,\n LinkOptions,\n ResolveRelativePath,\n ToOptions,\n} from './link'\nimport { LoaderContext, RouteConfig, RouteOptions } from './routeConfig'\nimport {\n AnyAllRouteInfo,\n AnyRouteInfo,\n DefaultAllRouteInfo,\n RouteInfo,\n RouteInfoByPath,\n} from './routeInfo'\nimport { RouteMatch } from './routeMatch'\nimport {\n Action,\n ActionState,\n Loader,\n LoaderState,\n MatchRouteOptions,\n Router,\n} from './router'\nimport { NoInfer, replaceEqualDeep } from './utils'\n\nexport interface AnyRoute extends Route<any, any> {}\n\nexport interface Route<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n> {\n routeId: TRouteInfo['id']\n routeRouteId: TRouteInfo['routeId']\n routePath: TRouteInfo['path']\n fullPath: TRouteInfo['fullPath']\n parentRoute?: AnyRoute\n childRoutes?: AnyRoute[]\n options: RouteOptions\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>\n buildLink: <TTo extends string = '.'>(\n options: Omit<\n LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,\n 'from'\n >,\n ) => LinkInfo\n matchRoute: <\n TTo extends string = '.',\n TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>,\n >(\n matchLocation: CheckRelativePath<\n TAllRouteInfo,\n TRouteInfo['fullPath'],\n NoInfer<TTo>\n > &\n Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>,\n opts?: MatchRouteOptions,\n ) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams']\n navigate: <TTo extends string = '.'>(\n options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>,\n ) => Promise<void>\n action: unknown extends TRouteInfo['actionResponse']\n ?\n | Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>\n | undefined\n : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>\n loader: unknown extends TRouteInfo['routeLoaderData']\n ?\n | Action<\n LoaderContext<\n TRouteInfo['fullSearchSchema'],\n TRouteInfo['allParams']\n >,\n TRouteInfo['routeLoaderData']\n >\n | undefined\n : Loader<\n TRouteInfo['fullSearchSchema'],\n TRouteInfo['allParams'],\n TRouteInfo['routeLoaderData']\n >\n}\n\nexport function createRoute<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n>(\n routeConfig: RouteConfig,\n options: TRouteInfo['options'],\n parent: undefined | Route<TAllRouteInfo, any>,\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>,\n): Route<TAllRouteInfo, TRouteInfo> {\n const { id, routeId, path: routePath, fullPath } = routeConfig\n\n const action =\n router.state.actions[id] ||\n (() => {\n router.state.actions[id] = {\n pending: [],\n submit: async <T, U>(\n submission: T,\n actionOpts?: { invalidate?: boolean },\n ) => {\n if (!route) {\n return\n }\n\n const invalidate = actionOpts?.invalidate ?? true\n\n const actionState: ActionState<T, U> = {\n submittedAt: Date.now(),\n status: 'pending',\n submission,\n }\n\n action.current = actionState\n action.latest = actionState\n action.pending.push(actionState)\n\n router.state = {\n ...router.state,\n currentAction: actionState,\n latestAction: actionState,\n }\n\n router.notify()\n\n try {\n const res = await route.options.action?.(submission)\n actionState.data = res as U\n if (invalidate) {\n router.invalidateRoute({ to: '.', fromCurrent: true })\n await router.reload()\n }\n actionState.status = 'success'\n return res\n } catch (err) {\n console.error(err)\n actionState.error = err\n actionState.status = 'error'\n } finally {\n action.pending = action.pending.filter((d) => d !== actionState)\n router.removeActionQueue.push({ action, actionState })\n router.notify()\n }\n },\n }\n return router.state.actions[id]!\n })()\n\n const loader =\n router.state.loaders[id] ||\n (() => {\n router.state.loaders[id] = {\n pending: [],\n fetch: (async (loaderContext: LoaderContext<any, any>) => {\n if (!route) {\n return\n }\n\n const loaderState: LoaderState<any, any> = {\n loadedAt: Date.now(),\n loaderContext,\n }\n\n loader.current = loaderState\n loader.latest = loaderState\n loader.pending.push(loaderState)\n\n // router.state = {\n // ...router.state,\n // currentAction: loaderState,\n // latestAction: loaderState,\n // }\n\n router.notify()\n\n try {\n return await route.options.loader?.(loaderContext)\n } finally {\n loader.pending = loader.pending.filter((d) => d !== loaderState)\n // router.removeActionQueue.push({ loader, loaderState })\n router.notify()\n }\n }) as any,\n }\n return router.state.loaders[id]!\n })()\n\n let route: Route<TAllRouteInfo, TRouteInfo> = {\n routeId: id,\n routeRouteId: routeId,\n routePath,\n fullPath,\n options,\n router,\n childRoutes: undefined!,\n parentRoute: parent,\n action,\n loader: loader as any,\n\n buildLink: (options) => {\n return router.buildLink({\n ...options,\n from: fullPath,\n } as any) as any\n },\n\n navigate: (options) => {\n return router.navigate({\n ...options,\n from: fullPath,\n } as any) as any\n },\n\n matchRoute: (matchLocation, opts) => {\n return router.matchRoute(\n {\n ...matchLocation,\n from: fullPath,\n } as any,\n opts,\n )\n },\n }\n\n router.options.createRoute?.({ router, route })\n\n return route\n}\n\nexport function cascadeLoaderData(matches: RouteMatch<any, any>[]) {\n matches.forEach((match, index) => {\n const parent = matches[index - 1]\n\n if (parent) {\n match.loaderData = replaceEqualDeep(match.loaderData, {\n ...parent.loaderData,\n ...match.routeLoaderData,\n })\n }\n })\n}\n"],"names":["createRoute","routeConfig","options","parent","router","id","routeId","path","routePath","fullPath","action","state","actions","pending","submit","submission","actionOpts","route","invalidate","actionState","submittedAt","Date","now","status","current","latest","push","currentAction","latestAction","notify","res","data","invalidateRoute","to","fromCurrent","reload","err","console","error","filter","d","removeActionQueue","loader","loaders","fetch","loaderContext","loaderState","loadedAt","routeRouteId","childRoutes","undefined","parentRoute","buildLink","_extends","from","navigate","matchRoute","matchLocation","opts","cascadeLoaderData","matches","forEach","match","index","loaderData","replaceEqualDeep","routeLoaderData"],"mappings":";;;;;;;;;;;;;;;;;AAmFO,SAASA,WAAT,CAILC,WAJK,EAKLC,OALK,EAMLC,MANK,EAOLC,MAPK,EAQ6B;EAClC,MAAM;IAAEC,EAAF;IAAMC,OAAN;AAAeC,IAAAA,IAAI,EAAEC,SAArB;AAAgCC,IAAAA,QAAAA;AAAhC,GAAA,GAA6CR,WAAnD,CAAA;;EAEA,MAAMS,MAAM,GACVN,MAAM,CAACO,KAAP,CAAaC,OAAb,CAAqBP,EAArB,CACA,IAAA,CAAC,MAAM;AACLD,IAAAA,MAAM,CAACO,KAAP,CAAaC,OAAb,CAAqBP,EAArB,CAA2B,GAAA;AACzBQ,MAA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,CAACmD,QAAP,CAAAF,oCAAA,CAAA,EAAA,EACFnD,OADE,EAAA;AAELoD,QAAAA,IAAI,EAAE7C,QAAAA;OAFR,CAAA,CAAA,CAAA;KApB0C;AA0B5C+C,IAAAA,UAAU,EAAE,CAACC,aAAD,EAAgBC,IAAhB,KAAyB;AACnC,MAAA,OAAOtD,MAAM,CAACoD,UAAP,CAAAH,oCAAA,CAAA,EAAA,EAEAI,aAFA,EAAA;AAGHH,QAAAA,IAAI,EAAE7C,QAAAA;AAHH,OAAA,CAAA,EAKLiD,IALK,CAAP,CAAA;AAOD,KAAA;GAlCH,CAAA;EAqCAtD,MAAM,CAACF,OAAP,CAAeF,WAAf,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAI,MAAM,CAACF,OAAP,CAAeF,WAAf,CAA6B;IAAEI,MAAF;AAAUa,IAAAA,KAAAA;GAAvC,CAAA,CAAA;AAEA,EAAA,OAAOA,KAAP,CAAA;AACD,CAAA;AAEM,SAAS0C,iBAAT,CAA2BC,OAA3B,EAA4D;AACjEA,EAAAA,OAAO,CAACC,OAAR,CAAgB,CAACC,KAAD,EAAQC,KAAR,KAAkB;AAChC,IAAA,MAAM5D,MAAM,GAAGyD,OAAO,CAACG,KAAK,GAAG,CAAT,CAAtB,CAAA;;AAEA,IAAA,IAAI5D,MAAJ,EAAY;AACV2D,MAAAA,KAAK,CAACE,UAAN,GAAmBC,sBAAgB,CAACH,KAAK,CAACE,UAAP,EAC9B7D,oCAAAA,CAAAA,EAAAA,EAAAA,MAAM,CAAC6D,UADuB,EAE9BF,KAAK,CAACI,eAFwB,CAAnC,CAAA,CAAA;AAID,KAAA;GARH,CAAA,CAAA;AAUD;;;;;"}
1
+ {"version":3,"file":"route.js","sources":["../../../../../src/route.ts"],"sourcesContent":["import {\n CheckRelativePath,\n LinkInfo,\n LinkOptions,\n ResolveRelativePath,\n ToOptions,\n} from './link'\nimport { LoaderContext, RouteConfig, RouteOptions } from './routeConfig'\nimport {\n AnyAllRouteInfo,\n AnyRouteInfo,\n DefaultAllRouteInfo,\n RouteInfo,\n RouteInfoByPath,\n} from './routeInfo'\nimport {\n Action,\n ActionState,\n Loader,\n LoaderState,\n MatchRouteOptions,\n Router,\n} from './router'\nimport { NoInfer } from './utils'\n\nexport interface AnyRoute extends Route<any, any> {}\n\nexport interface Route<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n> {\n routeId: TRouteInfo['id']\n routeRouteId: TRouteInfo['routeId']\n routePath: TRouteInfo['path']\n fullPath: TRouteInfo['fullPath']\n parentRoute?: AnyRoute\n childRoutes?: AnyRoute[]\n options: RouteOptions\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>\n buildLink: <TTo extends string = '.'>(\n options: Omit<\n LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,\n 'from'\n >,\n ) => LinkInfo\n matchRoute: <\n TTo extends string = '.',\n TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>,\n >(\n matchLocation: CheckRelativePath<\n TAllRouteInfo,\n TRouteInfo['fullPath'],\n NoInfer<TTo>\n > &\n Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>,\n opts?: MatchRouteOptions,\n ) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams']\n navigate: <TTo extends string = '.'>(\n options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>,\n ) => Promise<void>\n action: unknown extends TRouteInfo['actionResponse']\n ?\n | Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>\n | undefined\n : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>\n loader: unknown extends TRouteInfo['routeLoaderData']\n ?\n | Action<\n LoaderContext<\n TRouteInfo['fullSearchSchema'],\n TRouteInfo['allParams']\n >,\n TRouteInfo['routeLoaderData']\n >\n | undefined\n : Loader<\n TRouteInfo['fullSearchSchema'],\n TRouteInfo['allParams'],\n TRouteInfo['routeLoaderData']\n >\n}\n\nexport function createRoute<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n>(\n routeConfig: RouteConfig,\n options: TRouteInfo['options'],\n parent: undefined | Route<TAllRouteInfo, any>,\n router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>,\n): Route<TAllRouteInfo, TRouteInfo> {\n const { id, routeId, path: routePath, fullPath } = routeConfig\n\n const action =\n router.state.actions[id] ||\n (() => {\n router.state.actions[id] = {\n submissions: [],\n submit: async <T, U>(\n submission: T,\n actionOpts?: { invalidate?: boolean; multi?: boolean },\n ) => {\n if (!route) {\n return\n }\n\n const invalidate = actionOpts?.invalidate ?? true\n\n if (!actionOpts?.multi) {\n action.submissions = action.submissions.filter((d) => d.isMulti)\n }\n\n const actionState: ActionState<T, U> = {\n submittedAt: Date.now(),\n status: 'pending',\n submission,\n isMulti: !!actionOpts?.multi,\n }\n\n action.current = actionState\n action.latest = actionState\n action.submissions.push(actionState)\n\n router.notify()\n\n try {\n const res = await route.options.action?.(submission)\n actionState.data = res as U\n\n if (invalidate) {\n router.invalidateRoute({ to: '.', fromCurrent: true })\n await router.reload()\n }\n actionState.status = 'success'\n return res\n } catch (err) {\n console.error(err)\n actionState.error = err\n actionState.status = 'error'\n } finally {\n router.notify()\n }\n },\n }\n return router.state.actions[id]!\n })()\n\n const loader =\n router.state.loaders[id] ||\n (() => {\n router.state.loaders[id] = {\n pending: [],\n fetch: (async (loaderContext: LoaderContext<any, any>) => {\n if (!route) {\n return\n }\n\n const loaderState: LoaderState<any, any> = {\n loadedAt: Date.now(),\n loaderContext,\n }\n\n loader.current = loaderState\n loader.latest = loaderState\n loader.pending.push(loaderState)\n\n // router.state = {\n // ...router.state,\n // currentAction: loaderState,\n // latestAction: loaderState,\n // }\n\n router.notify()\n\n try {\n return await route.options.loader?.(loaderContext)\n } finally {\n loader.pending = loader.pending.filter((d) => d !== loaderState)\n // router.removeActionQueue.push({ loader, loaderState })\n router.notify()\n }\n }) as any,\n }\n return router.state.loaders[id]!\n })()\n\n let route: Route<TAllRouteInfo, TRouteInfo> = {\n routeId: id,\n routeRouteId: routeId,\n routePath,\n fullPath,\n options,\n router,\n childRoutes: undefined!,\n parentRoute: parent,\n action,\n loader: loader as any,\n\n buildLink: (options) => {\n return router.buildLink({\n ...options,\n from: fullPath,\n } as any) as any\n },\n\n navigate: (options) => {\n return router.navigate({\n ...options,\n from: fullPath,\n } as any) as any\n },\n\n matchRoute: (matchLocation, opts) => {\n return router.matchRoute(\n {\n ...matchLocation,\n from: fullPath,\n } as any,\n opts,\n )\n },\n }\n\n router.options.createRoute?.({ router, route })\n\n return route\n}\n"],"names":["createRoute","routeConfig","options","parent","router","id","routeId","path","routePath","fullPath","action","state","actions","submissions","submit","submission","actionOpts","route","invalidate","multi","filter","d","isMulti","actionState","submittedAt","Date","now","status","current","latest","push","notify","res","data","invalidateRoute","to","fromCurrent","reload","err","console","error","loader","loaders","pending","fetch","loaderContext","loaderState","loadedAt","routeRouteId","childRoutes","undefined","parentRoute","buildLink","_extends","from","navigate","matchRoute","matchLocation","opts"],"mappings":";;;;;;;;;;;;;;;;AAkFO,SAASA,WAAT,CAILC,WAJK,EAKLC,OALK,EAMLC,MANK,EAOLC,MAPK,EAQ6B;EAClC,MAAM;IAAEC,EAAF;IAAMC,OAAN;AAAeC,IAAAA,IAAI,EAAEC,SAArB;AAAgCC,IAAAA,QAAAA;AAAhC,GAAA,GAA6CR,WAAnD,CAAA;;EAEA,MAAMS,MAAM,GACVN,MAAM,CAACO,KAAP,CAAaC,OAAb,CAAqBP,EAArB,CACA,IAAA,CAAC,MAAM;AACLD,IAAAA,MAAM,CAACO,KAAP,CAAaC,OAAb,CAAqBP,EAArB,CAA2B,GAAA;AACzBQ,MAAAA,WAAW,EAAE,EADY;AAEzBC,MAAAA,MAAM,EAAE,OACNC,UADM,EAENC,UAFM,KAGH;AAAA,QAAA,IAAA,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tD,MAAM,CAACoD,UAAP,CAAAH,oCAAA,CAAA,EAAA,EAEAI,aAFA,EAAA;AAGHH,QAAAA,IAAI,EAAE7C,QAAAA;AAHH,OAAA,CAAA,EAKLiD,IALK,CAAP,CAAA;AAOD,KAAA;GAlCH,CAAA;EAqCAtD,MAAM,CAACF,OAAP,CAAeF,WAAf,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAI,MAAM,CAACF,OAAP,CAAeF,WAAf,CAA6B;IAAEI,MAAF;AAAUa,IAAAA,KAAAA;GAAvC,CAAA,CAAA;AAEA,EAAA,OAAOA,KAAP,CAAA;AACD;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"routeConfig.js","sources":["../../../../../src/routeConfig.ts"],"sourcesContent":["import { GetFrameworkGeneric } from './frameworks'\nimport { ParsePathParams } from './link'\nimport { joinPaths, trimPath, trimPathRight } from './path'\nimport { RouteInfo } from './routeInfo'\nimport { RouteMatch } from './routeMatch'\nimport {\n DeepAwaited,\n Expand,\n IsAny,\n NoInfer,\n PickUnsafe,\n Values,\n} from './utils'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\n\nexport type AnyLoaderData = {}\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport interface RouteMeta {}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn, TParentSchema> =\n | SearchSchemaValidatorObj<TReturn, TParentSchema>\n | SearchSchemaValidatorFn<TReturn, TParentSchema>\n\nexport type SearchSchemaValidatorObj<TReturn, TParentSchema> = {\n parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>\n}\n\nexport type SearchSchemaValidatorFn<TReturn, TParentSchema> = (\n searchObj: Record<string, unknown>,\n) => {} extends TParentSchema\n ? TReturn\n : keyof TReturn extends keyof TParentSchema\n ? {\n error: 'Top level search params cannot be redefined by child routes!'\n keys: keyof TReturn & keyof TParentSchema\n }\n : TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TRouteLoaderData extends AnyLoaderData,\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> = (\n loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,\n) => Promise<TRouteLoaderData>\n\nexport interface LoaderContext<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> {\n params: TAllParams\n search: TFullSearchSchema\n signal?: AbortSignal\n}\n\nexport type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (\n submission: TActionPayload,\n) => TActionResponse | Promise<TActionResponse>\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, RouteInfo<string, TPath>>,\n) => void\n\nexport type RouteOptions<\n TRouteId extends string = string,\n TPath extends string = string,\n TRouteLoaderData extends AnyLoaderData = {},\n TLoaderData extends AnyLoaderData = {},\n TActionPayload = unknown,\n TActionResponse = unknown,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParentParams extends AnyPathParams = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams = {},\n> = (\n | {\n // The path to match (relative to the nearest parent `Route` component or root basepath)\n path: TPath\n }\n | {\n id: TRouteId\n }\n) & {\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // The duration to wait during `loader` execution before showing the `pendingElement`\n pendingMs?: number\n // _If the `pendingElement` is shown_, the minimum duration for which it will be visible.\n pendingMinMs?: number\n // The content to be rendered when the route is matched. If no element is provided, defaults to `<Outlet />`\n element?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>\n // The content to be rendered when `loader` encounters an error\n errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>\n // The content to be rendered when rendering encounters an error\n catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>\n // The content to be rendered when the duration of `loader` execution surpasses the `pendingMs` duration\n pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> //, NoInfer<TLoaderData>>\n // An asynchronous function responsible for preparing or fetching data for the route before it is rendered\n loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>\n // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch\n // Defaults to 0. Only stale loader data is refetched.\n loaderMaxAge?: number\n // The max age to cache the loader data for this route in milliseconds from the time of route inactivity\n // before it is garbage collected.\n loaderGcMaxAge?: number\n // An asynchronous function made available to the route for performing asynchronous or mutative actions that\n // might invalidate the route's data.\n action?: ActionFn<TActionPayload, TActionResponse>\n // Set this to true to rethrow errors up the component tree to either the nearest error boundary or\n // route with error element, whichever comes first.\n useErrorBoundary?: boolean\n // This function is called\n // when moving from an inactive state to an active one. Likewise, when moving from\n // an active to an inactive state, the return function (if provided) is called.\n onMatch?: (matchContext: {\n params: TAllParams\n search: TFullSearchSchema\n }) =>\n | void\n | undefined\n | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)\n // This function is called when the route remains active from one transition to the next.\n onTransition?: (match: {\n params: TAllParams\n search: TFullSearchSchema\n }) => void\n // An object of whatever you want! This object is accessible anywhere matches are.\n meta?: RouteMeta // TODO: Make this nested and mergeable\n} & (\n | {\n parseParams?: never\n stringifyParams?: never\n }\n | {\n // Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)\n parseParams: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams\n stringifyParams: (\n params: TParams,\n ) => Record<ParsePathParams<TPath>, string>\n }\n ) &\n (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined\n ? {}\n : 'Cannot redefined path params in child routes!')\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport interface RouteConfig<\n TId extends string = string,\n TRouteId extends string = string,\n TPath extends string = string,\n TFullPath extends string = string,\n TRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TLoaderData extends AnyLoaderData = AnyLoaderData,\n TActionPayload = unknown,\n TActionResponse = unknown,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams = {},\n TKnownChildren = unknown,\n> {\n id: TId\n routeId: TRouteId\n path: NoInfer<TPath>\n fullPath: TFullPath\n options: RouteOptions<\n TRouteId,\n TPath,\n TRouteLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams\n >\n children?: TKnownChildren\n addChildren: IsAny<\n TId,\n any,\n <TNewChildren extends any>(\n children: TNewChildren extends AnyRouteConfig[]\n ? TNewChildren\n : { error: 'Invalid route detected'; route: TNewChildren },\n ) => RouteConfig<\n TId,\n TRouteId,\n TPath,\n TFullPath,\n TRouteLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams,\n TNewChildren\n >\n >\n createChildren: IsAny<\n TId,\n any,\n <TNewChildren extends any>(\n cb: (\n createChildRoute: CreateRouteConfigFn<\n false,\n TId,\n TFullPath,\n TLoaderData,\n TFullSearchSchema,\n TAllParams\n >,\n ) => TNewChildren extends AnyRouteConfig[]\n ? TNewChildren\n : { error: 'Invalid route detected'; route: TNewChildren },\n ) => RouteConfig<\n TId,\n TRouteId,\n TPath,\n TFullPath,\n TRouteLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams,\n TNewChildren\n >\n >\n createRoute: CreateRouteConfigFn<\n false,\n TId,\n TFullPath,\n TLoaderData,\n TFullSearchSchema,\n TAllParams\n >\n}\n\ntype CreateRouteConfigFn<\n TIsRoot extends boolean = false,\n TParentId extends string = string,\n TParentPath extends string = string,\n TParentAllLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n> = <\n TRouteId extends string,\n TPath extends string,\n TRouteLoaderData extends AnyLoaderData,\n TActionPayload,\n TActionResponse,\n TSearchSchema extends AnySearchSchema = AnySearchSchema,\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams> = AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams>,\n TKnownChildren extends RouteConfig[] = RouteConfig[],\n TResolvedId extends string = string extends TRouteId\n ? string extends TPath\n ? string\n : TPath\n : TRouteId,\n>(\n options?: TIsRoot extends true\n ? Omit<\n RouteOptions<\n TRouteId,\n TPath,\n TRouteLoaderData,\n Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n 'path'\n > & { path?: never }\n : RouteOptions<\n TRouteId,\n TPath,\n TRouteLoaderData,\n Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n children?: TKnownChildren,\n isRoot?: boolean,\n parentId?: string,\n parentPath?: string,\n) => RouteConfig<\n RoutePrefix<TParentId, TResolvedId>,\n TResolvedId,\n TPath,\n string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,\n TRouteLoaderData,\n Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>,\n TKnownChildren\n>\n\ntype RoutePath<T extends string> = T extends RootRouteId\n ? '/'\n : TrimPathRight<`${T}`>\n\ntype RoutePrefix<\n TPrefix extends string,\n TId extends string,\n> = string extends TId\n ? RootRouteId\n : TId extends string\n ? `${TPrefix}/${TId}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`\n : never\n\nexport interface AnyRouteConfig\n extends RouteConfig<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport interface AnyRouteConfigWithChildren<TChildren>\n extends RouteConfig<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n TChildren\n > {}\n\ntype TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\ntype TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\ntype TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport const createRouteConfig: CreateRouteConfigFn<true> = (\n options = {} as any,\n children,\n isRoot = true,\n parentId,\n parentPath,\n) => {\n if (isRoot) {\n ;(options as any).path = rootRouteId\n }\n\n // Strip the root from parentIds\n if (parentId === rootRouteId) {\n parentId = ''\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const routeId = path || (options as { id?: string }).id\n\n let id = joinPaths([parentId, routeId])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]))\n\n return {\n id: id as any,\n routeId: routeId as any,\n path: path as any,\n fullPath: fullPath as any,\n options: options as any,\n children,\n createChildren: (cb: any) =>\n createRouteConfig(\n options,\n cb((childOptions: any) =>\n createRouteConfig(childOptions, undefined, false, id, fullPath),\n ),\n false,\n parentId,\n parentPath,\n ),\n addChildren: (children: any) =>\n createRouteConfig(options, children, false, parentId, parentPath),\n createRoute: (childOptions: any) =>\n createRouteConfig(childOptions, undefined, false, id, fullPath) as any,\n }\n}\n"],"names":["rootRouteId","createRouteConfig","options","children","isRoot","parentId","parentPath","path","trimPath","routeId","id","joinPaths","fullPath","trimPathRight","createChildren","cb","childOptions","undefined","addChildren","createRoute"],"mappings":";;;;;;;;;;;;;;;;AAcO,MAAMA,WAAW,GAAG,WAApB;AAoaMC,MAAAA,iBAA4C,GAAG,SAA/CA,iBAA+C,CAC1DC,OAD0D,EAE1DC,QAF0D,EAG1DC,MAH0D,EAI1DC,QAJ0D,EAK1DC,UAL0D,EAMvD;AAAA,EAAA,IALHJ,OAKG,KAAA,KAAA,CAAA,EAAA;AALHA,IAAAA,OAKG,GALO,EAKP,CAAA;AAAA,GAAA;;AAAA,EAAA,IAHHE,MAGG,KAAA,KAAA,CAAA,EAAA;AAHHA,IAAAA,MAGG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,iBAAiB,CAACe,YAAD,EAAeC,SAAf,EAA0B,KAA1B,EAAiCP,EAAjC,EAAqCE,QAArC,CADjB,CAFa,EAKf,KALe,EAMfP,QANe,EAOfC,UAPe,CARd;AAiBLY,IAAAA,WAAW,EAAGf,QAAD,IACXF,iBAAiB,CAACC,OAAD,EAAUC,QAAV,EAAoB,KAApB,EAA2BE,QAA3B,EAAqCC,UAArC,CAlBd;AAmBLa,IAAAA,WAAW,EAAGH,YAAD,IACXf,iBAAiB,CAACe,YAAD,EAAeC,SAAf,EAA0B,KAA1B,EAAiCP,EAAjC,EAAqCE,QAArC,CAAA;GApBrB,CAAA;AAsBD;;;;;"}
1
+ {"version":3,"file":"routeConfig.js","sources":["../../../../../src/routeConfig.ts"],"sourcesContent":["import { GetFrameworkGeneric } from './frameworks'\nimport { ParsePathParams } from './link'\nimport { joinPaths, trimPath, trimPathRight } from './path'\nimport { RouteInfo } from './routeInfo'\nimport { RouteMatch } from './routeMatch'\nimport {\n DeepAwaited,\n Expand,\n IsAny,\n NoInfer,\n PickUnsafe,\n Values,\n} from './utils'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\n\nexport type AnyLoaderData = {}\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport interface RouteMeta {}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn, TParentSchema> =\n | SearchSchemaValidatorObj<TReturn, TParentSchema>\n | SearchSchemaValidatorFn<TReturn, TParentSchema>\n\nexport type SearchSchemaValidatorObj<TReturn, TParentSchema> = {\n parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>\n}\n\nexport type SearchSchemaValidatorFn<TReturn, TParentSchema> = (\n searchObj: Record<string, unknown>,\n) => {} extends TParentSchema\n ? TReturn\n : keyof TReturn extends keyof TParentSchema\n ? {\n error: 'Top level search params cannot be redefined by child routes!'\n keys: keyof TReturn & keyof TParentSchema\n }\n : TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TRouteLoaderData extends AnyLoaderData = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> = (\n loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,\n) => Promise<TRouteLoaderData>\n\nexport interface LoaderContext<\n TFullSearchSchema extends AnySearchSchema = {},\n TAllParams extends AnyPathParams = {},\n> {\n params: TAllParams\n search: TFullSearchSchema\n signal?: AbortSignal\n // parentLoaderPromise?: Promise<TParentRouteLoaderData>\n}\n\nexport type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (\n submission: TActionPayload,\n) => TActionResponse | Promise<TActionResponse>\n\nexport type UnloaderFn<TPath extends string> = (\n routeMatch: RouteMatch<any, RouteInfo<string, TPath>>,\n) => void\n\nexport type RouteOptions<\n TRouteId extends string = string,\n TPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = {},\n TRouteLoaderData extends AnyLoaderData = {},\n TLoaderData extends AnyLoaderData = {},\n TActionPayload = unknown,\n TActionResponse = unknown,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = TSearchSchema,\n TParentParams extends AnyPathParams = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams = {},\n> = (\n | {\n // The path to match (relative to the nearest parent `Route` component or root basepath)\n path: TPath\n }\n | {\n id: TRouteId\n }\n) & {\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>\n // The content to be rendered when the route encounters an error\n errorComponent?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>\n // An asynchronous function responsible for preparing or fetching data for the route before it is rendered\n loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>\n // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch\n // Defaults to 0. Only stale loader data is refetched.\n loaderMaxAge?: number\n // The max age to cache the loader data for this route in milliseconds from the time of route inactivity\n // before it is garbage collected.\n loaderGcMaxAge?: number\n // An asynchronous function made available to the route for performing asynchronous or mutative actions that\n // might invalidate the route's data.\n action?: ActionFn<TActionPayload, TActionResponse>\n // This function is called\n // when moving from an inactive state to an active one. Likewise, when moving from\n // an active to an inactive state, the return function (if provided) is called.\n onMatch?: (matchContext: {\n params: TAllParams\n search: TFullSearchSchema\n }) =>\n | void\n | undefined\n | ((match: { params: TAllParams; search: TFullSearchSchema }) => void)\n // This function is called when the route remains active from one transition to the next.\n onTransition?: (match: {\n params: TAllParams\n search: TFullSearchSchema\n }) => void\n // An object of whatever you want! This object is accessible anywhere matches are.\n meta?: RouteMeta // TODO: Make this nested and mergeable\n} & (\n | {\n parseParams?: never\n stringifyParams?: never\n }\n | {\n // Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)\n parseParams: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams\n stringifyParams: (\n params: TParams,\n ) => Record<ParsePathParams<TPath>, string>\n }\n ) &\n (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined\n ? {}\n : 'Cannot redefined path params in child routes!')\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport interface RouteConfig<\n TId extends string = string,\n TRouteId extends string = string,\n TPath extends string = string,\n TFullPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TRouteLoaderData extends AnyLoaderData = AnyLoaderData,\n TLoaderData extends AnyLoaderData = AnyLoaderData,\n TActionPayload = unknown,\n TActionResponse = unknown,\n TParentSearchSchema extends {} = {},\n TSearchSchema extends AnySearchSchema = {},\n TFullSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams = {},\n TKnownChildren = unknown,\n> {\n id: TId\n routeId: TRouteId\n path: NoInfer<TPath>\n fullPath: TFullPath\n options: RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams\n >\n children?: TKnownChildren\n addChildren: IsAny<\n TId,\n any,\n <TNewChildren extends any>(\n children: TNewChildren extends AnyRouteConfig[]\n ? TNewChildren\n : { error: 'Invalid route detected'; route: TNewChildren },\n ) => RouteConfig<\n TId,\n TRouteId,\n TPath,\n TFullPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams,\n TNewChildren\n >\n >\n createChildren: IsAny<\n TId,\n any,\n <TNewChildren extends any>(\n cb: (\n createChildRoute: CreateRouteConfigFn<\n false,\n TId,\n TFullPath,\n TRouteLoaderData,\n TLoaderData,\n TFullSearchSchema,\n TAllParams\n >,\n ) => TNewChildren extends AnyRouteConfig[]\n ? TNewChildren\n : { error: 'Invalid route detected'; route: TNewChildren },\n ) => RouteConfig<\n TId,\n TRouteId,\n TPath,\n TFullPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n TLoaderData,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n TFullSearchSchema,\n TParentParams,\n TParams,\n TAllParams,\n TNewChildren\n >\n >\n createRoute: CreateRouteConfigFn<\n false,\n TId,\n TFullPath,\n TRouteLoaderData,\n TLoaderData,\n TFullSearchSchema,\n TAllParams\n >\n}\n\ntype CreateRouteConfigFn<\n TIsRoot extends boolean = false,\n TParentId extends string = string,\n TParentPath extends string = string,\n TParentRouteLoaderData extends AnyLoaderData = {},\n TParentLoaderData extends AnyLoaderData = {},\n TParentSearchSchema extends AnySearchSchema = {},\n TParentParams extends AnyPathParams = {},\n> = <\n TRouteId extends string,\n TPath extends string,\n TRouteLoaderData extends AnyLoaderData,\n TActionPayload,\n TActionResponse,\n TSearchSchema extends AnySearchSchema = AnySearchSchema,\n TParams extends Record<ParsePathParams<TPath>, unknown> = Record<\n ParsePathParams<TPath>,\n string\n >,\n TAllParams extends AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams> = AnyPathParams extends TParams\n ? Record<ParsePathParams<TPath>, string>\n : NoInfer<TParams>,\n TKnownChildren extends RouteConfig[] = RouteConfig[],\n TResolvedId extends string = string extends TRouteId\n ? string extends TPath\n ? string\n : TPath\n : TRouteId,\n>(\n options?: TIsRoot extends true\n ? Omit<\n RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n 'path'\n > & { path?: never }\n : RouteOptions<\n TRouteId,\n TPath,\n TParentRouteLoaderData,\n TRouteLoaderData,\n Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>\n >,\n children?: TKnownChildren,\n isRoot?: boolean,\n parentId?: string,\n parentPath?: string,\n) => RouteConfig<\n RoutePrefix<TParentId, TResolvedId>,\n TResolvedId,\n TPath,\n string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,\n TParentRouteLoaderData,\n TRouteLoaderData,\n Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,\n TActionPayload,\n TActionResponse,\n TParentSearchSchema,\n TSearchSchema,\n Expand<TParentSearchSchema & TSearchSchema>,\n TParentParams,\n TParams,\n Expand<TParentParams & TAllParams>,\n TKnownChildren\n>\n\ntype RoutePath<T extends string> = T extends RootRouteId\n ? '/'\n : TrimPathRight<`${T}`>\n\ntype RoutePrefix<\n TPrefix extends string,\n TId extends string,\n> = string extends TId\n ? RootRouteId\n : TId extends string\n ? `${TPrefix}/${TId}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`\n : never\n\nexport interface AnyRouteConfig\n extends RouteConfig<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport interface AnyRouteConfigWithChildren<TChildren>\n extends RouteConfig<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n TChildren\n > {}\n\ntype TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\ntype TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\ntype TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport const createRouteConfig: CreateRouteConfigFn<true> = (\n options = {} as any,\n children,\n isRoot = true,\n parentId,\n parentPath,\n) => {\n if (isRoot) {\n ;(options as any).path = rootRouteId\n }\n\n // Strip the root from parentIds\n if (parentId === rootRouteId) {\n parentId = ''\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const routeId = path || (options as { id?: string }).id\n\n let id = joinPaths([parentId, routeId])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]))\n\n return {\n id: id as any,\n routeId: routeId as any,\n path: path as any,\n fullPath: fullPath as any,\n options: options as any,\n children,\n createChildren: (cb: any) =>\n createRouteConfig(\n options,\n cb((childOptions: any) =>\n createRouteConfig(childOptions, undefined, false, id, fullPath),\n ),\n false,\n parentId,\n parentPath,\n ),\n addChildren: (children: any) =>\n createRouteConfig(options, children, false, parentId, parentPath),\n createRoute: (childOptions: any) =>\n createRouteConfig(childOptions, undefined, false, id, fullPath) as any,\n }\n}\n"],"names":["rootRouteId","createRouteConfig","options","children","isRoot","parentId","parentPath","path","trimPath","routeId","id","joinPaths","fullPath","trimPathRight","createChildren","cb","childOptions","undefined","addChildren","createRoute"],"mappings":";;;;;;;;;;;;;;;;AAcO,MAAMA,WAAW,GAAG,WAApB;AAyaMC,MAAAA,iBAA4C,GAAG,SAA/CA,iBAA+C,CAC1DC,OAD0D,EAE1DC,QAF0D,EAG1DC,MAH0D,EAI1DC,QAJ0D,EAK1DC,UAL0D,EAMvD;AAAA,EAAA,IALHJ,OAKG,KAAA,KAAA,CAAA,EAAA;AALHA,IAAAA,OAKG,GALO,EAKP,CAAA;AAAA,GAAA;;AAAA,EAAA,IAHHE,MAGG,KAAA,KAAA,CAAA,EAAA;AAHHA,IAAAA,MAGG,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iBAAiB,CAACe,YAAD,EAAeC,SAAf,EAA0B,KAA1B,EAAiCP,EAAjC,EAAqCE,QAArC,CADjB,CAFa,EAKf,KALe,EAMfP,QANe,EAOfC,UAPe,CARd;AAiBLY,IAAAA,WAAW,EAAGf,QAAD,IACXF,iBAAiB,CAACC,OAAD,EAAUC,QAAV,EAAoB,KAApB,EAA2BE,QAA3B,EAAqCC,UAArC,CAlBd;AAmBLa,IAAAA,WAAW,EAAGH,YAAD,IACXf,iBAAiB,CAACe,YAAD,EAAeC,SAAf,EAA0B,KAA1B,EAAiCP,EAAjC,EAAqCE,QAArC,CAAA;GApBrB,CAAA;AAsBD;;;;;"}
@@ -15,7 +15,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
15
15
  var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
16
16
  var utils = require('./utils.js');
17
17
 
18
- const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
18
+ const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
19
19
  function createRouteMatch(router, route, opts) {
20
20
  const routeMatch = _rollupPluginBabelHelpers["extends"]({}, route, opts, {
21
21
  router,
@@ -25,10 +25,10 @@ function createRouteMatch(router, route, opts) {
25
25
  status: 'idle',
26
26
  routeLoaderData: {},
27
27
  loaderData: {},
28
- isPending: false,
29
28
  isFetching: false,
30
29
  isInvalid: false,
31
30
  invalidAt: Infinity,
31
+ // pendingActions: [],
32
32
  getIsInvalid: () => {
33
33
  const now = Date.now();
34
34
  return routeMatch.isInvalid || routeMatch.invalidAt < now;
@@ -42,43 +42,6 @@ function createRouteMatch(router, route, opts) {
42
42
 
43
43
  routeMatch.router.notify();
44
44
  },
45
- startPending: () => {
46
- var _routeMatch$options$p, _routeMatch$options$p2;
47
-
48
- const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
49
- const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
50
-
51
- if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
52
- return;
53
- }
54
-
55
- routeMatch.__.pendingTimeout = setTimeout(() => {
56
- routeMatch.isPending = true;
57
-
58
- routeMatch.__.resolve();
59
-
60
- if (typeof pendingMinMs !== 'undefined') {
61
- routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
62
- }
63
- }, pendingMs);
64
- },
65
- cancelPending: () => {
66
- routeMatch.isPending = false;
67
- clearTimeout(routeMatch.__.pendingTimeout);
68
- clearTimeout(routeMatch.__.pendingMinTimeout);
69
- delete routeMatch.__.pendingMinPromise;
70
- },
71
- // setParentMatch: (parentMatch?: RouteMatch) => {
72
- // routeMatch.parentMatch = parentMatch
73
- // },
74
- // addChildMatch: (childMatch: RouteMatch) => {
75
- // if (
76
- // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
77
- // ) {
78
- // return
79
- // }
80
- // routeMatch.childMatches.push(childMatch)
81
- // },
82
45
  validate: () => {
83
46
  var _routeMatch$parentMat, _routeMatch$parentMat2;
84
47
 
@@ -86,9 +49,11 @@ function createRouteMatch(router, route, opts) {
86
49
  const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
87
50
 
88
51
  try {
52
+ var _validator;
53
+
89
54
  const prevSearch = routeMatch.routeSearch;
90
55
  const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
91
- let nextSearch = utils.replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
56
+ let nextSearch = utils.replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
92
57
 
93
58
  if (prevSearch !== nextSearch) {
94
59
  routeMatch.isInvalid = true;
@@ -96,6 +61,13 @@ function createRouteMatch(router, route, opts) {
96
61
 
97
62
  routeMatch.routeSearch = nextSearch;
98
63
  routeMatch.search = utils.replaceEqualDeep(parentSearch, _rollupPluginBabelHelpers["extends"]({}, parentSearch, nextSearch));
64
+ componentTypes.map(async type => {
65
+ const component = routeMatch.options[type];
66
+
67
+ if (typeof routeMatch.__[type] !== 'function') {
68
+ routeMatch.__[type] = component;
69
+ }
70
+ });
99
71
  } catch (err) {
100
72
  console.error(err);
101
73
  const error = new Error('Invalid search params found', {
@@ -113,14 +85,16 @@ function createRouteMatch(router, route, opts) {
113
85
  var _routeMatch$__$abortC;
114
86
 
115
87
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
116
-
117
- routeMatch.__.cancelPending();
118
88
  },
119
89
  invalidate: () => {
120
90
  routeMatch.isInvalid = true;
121
91
  },
122
92
  hasLoaders: () => {
123
- return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
93
+ return !!(route.options.loader || componentTypes.some(d => {
94
+ var _route$options$d;
95
+
96
+ return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
97
+ }));
124
98
  },
125
99
  load: async loaderOpts => {
126
100
  const now = Date.now();
@@ -141,17 +115,25 @@ function createRouteMatch(router, route, opts) {
141
115
 
142
116
  if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
143
117
  const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
144
- routeMatch.fetch({
118
+ await routeMatch.fetch({
145
119
  maxAge
146
120
  });
147
121
  }
148
122
  },
149
123
  fetch: async opts => {
150
- const id = '' + Date.now() + Math.random();
151
- routeMatch.__.latestId = id; // If the match was in an error state, set it
124
+ const loadId = '' + Date.now() + Math.random();
125
+ routeMatch.__.latestId = loadId;
126
+
127
+ const checkLatest = async () => {
128
+ if (loadId !== routeMatch.__.latestId) {
129
+ // warning(true, 'Data loader is out of date!')
130
+ return new Promise(() => {});
131
+ }
132
+ }; // If the match was in an error state, set it
152
133
  // to a loading state again. Otherwise, keep it
153
134
  // as loading or resolved
154
135
 
136
+
155
137
  if (routeMatch.status === 'idle') {
156
138
  routeMatch.status = 'loading';
157
139
  } // We started loading the route, so it's no longer invalid
@@ -164,94 +146,66 @@ function createRouteMatch(router, route, opts) {
164
146
  routeMatch.isFetching = true;
165
147
  routeMatch.__.resolve = resolve;
166
148
 
167
- const loaderPromise = (async () => {
168
- // Load the elements and data in parallel
169
- routeMatch.__.elementsPromise = (async () => {
170
- // then run all element and data loaders in parallel
171
- // For each element type, potentially load it asynchronously
172
- await Promise.all(elementTypes.map(async type => {
173
- const routeElement = routeMatch.options[type];
174
-
175
- if (routeMatch.__[type]) {
176
- return;
177
- }
178
-
179
- routeMatch.__[type] = await router.options.createElement(routeElement);
180
- }));
181
- })();
182
-
183
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
184
- try {
185
- var _ref, _ref2, _opts$maxAge;
186
-
187
- if (routeMatch.options.loader) {
188
- const data = await routeMatch.options.loader({
189
- params: routeMatch.params,
190
- search: routeMatch.routeSearch,
191
- signal: routeMatch.__.abortController.signal
192
- });
193
-
194
- if (id !== routeMatch.__.latestId) {
195
- return routeMatch.__.loaderPromise;
196
- }
197
-
198
- routeMatch.routeLoaderData = utils.replaceEqualDeep(routeMatch.routeLoaderData, data);
199
- }
200
-
201
- routeMatch.error = undefined;
202
- routeMatch.status = 'success';
203
- routeMatch.updatedAt = Date.now();
204
- routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
205
- } catch (err) {
206
- if (id !== routeMatch.__.latestId) {
207
- return routeMatch.__.loaderPromise;
208
- }
209
-
210
- if (process.env.NODE_ENV !== 'production') {
211
- console.error(err);
212
- }
213
-
214
- routeMatch.error = err;
215
- routeMatch.status = 'error';
216
- routeMatch.updatedAt = Date.now();
217
- }
218
- });
149
+ routeMatch.__.componentsPromise = (async () => {
150
+ // then run all component and data loaders in parallel
151
+ // For each component type, potentially load it asynchronously
152
+ await Promise.all(componentTypes.map(async type => {
153
+ var _routeMatch$__$type;
219
154
 
220
- try {
221
- await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
155
+ const component = routeMatch.options[type];
222
156
 
223
- if (id !== routeMatch.__.latestId) {
224
- return routeMatch.__.loaderPromise;
157
+ if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
158
+ routeMatch.__[type] = await router.options.loadComponent(component);
225
159
  }
160
+ }));
161
+ })();
226
162
 
227
- if (routeMatch.__.pendingMinPromise) {
228
- await routeMatch.__.pendingMinPromise;
229
- delete routeMatch.__.pendingMinPromise;
230
- }
231
- } finally {
232
- if (id !== routeMatch.__.latestId) {
233
- return routeMatch.__.loaderPromise;
163
+ routeMatch.__.dataPromise = Promise.resolve().then(async () => {
164
+ try {
165
+ var _ref, _ref2, _opts$maxAge;
166
+
167
+ if (routeMatch.options.loader) {
168
+ const data = await router.loadMatchData(routeMatch);
169
+ await checkLatest();
170
+ routeMatch.routeLoaderData = utils.replaceEqualDeep(routeMatch.routeLoaderData, data);
234
171
  }
235
172
 
236
- routeMatch.__.cancelPending();
173
+ routeMatch.error = undefined;
174
+ routeMatch.status = 'success';
175
+ routeMatch.updatedAt = Date.now();
176
+ routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
177
+ return routeMatch.routeLoaderData;
178
+ } catch (err) {
179
+ await checkLatest();
237
180
 
238
- routeMatch.isPending = false;
239
- routeMatch.isFetching = false;
181
+ if (process.env.NODE_ENV !== 'production') {
182
+ console.error(err);
183
+ }
240
184
 
241
- routeMatch.__.notify();
185
+ routeMatch.error = err;
186
+ routeMatch.status = 'error';
187
+ routeMatch.updatedAt = Date.now();
188
+ throw err;
242
189
  }
243
- })();
190
+ });
244
191
 
245
- routeMatch.__.loaderPromise = loaderPromise;
246
- await loaderPromise;
192
+ const after = async () => {
193
+ await checkLatest();
194
+ routeMatch.isFetching = false;
195
+ delete routeMatch.__.loadPromise;
247
196
 
248
- if (id !== routeMatch.__.latestId) {
249
- return routeMatch.__.loaderPromise;
250
- }
197
+ routeMatch.__.notify();
198
+ };
251
199
 
252
- delete routeMatch.__.loaderPromise;
200
+ try {
201
+ await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
202
+ after();
203
+ } catch (_unused) {
204
+ after();
205
+ }
253
206
  });
254
- return await routeMatch.__.loadPromise;
207
+ await routeMatch.__.loadPromise;
208
+ await checkLatest();
255
209
  }
256
210
  });
257
211