@tanstack/router-core 0.0.1-beta.11 → 0.0.1-beta.13

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.
@@ -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,GAHM,IAGN,CAAA;AAAA,GAAA;;AACH,EAAA,IAAIA,MAAJ,EAAY;IACRF,OAAD,CAAiBK,IAAjB,GAAwBP,WAAxB,CAAA;AACF,GAHE;;;EAMH,IAAIK,QAAQ,KAAKL,WAAjB,EAA8B;AAC5BK,IAAAA,QAAQ,GAAG,EAAX,CAAA;AACD,GAAA;;EAED,IAAIE,MAAwB,GAAGH,MAAM,GAAGJ,W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a,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}\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 content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: GetFrameworkGeneric<'Component'> // , NoInfer<TLoaderData>>\n // The content to be rendered when the route encounters an error\n errorComponent?: GetFrameworkGeneric<'Component'> // , NoInfer<TLoaderData>>\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<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 component, 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;AA8ZMC,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,GAHM,IAGN,CAAA;AAAA,GAAA;;AACH,EAAA,IAAIA,MAAJ,EAAY;IACRF,OAAD,CAAiBK,IAAjB,GAAwBP,WAAxB,CAAA;AACF,GAHE;;;EAMH,IAAIK,QAAQ,KAAKL,WAAjB,EAA8B;AAC5BK,IAAAA,QAAQ,GAAG,EAAX,CAAA;AACD,GAAA;;EAED,IAAIE,MAAwB,GAAGH,MAAM,GAAGJ,WAAH,GAAiBE,OAAO,CAACK,IAA9D,CAVG;;AAaH,EAAA,IAAIA,MAAI,IAAIA,MAAI,KAAK,GAArB,EAA0B;AACxBA,IAAAA,MAAI,GAAGC,aAAQ,CAACD,MAAD,CAAf,CAAA;AACD,GAAA;;AAED,EAAA,MAAME,OAAO,GAAGF,MAAI,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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,7 +25,6 @@ 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,
@@ -43,32 +42,6 @@ function createRouteMatch(router, route, opts) {
43
42
 
44
43
  routeMatch.router.notify();
45
44
  },
46
- startPending: () => {
47
- var _routeMatch$options$p, _routeMatch$options$p2;
48
-
49
- const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
50
- const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
51
-
52
- if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
53
- return;
54
- }
55
-
56
- routeMatch.__.pendingTimeout = setTimeout(() => {
57
- routeMatch.isPending = true;
58
-
59
- routeMatch.__.resolve();
60
-
61
- if (typeof pendingMinMs !== 'undefined') {
62
- routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
63
- }
64
- }, pendingMs);
65
- },
66
- cancelPending: () => {
67
- routeMatch.isPending = false;
68
- clearTimeout(routeMatch.__.pendingTimeout);
69
- clearTimeout(routeMatch.__.pendingMinTimeout);
70
- delete routeMatch.__.pendingMinPromise;
71
- },
72
45
  validate: () => {
73
46
  var _routeMatch$parentMat, _routeMatch$parentMat2;
74
47
 
@@ -88,11 +61,11 @@ function createRouteMatch(router, route, opts) {
88
61
 
89
62
  routeMatch.routeSearch = nextSearch;
90
63
  routeMatch.search = utils.replaceEqualDeep(parentSearch, _rollupPluginBabelHelpers["extends"]({}, parentSearch, nextSearch));
91
- elementTypes.map(async type => {
92
- const routeElement = routeMatch.options[type];
64
+ componentTypes.map(async type => {
65
+ const component = routeMatch.options[type];
93
66
 
94
67
  if (typeof routeMatch.__[type] !== 'function') {
95
- routeMatch.__[type] = routeElement;
68
+ routeMatch.__[type] = component;
96
69
  }
97
70
  });
98
71
  } catch (err) {
@@ -112,14 +85,16 @@ function createRouteMatch(router, route, opts) {
112
85
  var _routeMatch$__$abortC;
113
86
 
114
87
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
115
-
116
- routeMatch.__.cancelPending();
117
88
  },
118
89
  invalidate: () => {
119
90
  routeMatch.isInvalid = true;
120
91
  },
121
92
  hasLoaders: () => {
122
- 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
+ }));
123
98
  },
124
99
  load: async loaderOpts => {
125
100
  const now = Date.now();
@@ -163,91 +138,79 @@ function createRouteMatch(router, route, opts) {
163
138
  routeMatch.isFetching = true;
164
139
  routeMatch.__.resolve = resolve;
165
140
 
166
- routeMatch.__.loaderDataPromise = (async () => {
167
- // Load the elements and data in parallel
168
- routeMatch.__.elementsPromise = (async () => {
169
- // then run all element and data loaders in parallel
170
- // For each element type, potentially load it asynchronously
171
- await Promise.all(elementTypes.map(async type => {
172
- const routeElement = routeMatch.options[type];
173
-
174
- if (typeof routeMatch.__[type] === 'function') {
175
- routeMatch.__[type] = await router.options.createElement(routeElement);
176
- }
177
- }));
178
- })();
141
+ routeMatch.__.componentsPromise = (async () => {
142
+ // then run all component and data loaders in parallel
143
+ // For each component type, potentially load it asynchronously
144
+ await Promise.all(componentTypes.map(async type => {
145
+ var _routeMatch$__$type;
179
146
 
180
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
181
- try {
182
- var _ref, _ref2, _opts$maxAge;
147
+ const component = routeMatch.options[type];
183
148
 
184
- if (routeMatch.options.loader) {
185
- const data = await routeMatch.options.loader({
186
- params: routeMatch.params,
187
- search: routeMatch.routeSearch,
188
- signal: routeMatch.__.abortController.signal
189
- });
149
+ if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
150
+ routeMatch.__[type] = await router.options.loadComponent(component);
151
+ }
152
+ }));
153
+ })();
190
154
 
191
- if (id !== routeMatch.__.latestId) {
192
- return routeMatch.__.loadPromise;
193
- }
155
+ routeMatch.__.dataPromise = Promise.resolve().then(async () => {
156
+ try {
157
+ var _ref, _ref2, _opts$maxAge;
194
158
 
195
- routeMatch.routeLoaderData = utils.replaceEqualDeep(routeMatch.routeLoaderData, data);
196
- }
159
+ if (routeMatch.options.loader) {
160
+ const data = await routeMatch.options.loader({
161
+ params: routeMatch.params,
162
+ search: routeMatch.routeSearch,
163
+ signal: routeMatch.__.abortController.signal
164
+ });
197
165
 
198
- routeMatch.error = undefined;
199
- routeMatch.status = 'success';
200
- routeMatch.updatedAt = Date.now();
201
- 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);
202
- } catch (err) {
203
166
  if (id !== routeMatch.__.latestId) {
204
167
  return routeMatch.__.loadPromise;
205
168
  }
206
169
 
207
- if (process.env.NODE_ENV !== 'production') {
208
- console.error(err);
209
- }
210
-
211
- routeMatch.error = err;
212
- routeMatch.status = 'error';
213
- routeMatch.updatedAt = Date.now();
170
+ routeMatch.routeLoaderData = utils.replaceEqualDeep(routeMatch.routeLoaderData, data);
214
171
  }
215
- });
216
-
217
- try {
218
- await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
219
172
 
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
+ } catch (err) {
220
178
  if (id !== routeMatch.__.latestId) {
221
179
  return routeMatch.__.loadPromise;
222
180
  }
223
181
 
224
- if (routeMatch.__.pendingMinPromise) {
225
- await routeMatch.__.pendingMinPromise;
226
- delete routeMatch.__.pendingMinPromise;
227
- }
228
- } finally {
229
- if (id !== routeMatch.__.latestId) {
230
- return routeMatch.__.loadPromise;
182
+ if (process.env.NODE_ENV !== 'production') {
183
+ console.error(err);
231
184
  }
232
185
 
233
- routeMatch.__.cancelPending();
186
+ routeMatch.error = err;
187
+ routeMatch.status = 'error';
188
+ routeMatch.updatedAt = Date.now();
189
+ }
190
+ });
234
191
 
235
- routeMatch.isPending = false;
236
- routeMatch.isFetching = false;
192
+ try {
193
+ await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise]);
237
194
 
238
- routeMatch.__.notify();
195
+ if (id !== routeMatch.__.latestId) {
196
+ return routeMatch.__.loadPromise;
197
+ }
198
+ } finally {
199
+ if (id !== routeMatch.__.latestId) {
200
+ return routeMatch.__.loadPromise;
239
201
  }
240
- })();
241
202
 
242
- await routeMatch.__.loaderDataPromise;
203
+ routeMatch.isFetching = false;
243
204
 
244
- if (id !== routeMatch.__.latestId) {
245
- return routeMatch.__.loadPromise;
205
+ routeMatch.__.notify();
246
206
  }
247
-
248
- delete routeMatch.__.loaderDataPromise;
249
207
  });
250
208
  await routeMatch.__.loadPromise;
209
+
210
+ if (id !== routeMatch.__.latestId) {
211
+ return routeMatch.__.loadPromise;
212
+ }
213
+
251
214
  delete routeMatch.__.loadPromise;
252
215
  }
253
216
  });
@@ -1 +1 @@
1
- {"version":3,"file":"routeMatch.js","sources":["../../../../../src/routeMatch.ts"],"sourcesContent":["import { GetFrameworkGeneric } from './frameworks'\nimport { Route } from './route'\nimport {\n AnyAllRouteInfo,\n AnyRouteInfo,\n DefaultAllRouteInfo,\n RouteInfo,\n} from './routeInfo'\nimport { ActionState, Router } from './router'\nimport { replaceEqualDeep, Timeout } from './utils'\n\nexport interface RouteMatch<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n> extends Route<TAllRouteInfo, TRouteInfo> {\n matchId: string\n pathname: string\n params: TRouteInfo['params']\n parentMatch?: RouteMatch\n childMatches: RouteMatch[]\n routeSearch: TRouteInfo['searchSchema']\n search: TRouteInfo['fullSearchSchema']\n status: 'idle' | 'loading' | 'success' | 'error'\n updatedAt?: number\n error?: unknown\n isInvalid: boolean\n getIsInvalid: () => boolean\n loaderData: TRouteInfo['loaderData']\n routeLoaderData: TRouteInfo['routeLoaderData']\n isFetching: boolean\n isPending: boolean\n invalidAt: number\n __: {\n element?: GetFrameworkGeneric<'Element'> // , TRouteInfo['loaderData']>\n errorElement?: GetFrameworkGeneric<'Element'> // , TRouteInfo['loaderData']>\n catchElement?: GetFrameworkGeneric<'Element'> // , TRouteInfo['loaderData']>\n pendingElement?: GetFrameworkGeneric<'Element'> // , TRouteInfo['loaderData']>\n loadPromise?: Promise<void>\n loaderDataPromise?: Promise<void>\n elementsPromise?: Promise<void>\n dataPromise?: Promise<void>\n pendingTimeout?: Timeout\n pendingMinTimeout?: Timeout\n pendingMinPromise?: Promise<void>\n onExit?:\n | void\n | ((matchContext: {\n params: TRouteInfo['allParams']\n search: TRouteInfo['fullSearchSchema']\n }) => void)\n abortController: AbortController\n latestId: string\n // setParentMatch: (parentMatch: RouteMatch) => void\n // addChildMatch: (childMatch: RouteMatch) => void\n validate: () => void\n startPending: () => void\n cancelPending: () => void\n notify: () => void\n resolve: () => void\n }\n cancel: () => void\n load: (\n loaderOpts?: { withPending?: boolean } & (\n | { preload: true; maxAge: number; gcMaxAge: number }\n | { preload?: false; maxAge?: never; gcMaxAge?: never }\n ),\n ) => Promise<TRouteInfo['routeLoaderData']>\n fetch: (opts?: { maxAge?: number }) => Promise<TRouteInfo['routeLoaderData']>\n invalidate: () => void\n hasLoaders: () => boolean\n}\n\nconst elementTypes = [\n 'element',\n 'errorElement',\n 'catchElement',\n 'pendingElement',\n] as const\n\nexport function createRouteMatch<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n>(\n router: Router<any, any>,\n route: Route<TAllRouteInfo, TRouteInfo>,\n opts: {\n matchId: string\n params: TRouteInfo['allParams']\n pathname: string\n },\n): RouteMatch<TAllRouteInfo, TRouteInfo> {\n const routeMatch: RouteMatch<TAllRouteInfo, TRouteInfo> = {\n ...route,\n ...opts,\n router,\n routeSearch: {},\n search: {},\n childMatches: [],\n status: 'idle',\n routeLoaderData: {} as TRouteInfo['routeLoaderData'],\n loaderData: {} as TRouteInfo['loaderData'],\n isPending: false,\n isFetching: false,\n isInvalid: false,\n invalidAt: Infinity,\n // pendingActions: [],\n getIsInvalid: () => {\n const now = Date.now()\n return routeMatch.isInvalid || routeMatch.invalidAt < now\n },\n __: {\n abortController: new AbortController(),\n latestId: '',\n resolve: () => {},\n notify: () => {\n routeMatch.__.resolve()\n routeMatch.router.notify()\n },\n startPending: () => {\n const pendingMs =\n routeMatch.options.pendingMs ?? router.options.defaultPendingMs\n const pendingMinMs =\n routeMatch.options.pendingMinMs ?? router.options.defaultPendingMinMs\n\n if (\n routeMatch.__.pendingTimeout ||\n routeMatch.status !== 'loading' ||\n typeof pendingMs === 'undefined'\n ) {\n return\n }\n\n routeMatch.__.pendingTimeout = setTimeout(() => {\n routeMatch.isPending = true\n routeMatch.__.resolve()\n if (typeof pendingMinMs !== 'undefined') {\n routeMatch.__.pendingMinPromise = new Promise(\n (r) =>\n (routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs)),\n )\n }\n }, pendingMs)\n },\n cancelPending: () => {\n routeMatch.isPending = false\n clearTimeout(routeMatch.__.pendingTimeout)\n clearTimeout(routeMatch.__.pendingMinTimeout)\n delete routeMatch.__.pendingMinPromise\n },\n validate: () => {\n // Validate the search params and stabilize them\n const parentSearch =\n routeMatch.parentMatch?.search ?? router.location.search\n\n try {\n const prevSearch = routeMatch.routeSearch\n\n const validator =\n typeof routeMatch.options.validateSearch === 'object'\n ? routeMatch.options.validateSearch.parse\n : routeMatch.options.validateSearch\n\n let nextSearch = replaceEqualDeep(\n prevSearch,\n validator?.(parentSearch) ?? {},\n )\n\n // Invalidate route matches when search param stability changes\n if (prevSearch !== nextSearch) {\n routeMatch.isInvalid = true\n }\n\n routeMatch.routeSearch = nextSearch\n\n routeMatch.search = replaceEqualDeep(parentSearch, {\n ...parentSearch,\n ...nextSearch,\n })\n\n elementTypes.map(async (type) => {\n const routeElement = routeMatch.options[type]\n\n if (typeof routeMatch.__[type] !== 'function') {\n routeMatch.__[type] = routeElement\n }\n })\n } catch (err: any) {\n console.error(err)\n const error = new (Error as any)('Invalid search params found', {\n cause: err,\n })\n error.code = 'INVALID_SEARCH_PARAMS'\n routeMatch.status = 'error'\n routeMatch.error = error\n // Do not proceed with loading the route\n return\n }\n },\n },\n cancel: () => {\n routeMatch.__.abortController?.abort()\n routeMatch.__.cancelPending()\n },\n invalidate: () => {\n routeMatch.isInvalid = true\n },\n hasLoaders: () => {\n return !!(\n route.options.loader ||\n elementTypes.some((d) => typeof route.options[d] === 'function')\n )\n },\n load: async (loaderOpts) => {\n const now = Date.now()\n const minMaxAge = loaderOpts?.preload\n ? Math.max(loaderOpts?.maxAge, loaderOpts?.gcMaxAge)\n : 0\n\n // If this is a preload, add it to the preload cache\n if (loaderOpts?.preload && minMaxAge > 0) {\n // If the match is currently active, don't preload it\n if (\n router.state.matches.find((d) => d.matchId === routeMatch.matchId)\n ) {\n return\n }\n\n router.matchCache[routeMatch.matchId] = {\n gc: now + loaderOpts.gcMaxAge,\n match: routeMatch as RouteMatch<any, any>,\n }\n }\n\n // If the match is invalid, errored or idle, trigger it to load\n if (\n (routeMatch.status === 'success' && routeMatch.getIsInvalid()) ||\n routeMatch.status === 'error' ||\n routeMatch.status === 'idle'\n ) {\n const maxAge = loaderOpts?.preload ? loaderOpts?.maxAge : undefined\n\n await routeMatch.fetch({ maxAge })\n }\n },\n fetch: async (opts) => {\n const id = '' + Date.now() + Math.random()\n routeMatch.__.latestId = id\n\n // If the match was in an error state, set it\n // to a loading state again. Otherwise, keep it\n // as loading or resolved\n if (routeMatch.status === 'idle') {\n routeMatch.status = 'loading'\n }\n\n // We started loading the route, so it's no longer invalid\n routeMatch.isInvalid = false\n\n routeMatch.__.loadPromise = new Promise(async (resolve) => {\n // We are now fetching, even if it's in the background of a\n // resolved state\n routeMatch.isFetching = true\n routeMatch.__.resolve = resolve as () => void\n\n routeMatch.__.loaderDataPromise = (async () => {\n // Load the elements and data in parallel\n\n routeMatch.__.elementsPromise = (async () => {\n // then run all element and data loaders in parallel\n // For each element type, potentially load it asynchronously\n\n await Promise.all(\n elementTypes.map(async (type) => {\n const routeElement = routeMatch.options[type]\n\n if (typeof routeMatch.__[type] === 'function') {\n routeMatch.__[type] = await router.options.createElement!(\n routeElement,\n )\n }\n }),\n )\n })()\n\n routeMatch.__.dataPromise = Promise.resolve().then(async () => {\n try {\n if (routeMatch.options.loader) {\n const data = await routeMatch.options.loader({\n params: routeMatch.params,\n search: routeMatch.routeSearch,\n signal: routeMatch.__.abortController.signal,\n })\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n routeMatch.routeLoaderData = replaceEqualDeep(\n routeMatch.routeLoaderData,\n data,\n )\n }\n\n routeMatch.error = undefined\n routeMatch.status = 'success'\n routeMatch.updatedAt = Date.now()\n routeMatch.invalidAt =\n routeMatch.updatedAt +\n (opts?.maxAge ??\n routeMatch.options.loaderMaxAge ??\n router.options.defaultLoaderMaxAge ??\n 0)\n } catch (err) {\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n if (process.env.NODE_ENV !== 'production') {\n console.error(err)\n }\n routeMatch.error = err\n routeMatch.status = 'error'\n routeMatch.updatedAt = Date.now()\n }\n })\n\n try {\n await Promise.all([\n routeMatch.__.elementsPromise,\n routeMatch.__.dataPromise,\n ])\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n if (routeMatch.__.pendingMinPromise) {\n await routeMatch.__.pendingMinPromise\n delete routeMatch.__.pendingMinPromise\n }\n } finally {\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n routeMatch.__.cancelPending()\n routeMatch.isPending = false\n routeMatch.isFetching = false\n routeMatch.__.notify()\n }\n })()\n\n await routeMatch.__.loaderDataPromise\n\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n delete routeMatch.__.loaderDataPromise\n })\n\n await routeMatch.__.loadPromise\n\n delete routeMatch.__.loadPromise\n },\n }\n\n if (!routeMatch.hasLoaders()) {\n routeMatch.status = 'success'\n }\n\n return routeMatch\n}\n"],"names":["elementTypes","createRouteMatch","router","route","opts","routeMatch","_extends","routeSearch","search","childMatches","status","routeLoaderData","loaderData","isPending","isFetching","isInvalid","invalidAt","Infinity","getIsInvalid","now","Date","__","abortController","AbortController","latestId","resolve","notify","startPending","pendingMs","options","defaultPendingMs","pendingMinMs","defaultPendingMinMs","pendingTimeout","setTimeout","pendingMinPromise","Promise","r","pendingMinTimeout","cancelPending","clearTimeout","validate","parentSearch","parentMatch","location","prevSearch","validator","validateSearch","parse","nextSearch","replaceEqualDeep","map","type","routeElement","err","console","error","Error","cause","code","cancel","abort","invalidate","hasLoaders","loader","some","d","load","loaderOpts","minMaxAge","preload","Math","max","maxAge","gcMaxAge","state","matches","find","matchId","matchCache","gc","match","undefined","fetch","id","random","loadPromise","loaderDataPromise","elementsPromise","all","createElement","dataPromise","then","data","params","signal","updatedAt","loaderMaxAge","defaultLoaderMaxAge","process","env","NODE_ENV"],"mappings":";;;;;;;;;;;;;;;;;AAwEA,MAAMA,YAAY,GAAG,CACnB,SADmB,EAEnB,cAFmB,EAGnB,cAHmB,EAInB,gBAJmB,CAArB,CAAA;AAOO,SAASC,gBAAT,CAILC,MAJK,EAKLC,KALK,EAMLC,IANK,EAWkC;AACvC,EAAA,MAAMC,UAAiD,GAAAC,oCAAA,CAAA,EAAA,EAClDH,KADkD,EAElDC,IAFkD,EAAA;IAGrDF,MAHqD;AAIrDK,IAAAA,WAAW,EAAE,EAJwC;AAKrDC,IAAAA,MAAM,EAAE,EAL6C;AAMrDC,IAAAA,YAAY,EAAE,EANuC;AAOrDC,IAAAA,MAAM,EAAE,MAP6C;AAQrDC,IAAAA,eAAe,EAAE,EARoC;AASrDC,IAAAA,UAAU,EAAE,EATyC;AAUrDC,IAAAA,SAAS,EAAE,KAV0C;AAWrDC,IAAAA,UAAU,EAAE,KAXyC;AAYrDC,IAAAA,SAAS,EAAE,KAZ0C;AAarDC,IAAAA,SAAS,EAAEC,QAb0C;AAcrD;AACAC,IAAAA,YAAY,EAAE,MAAM;AAClB,MAAA,MAAMC,GAAG,GAAGC,IAAI,CAACD,GAAL,EAAZ,CAAA;MACA,OAAOd,UAAU,CAACU,SAAX,IAAwBV,UAAU,CAACW,SAAX,GAAuBG,GAAtD,CAAA;KAjBmD;AAmBrDE,IAAAA,EAAE,EAAE;MACFC,eAAe,EAAE,IAAIC,eAAJ,EADf;AAEFC,MAAAA,QAAQ,EAAE,EAFR;MAGFC,OAAO,EAAE,MAAM,EAHb;AAIFC,MAAAA,MAAM,EAAE,MAAM;QACZrB,UAAU,CAACgB,EAAX,CAAcI,OAAd,EAAA,CAAA;;QACApB,UAAU,CAACH,MAAX,CAAkBwB,MAAlB,EAAA,CAAA;OANA;AAQFC,MAAAA,YAAY,EAAE,MAAM;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AAA,OAAOnB,UAAU,CAACgB,EAAX,CAAciE,WAArB,CAAA;AACD,aAAA;;YACDjF,UAAU,CAACgB,EAAX,CAAckB,aAAd,EAAA,CAAA;;YACAlC,UAAU,CAACQ,SAAX,GAAuB,KAAvB,CAAA;YACAR,UAAU,CAACS,UAAX,GAAwB,KAAxB,CAAA;;YACAT,UAAU,CAACgB,EAAX,CAAcK,MAAd,EAAA,CAAA;AACD,WAAA;AACF,SAnFiC,GAAlC,CAAA;;AAqFA,QAAA,MAAMrB,UAAU,CAACgB,EAAX,CAAckE,iBAApB,CAAA;;AAEA,QAAA,IAAIH,EAAE,KAAK/E,UAAU,CAACgB,EAAX,CAAcG,QAAzB,EAAmC;AACjC,UAAA,OAAOnB,UAAU,CAACgB,EAAX,CAAciE,WAArB,CAAA;AACD,SAAA;;AAED,QAAA,OAAOjF,UAAU,CAACgB,EAAX,CAAckE,iBAArB,CAAA;AACD,OAlG2B,CAA5B,CAAA;AAoGA,MAAA,MAAMlF,UAAU,CAACgB,EAAX,CAAciE,WAApB,CAAA;AAEA,MAAA,OAAOjF,UAAU,CAACgB,EAAX,CAAciE,WAArB,CAAA;AACD,KAAA;GA9QH,CAAA,CAAA;;AAiRA,EAAA,IAAI,CAACjF,UAAU,CAAC0D,UAAX,EAAL,EAA8B;IAC5B1D,UAAU,CAACK,MAAX,GAAoB,SAApB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOL,UAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"routeMatch.js","sources":["../../../../../src/routeMatch.ts"],"sourcesContent":["import { GetFrameworkGeneric } from './frameworks'\nimport { Route } from './route'\nimport {\n AnyAllRouteInfo,\n AnyRouteInfo,\n DefaultAllRouteInfo,\n RouteInfo,\n} from './routeInfo'\nimport { ActionState, Router } from './router'\nimport { replaceEqualDeep, Timeout } from './utils'\n\nexport interface RouteMatch<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n> extends Route<TAllRouteInfo, TRouteInfo> {\n matchId: string\n pathname: string\n params: TRouteInfo['params']\n parentMatch?: RouteMatch\n childMatches: RouteMatch[]\n routeSearch: TRouteInfo['searchSchema']\n search: TRouteInfo['fullSearchSchema']\n status: 'idle' | 'loading' | 'success' | 'error'\n updatedAt?: number\n error?: unknown\n isInvalid: boolean\n getIsInvalid: () => boolean\n loaderData: TRouteInfo['loaderData']\n routeLoaderData: TRouteInfo['routeLoaderData']\n isFetching: boolean\n invalidAt: number\n __: {\n component?: GetFrameworkGeneric<'Component'> // , TRouteInfo['loaderData']>\n errorComponent?: GetFrameworkGeneric<'Component'> // , TRouteInfo['loaderData']>\n pendingComponent?: GetFrameworkGeneric<'Component'> // , TRouteInfo['loaderData']>\n loadPromise?: Promise<void>\n componentsPromise?: Promise<void>\n dataPromise?: Promise<void>\n onExit?:\n | void\n | ((matchContext: {\n params: TRouteInfo['allParams']\n search: TRouteInfo['fullSearchSchema']\n }) => void)\n abortController: AbortController\n latestId: string\n // setParentMatch: (parentMatch: RouteMatch) => void\n // addChildMatch: (childMatch: RouteMatch) => void\n validate: () => void\n notify: () => void\n resolve: () => void\n }\n cancel: () => void\n load: (\n loaderOpts?:\n | { preload: true; maxAge: number; gcMaxAge: number }\n | { preload?: false; maxAge?: never; gcMaxAge?: never },\n ) => Promise<TRouteInfo['routeLoaderData']>\n fetch: (opts?: { maxAge?: number }) => Promise<TRouteInfo['routeLoaderData']>\n invalidate: () => void\n hasLoaders: () => boolean\n}\n\nconst componentTypes = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n] as const\n\nexport function createRouteMatch<\n TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,\n TRouteInfo extends AnyRouteInfo = RouteInfo,\n>(\n router: Router<any, any>,\n route: Route<TAllRouteInfo, TRouteInfo>,\n opts: {\n matchId: string\n params: TRouteInfo['allParams']\n pathname: string\n },\n): RouteMatch<TAllRouteInfo, TRouteInfo> {\n const routeMatch: RouteMatch<TAllRouteInfo, TRouteInfo> = {\n ...route,\n ...opts,\n router,\n routeSearch: {},\n search: {},\n childMatches: [],\n status: 'idle',\n routeLoaderData: {} as TRouteInfo['routeLoaderData'],\n loaderData: {} as TRouteInfo['loaderData'],\n isFetching: false,\n isInvalid: false,\n invalidAt: Infinity,\n // pendingActions: [],\n getIsInvalid: () => {\n const now = Date.now()\n return routeMatch.isInvalid || routeMatch.invalidAt < now\n },\n __: {\n abortController: new AbortController(),\n latestId: '',\n resolve: () => {},\n notify: () => {\n routeMatch.__.resolve()\n routeMatch.router.notify()\n },\n validate: () => {\n // Validate the search params and stabilize them\n const parentSearch =\n routeMatch.parentMatch?.search ?? router.location.search\n\n try {\n const prevSearch = routeMatch.routeSearch\n\n const validator =\n typeof routeMatch.options.validateSearch === 'object'\n ? routeMatch.options.validateSearch.parse\n : routeMatch.options.validateSearch\n\n let nextSearch = replaceEqualDeep(\n prevSearch,\n validator?.(parentSearch) ?? {},\n )\n\n // Invalidate route matches when search param stability changes\n if (prevSearch !== nextSearch) {\n routeMatch.isInvalid = true\n }\n\n routeMatch.routeSearch = nextSearch\n\n routeMatch.search = replaceEqualDeep(parentSearch, {\n ...parentSearch,\n ...nextSearch,\n })\n\n componentTypes.map(async (type) => {\n const component = routeMatch.options[type]\n\n if (typeof routeMatch.__[type] !== 'function') {\n routeMatch.__[type] = component\n }\n })\n } catch (err: any) {\n console.error(err)\n const error = new (Error as any)('Invalid search params found', {\n cause: err,\n })\n error.code = 'INVALID_SEARCH_PARAMS'\n routeMatch.status = 'error'\n routeMatch.error = error\n // Do not proceed with loading the route\n return\n }\n },\n },\n cancel: () => {\n routeMatch.__.abortController?.abort()\n },\n invalidate: () => {\n routeMatch.isInvalid = true\n },\n hasLoaders: () => {\n return !!(\n route.options.loader ||\n componentTypes.some((d) => route.options[d]?.preload)\n )\n },\n load: async (loaderOpts) => {\n const now = Date.now()\n const minMaxAge = loaderOpts?.preload\n ? Math.max(loaderOpts?.maxAge, loaderOpts?.gcMaxAge)\n : 0\n\n // If this is a preload, add it to the preload cache\n if (loaderOpts?.preload && minMaxAge > 0) {\n // If the match is currently active, don't preload it\n if (\n router.state.matches.find((d) => d.matchId === routeMatch.matchId)\n ) {\n return\n }\n\n router.matchCache[routeMatch.matchId] = {\n gc: now + loaderOpts.gcMaxAge,\n match: routeMatch as RouteMatch<any, any>,\n }\n }\n\n // If the match is invalid, errored or idle, trigger it to load\n if (\n (routeMatch.status === 'success' && routeMatch.getIsInvalid()) ||\n routeMatch.status === 'error' ||\n routeMatch.status === 'idle'\n ) {\n const maxAge = loaderOpts?.preload ? loaderOpts?.maxAge : undefined\n\n await routeMatch.fetch({ maxAge })\n }\n },\n fetch: async (opts) => {\n const id = '' + Date.now() + Math.random()\n routeMatch.__.latestId = id\n\n // If the match was in an error state, set it\n // to a loading state again. Otherwise, keep it\n // as loading or resolved\n if (routeMatch.status === 'idle') {\n routeMatch.status = 'loading'\n }\n\n // We started loading the route, so it's no longer invalid\n routeMatch.isInvalid = false\n\n routeMatch.__.loadPromise = new Promise(async (resolve) => {\n // We are now fetching, even if it's in the background of a\n // resolved state\n routeMatch.isFetching = true\n routeMatch.__.resolve = resolve as () => void\n\n routeMatch.__.componentsPromise = (async () => {\n // then run all component and data loaders in parallel\n // For each component type, potentially load it asynchronously\n\n await Promise.all(\n componentTypes.map(async (type) => {\n const component = routeMatch.options[type]\n\n if (routeMatch.__[type]?.preload) {\n routeMatch.__[type] = await router.options.loadComponent!(\n component,\n )\n }\n }),\n )\n })()\n\n routeMatch.__.dataPromise = Promise.resolve().then(async () => {\n try {\n if (routeMatch.options.loader) {\n const data = await routeMatch.options.loader({\n params: routeMatch.params,\n search: routeMatch.routeSearch,\n signal: routeMatch.__.abortController.signal,\n })\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n routeMatch.routeLoaderData = replaceEqualDeep(\n routeMatch.routeLoaderData,\n data,\n )\n }\n\n routeMatch.error = undefined\n routeMatch.status = 'success'\n routeMatch.updatedAt = Date.now()\n routeMatch.invalidAt =\n routeMatch.updatedAt +\n (opts?.maxAge ??\n routeMatch.options.loaderMaxAge ??\n router.options.defaultLoaderMaxAge ??\n 0)\n } catch (err) {\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n if (process.env.NODE_ENV !== 'production') {\n console.error(err)\n }\n routeMatch.error = err\n routeMatch.status = 'error'\n routeMatch.updatedAt = Date.now()\n }\n })\n\n try {\n await Promise.all([\n routeMatch.__.componentsPromise,\n routeMatch.__.dataPromise,\n ])\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n } finally {\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n routeMatch.isFetching = false\n routeMatch.__.notify()\n }\n })\n\n await routeMatch.__.loadPromise\n\n if (id !== routeMatch.__.latestId) {\n return routeMatch.__.loadPromise\n }\n\n delete routeMatch.__.loadPromise\n },\n }\n\n if (!routeMatch.hasLoaders()) {\n routeMatch.status = 'success'\n }\n\n return routeMatch\n}\n"],"names":["componentTypes","createRouteMatch","router","route","opts","routeMatch","_extends","routeSearch","search","childMatches","status","routeLoaderData","loaderData","isFetching","isInvalid","invalidAt","Infinity","getIsInvalid","now","Date","__","abortController","AbortController","latestId","resolve","notify","validate","parentSearch","parentMatch","location","prevSearch","validator","options","validateSearch","parse","nextSearch","replaceEqualDeep","map","type","component","err","console","error","Error","cause","code","cancel","abort","invalidate","hasLoaders","loader","some","d","preload","load","loaderOpts","minMaxAge","Math","max","maxAge","gcMaxAge","state","matches","find","matchId","matchCache","gc","match","undefined","fetch","id","random","loadPromise","Promise","componentsPromise","all","loadComponent","dataPromise","then","data","params","signal","updatedAt","loaderMaxAge","defaultLoaderMaxAge","process","env","NODE_ENV"],"mappings":";;;;;;;;;;;;;;;;;AA+DA,MAAMA,cAAc,GAAG,CACrB,WADqB,EAErB,gBAFqB,EAGrB,kBAHqB,CAAvB,CAAA;AAMO,SAASC,gBAAT,CAILC,M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I,CAACnE,UAAU,CAAC4C,UAAX,EAAL,EAA8B;IAC5B5C,UAAU,CAACK,MAAX,GAAoB,SAApB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOL,UAAP,CAAA;AACD;;;;"}
@@ -197,18 +197,26 @@ function createRouter(userOptions) {
197
197
  const matches = router.matchRoutes(router.location.pathname, {
198
198
  strictParseParams: true
199
199
  });
200
- router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
201
- pending: {
200
+
201
+ if (typeof document !== 'undefined') {
202
+ router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
203
+ pending: {
204
+ matches: matches,
205
+ location: router.location
206
+ },
207
+ status: 'loading'
208
+ });
209
+ } else {
210
+ router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
202
211
  matches: matches,
203
- location: router.location
204
- },
205
- status: 'loading'
206
- });
212
+ location: router.location,
213
+ status: 'loading'
214
+ });
215
+ }
216
+
207
217
  router.notify(); // Load the matches
208
218
 
209
- await router.loadMatches(matches, {
210
- withPending: true
211
- });
219
+ await router.loadMatches(matches);
212
220
 
213
221
  if (router.startedLoadingAt !== id) {
214
222
  // Ignore side-effects of match loading
@@ -430,14 +438,8 @@ function createRouter(userOptions) {
430
438
 
431
439
  match.load(loaderOpts);
432
440
 
433
- if (match.status === 'loading') {
434
- // If requested, start the pending timers
435
- if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
436
- }
437
-
438
441
  if (match.__.loadPromise) {
439
442
  // Wait for the first sign of activity from the match
440
- // This might be completion, error, or a pending state
441
443
  await match.__.loadPromise;
442
444
  }
443
445
  });