@tanstack/router-core 1.131.4 → 1.131.7

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.
@@ -74,23 +74,25 @@ async function hydrate(router) {
74
74
  await ((_c = (_b = router.options).hydrate) == null ? void 0 : _c.call(_b, dehydratedData));
75
75
  await Promise.all(
76
76
  router.state.matches.map(async (match) => {
77
- var _a2, _b2, _c2, _d, _e, _f;
77
+ var _a2, _b2, _c2, _d;
78
78
  const route = router.looseRoutesById[match.routeId];
79
79
  const parentMatch = router.state.matches[match.index - 1];
80
- const parentContext = (parentMatch == null ? void 0 : parentMatch.context) ?? router.options.context ?? {};
81
- const contextFnContext = {
82
- deps: match.loaderDeps,
83
- params: match.params,
84
- context: parentContext,
85
- location: router.state.location,
86
- navigate: (opts) => router.navigate({ ...opts, _fromLocation: router.state.location }),
87
- buildLocation: router.buildLocation,
88
- cause: match.cause,
89
- abortController: match.abortController,
90
- preload: false,
91
- matches
92
- };
93
- match.__routeContext = ((_b2 = (_a2 = route.options).context) == null ? void 0 : _b2.call(_a2, contextFnContext)) ?? {};
80
+ const parentContext = (parentMatch == null ? void 0 : parentMatch.context) ?? router.options.context;
81
+ if (route.options.context) {
82
+ const contextFnContext = {
83
+ deps: match.loaderDeps,
84
+ params: match.params,
85
+ context: parentContext ?? {},
86
+ location: router.state.location,
87
+ navigate: (opts) => router.navigate({ ...opts, _fromLocation: router.state.location }),
88
+ buildLocation: router.buildLocation,
89
+ cause: match.cause,
90
+ abortController: match.abortController,
91
+ preload: false,
92
+ matches
93
+ };
94
+ match.__routeContext = route.options.context(contextFnContext) ?? void 0;
95
+ }
94
96
  match.context = {
95
97
  ...parentContext,
96
98
  ...match.__routeContext,
@@ -102,8 +104,8 @@ async function hydrate(router) {
102
104
  params: match.params,
103
105
  loaderData: match.loaderData
104
106
  };
105
- const headFnContent = await ((_d = (_c2 = route.options).head) == null ? void 0 : _d.call(_c2, assetContext));
106
- const scripts = await ((_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e, assetContext));
107
+ const headFnContent = await ((_b2 = (_a2 = route.options).head) == null ? void 0 : _b2.call(_a2, assetContext));
108
+ const scripts = await ((_d = (_c2 = route.options).scripts) == null ? void 0 : _d.call(_c2, assetContext));
107
109
  match.meta = headFnContent == null ? void 0 : headFnContent.meta;
108
110
  match.links = headFnContent == null ? void 0 : headFnContent.links;
109
111
  match.headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-client.js","sources":["../../../src/ssr/ssr-client.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { batch } from '@tanstack/store'\nimport { createControlledPromise } from '../utils'\nimport type { AnyRouteMatch, MakeRouteMatch } from '../Matches'\nimport type { AnyRouter } from '../router'\nimport type { Manifest } from '../manifest'\nimport type { RouteContextOptions } from '../route'\nimport type { GLOBAL_TSR } from './ssr-server'\n\ndeclare global {\n interface Window {\n [GLOBAL_TSR]?: TsrSsrGlobal\n }\n}\n\nexport interface TsrSsrGlobal {\n router?: DehydratedRouter\n // clean scripts, shortened since this is sent for each streamed script\n c: () => void\n}\n\nfunction hydrateMatch(\n match: AnyRouteMatch,\n deyhydratedMatch: DehydratedMatch,\n): void {\n match.id = deyhydratedMatch.i\n match.__beforeLoadContext = deyhydratedMatch.b\n match.loaderData = deyhydratedMatch.l\n match.status = deyhydratedMatch.s\n match.ssr = deyhydratedMatch.ssr\n match.updatedAt = deyhydratedMatch.u\n match.error = deyhydratedMatch.e\n}\nexport interface DehydratedMatch {\n i: MakeRouteMatch['id']\n b?: MakeRouteMatch['__beforeLoadContext']\n l?: MakeRouteMatch['loaderData']\n e?: MakeRouteMatch['error']\n u: MakeRouteMatch['updatedAt']\n s: MakeRouteMatch['status']\n ssr?: MakeRouteMatch['ssr']\n}\n\nexport interface DehydratedRouter {\n manifest: Manifest | undefined\n dehydratedData?: any\n lastMatchId?: string\n matches: Array<DehydratedMatch>\n}\n\nexport async function hydrate(router: AnyRouter): Promise<any> {\n invariant(\n window.$_TSR?.router,\n 'Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!',\n )\n\n const { manifest, dehydratedData, lastMatchId } = window.$_TSR.router\n\n router.ssr = {\n manifest,\n }\n\n // Hydrate the router state\n const matches = router.matchRoutes(router.state.location)\n\n // kick off loading the route chunks\n const routeChunkPromise = Promise.all(\n matches.map((match) => {\n const route = router.looseRoutesById[match.routeId]!\n return router.loadRouteChunk(route)\n }),\n )\n\n function setMatchForcePending(match: AnyRouteMatch) {\n // usually the minPendingPromise is created in the Match component if a pending match is rendered\n // however, this might be too late if the match synchronously resolves\n const route = router.looseRoutesById[match.routeId]!\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const minPendingPromise = createControlledPromise<void>()\n match._nonReactive.minPendingPromise = minPendingPromise\n match._forcePending = true\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n router.updateMatch(match.id, (prev) => {\n prev._nonReactive.minPendingPromise = undefined\n return {\n ...prev,\n _forcePending: undefined,\n }\n })\n }, pendingMinMs)\n }\n }\n\n // Right after hydration and before the first render, we need to rehydrate each match\n // First step is to reyhdrate loaderData and __beforeLoadContext\n let firstNonSsrMatchIndex: number | undefined = undefined\n matches.forEach((match) => {\n const dehydratedMatch = window.$_TSR!.router!.matches.find(\n (d) => d.i === match.id,\n )\n if (!dehydratedMatch) {\n match._nonReactive.dehydrated = false\n match.ssr = false\n return\n }\n\n hydrateMatch(match, dehydratedMatch)\n\n match._nonReactive.dehydrated = match.ssr !== false\n\n if (match.ssr === 'data-only' || match.ssr === false) {\n if (firstNonSsrMatchIndex === undefined) {\n firstNonSsrMatchIndex = match.index\n setMatchForcePending(match)\n }\n }\n })\n\n router.__store.setState((s) => {\n return {\n ...s,\n matches,\n }\n })\n\n // Allow the user to handle custom hydration data\n await router.options.hydrate?.(dehydratedData)\n\n // now that all necessary data is hydrated:\n // 1) fully reconstruct the route context\n // 2) execute `head()` and `scripts()` for each match\n await Promise.all(\n router.state.matches.map(async (match) => {\n const route = router.looseRoutesById[match.routeId]!\n\n const parentMatch = router.state.matches[match.index - 1]\n const parentContext = parentMatch?.context ?? router.options.context ?? {}\n\n // `context()` was already executed by `matchRoutes`, however route context was not yet fully reconstructed\n // so run it again and merge route context\n const contextFnContext: RouteContextOptions<any, any, any, any> = {\n deps: match.loaderDeps,\n params: match.params,\n context: parentContext,\n location: router.state.location,\n navigate: (opts: any) =>\n router.navigate({ ...opts, _fromLocation: router.state.location }),\n buildLocation: router.buildLocation,\n cause: match.cause,\n abortController: match.abortController,\n preload: false,\n matches,\n }\n match.__routeContext = route.options.context?.(contextFnContext) ?? {}\n\n match.context = {\n ...parentContext,\n ...match.__routeContext,\n ...match.__beforeLoadContext,\n }\n\n const assetContext = {\n matches: router.state.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n const headFnContent = await route.options.head?.(assetContext)\n\n const scripts = await route.options.scripts?.(assetContext)\n\n match.meta = headFnContent?.meta\n match.links = headFnContent?.links\n match.headScripts = headFnContent?.scripts\n match.styles = headFnContent?.styles\n match.scripts = scripts\n }),\n )\n\n const isSpaMode = matches[matches.length - 1]!.id !== lastMatchId\n const hasSsrFalseMatches = matches.some((m) => m.ssr === false)\n // all matches have data from the server and we are not in SPA mode so we don't need to kick of router.load()\n if (!hasSsrFalseMatches && !isSpaMode) {\n matches.forEach((match) => {\n // remove the dehydrated flag since we won't run router.load() which would remove it\n match._nonReactive.dehydrated = undefined\n })\n return routeChunkPromise\n }\n\n // schedule router.load() to run after the next tick so we can store the promise in the match before loading starts\n const loadPromise = Promise.resolve()\n .then(() => router.load())\n .catch((err) => {\n console.error('Error during router hydration:', err)\n })\n\n // in SPA mode we need to keep the first match below the root route pending until router.load() is finished\n // this will prevent that other pending components are rendered but hydration is not blocked\n if (isSpaMode) {\n const match = matches[1]\n invariant(\n match,\n 'Expected to find a match below the root match in SPA mode.',\n )\n setMatchForcePending(match)\n\n match._displayPending = true\n match._nonReactive.displayPendingPromise = loadPromise\n\n loadPromise.then(() => {\n batch(() => {\n // ensure router is not in status 'pending' anymore\n // this usually happens in Transitioner but if loading synchronously resolves,\n // Transitioner won't be rendered while loading so it cannot track the change from loading:true to loading:false\n if (router.__store.state.status === 'pending') {\n router.__store.setState((s) => ({\n ...s,\n status: 'idle',\n resolvedLocation: s.location,\n }))\n }\n // hide the pending component once the load is finished\n router.updateMatch(match.id, (prev) => {\n return {\n ...prev,\n _displayPending: undefined,\n displayPendingPromise: undefined,\n }\n })\n })\n })\n }\n return routeChunkPromise\n}\n"],"names":["_b","_a","_c"],"mappings":";;;AAqBA,SAAS,aACP,OACA,kBACM;AACN,QAAM,KAAK,iBAAiB;AAC5B,QAAM,sBAAsB,iBAAiB;AAC7C,QAAM,aAAa,iBAAiB;AACpC,QAAM,SAAS,iBAAiB;AAChC,QAAM,MAAM,iBAAiB;AAC7B,QAAM,YAAY,iBAAiB;AACnC,QAAM,QAAQ,iBAAiB;AACjC;AAkBA,eAAsB,QAAQ,QAAiC;;AAC7D;AAAA,KACE,YAAO,UAAP,mBAAc;AAAA,IACd;AAAA,EACF;AAEA,QAAM,EAAE,UAAU,gBAAgB,YAAY,IAAI,OAAO,MAAM;AAE/D,SAAO,MAAM;AAAA,IACX;AAAA,EACF;AAGA,QAAM,UAAU,OAAO,YAAY,OAAO,MAAM,QAAQ;AAGxD,QAAM,oBAAoB,QAAQ;AAAA,IAChC,QAAQ,IAAI,CAAC,UAAU;AACrB,YAAM,QAAQ,OAAO,gBAAgB,MAAM,OAAO;AAC3C,aAAA,OAAO,eAAe,KAAK;AAAA,IACnC,CAAA;AAAA,EACH;AAEA,WAAS,qBAAqB,OAAsB;AAGlD,UAAM,QAAQ,OAAO,gBAAgB,MAAM,OAAO;AAClD,UAAM,eACJ,MAAM,QAAQ,gBAAgB,OAAO,QAAQ;AAC/C,QAAI,cAAc;AAChB,YAAM,oBAAoB,wBA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Q,QAAQ,CAAC;AACvB;AAAA,MACE;AAAA,MACA;AAAA,IACF;AACA,yBAAqB,KAAK;AAE1B,UAAM,kBAAkB;AACxB,UAAM,aAAa,wBAAwB;AAE3C,gBAAY,KAAK,MAAM;AACrB,YAAM,MAAM;AAIV,YAAI,OAAO,QAAQ,MAAM,WAAW,WAAW;AACtC,iBAAA,QAAQ,SAAS,CAAC,OAAO;AAAA,YAC9B,GAAG;AAAA,YACH,QAAQ;AAAA,YACR,kBAAkB,EAAE;AAAA,UAAA,EACpB;AAAA,QAAA;AAGJ,eAAO,YAAY,MAAM,IAAI,CAAC,SAAS;AAC9B,iBAAA;AAAA,YACL,GAAG;AAAA,YACH,iBAAiB;AAAA,YACjB,uBAAuB;AAAA,UACzB;AAAA,QAAA,CACD;AAAA,MAAA,CACF;AAAA,IAAA,CACF;AAAA,EAAA;AAEI,SAAA;AACT;"}
1
+ {"version":3,"file":"ssr-client.js","sources":["../../../src/ssr/ssr-client.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { batch } from '@tanstack/store'\nimport { createControlledPromise } from '../utils'\nimport type { AnyRouteMatch, MakeRouteMatch } from '../Matches'\nimport type { AnyRouter } from '../router'\nimport type { Manifest } from '../manifest'\nimport type { RouteContextOptions } from '../route'\nimport type { GLOBAL_TSR } from './ssr-server'\n\ndeclare global {\n interface Window {\n [GLOBAL_TSR]?: TsrSsrGlobal\n }\n}\n\nexport interface TsrSsrGlobal {\n router?: DehydratedRouter\n // clean scripts, shortened since this is sent for each streamed script\n c: () => void\n}\n\nfunction hydrateMatch(\n match: AnyRouteMatch,\n deyhydratedMatch: DehydratedMatch,\n): void {\n match.id = deyhydratedMatch.i\n match.__beforeLoadContext = deyhydratedMatch.b\n match.loaderData = deyhydratedMatch.l\n match.status = deyhydratedMatch.s\n match.ssr = deyhydratedMatch.ssr\n match.updatedAt = deyhydratedMatch.u\n match.error = deyhydratedMatch.e\n}\nexport interface DehydratedMatch {\n i: MakeRouteMatch['id']\n b?: MakeRouteMatch['__beforeLoadContext']\n l?: MakeRouteMatch['loaderData']\n e?: MakeRouteMatch['error']\n u: MakeRouteMatch['updatedAt']\n s: MakeRouteMatch['status']\n ssr?: MakeRouteMatch['ssr']\n}\n\nexport interface DehydratedRouter {\n manifest: Manifest | undefined\n dehydratedData?: any\n lastMatchId?: string\n matches: Array<DehydratedMatch>\n}\n\nexport async function hydrate(router: AnyRouter): Promise<any> {\n invariant(\n window.$_TSR?.router,\n 'Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!',\n )\n\n const { manifest, dehydratedData, lastMatchId } = window.$_TSR.router\n\n router.ssr = {\n manifest,\n }\n\n // Hydrate the router state\n const matches = router.matchRoutes(router.state.location)\n\n // kick off loading the route chunks\n const routeChunkPromise = Promise.all(\n matches.map((match) => {\n const route = router.looseRoutesById[match.routeId]!\n return router.loadRouteChunk(route)\n }),\n )\n\n function setMatchForcePending(match: AnyRouteMatch) {\n // usually the minPendingPromise is created in the Match component if a pending match is rendered\n // however, this might be too late if the match synchronously resolves\n const route = router.looseRoutesById[match.routeId]!\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const minPendingPromise = createControlledPromise<void>()\n match._nonReactive.minPendingPromise = minPendingPromise\n match._forcePending = true\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n router.updateMatch(match.id, (prev) => {\n prev._nonReactive.minPendingPromise = undefined\n return {\n ...prev,\n _forcePending: undefined,\n }\n })\n }, pendingMinMs)\n }\n }\n\n // Right after hydration and before the first render, we need to rehydrate each match\n // First step is to reyhdrate loaderData and __beforeLoadContext\n let firstNonSsrMatchIndex: number | undefined = undefined\n matches.forEach((match) => {\n const dehydratedMatch = window.$_TSR!.router!.matches.find(\n (d) => d.i === match.id,\n )\n if (!dehydratedMatch) {\n match._nonReactive.dehydrated = false\n match.ssr = false\n return\n }\n\n hydrateMatch(match, dehydratedMatch)\n\n match._nonReactive.dehydrated = match.ssr !== false\n\n if (match.ssr === 'data-only' || match.ssr === false) {\n if (firstNonSsrMatchIndex === undefined) {\n firstNonSsrMatchIndex = match.index\n setMatchForcePending(match)\n }\n }\n })\n\n router.__store.setState((s) => {\n return {\n ...s,\n matches,\n }\n })\n\n // Allow the user to handle custom hydration data\n await router.options.hydrate?.(dehydratedData)\n\n // now that all necessary data is hydrated:\n // 1) fully reconstruct the route context\n // 2) execute `head()` and `scripts()` for each match\n await Promise.all(\n router.state.matches.map(async (match) => {\n const route = router.looseRoutesById[match.routeId]!\n\n const parentMatch = router.state.matches[match.index - 1]\n const parentContext = parentMatch?.context ?? router.options.context\n\n // `context()` was already executed by `matchRoutes`, however route context was not yet fully reconstructed\n // so run it again and merge route context\n if (route.options.context) {\n const contextFnContext: RouteContextOptions<any, any, any, any> = {\n deps: match.loaderDeps,\n params: match.params,\n context: parentContext ?? {},\n location: router.state.location,\n navigate: (opts: any) =>\n router.navigate({ ...opts, _fromLocation: router.state.location }),\n buildLocation: router.buildLocation,\n cause: match.cause,\n abortController: match.abortController,\n preload: false,\n matches,\n }\n match.__routeContext =\n route.options.context(contextFnContext) ?? undefined\n }\n\n match.context = {\n ...parentContext,\n ...match.__routeContext,\n ...match.__beforeLoadContext,\n }\n\n const assetContext = {\n matches: router.state.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n const headFnContent = await route.options.head?.(assetContext)\n\n const scripts = await route.options.scripts?.(assetContext)\n\n match.meta = headFnContent?.meta\n match.links = headFnContent?.links\n match.headScripts = headFnContent?.scripts\n match.styles = headFnContent?.styles\n match.scripts = scripts\n }),\n )\n\n const isSpaMode = matches[matches.length - 1]!.id !== lastMatchId\n const hasSsrFalseMatches = matches.some((m) => m.ssr === false)\n // all matches have data from the server and we are not in SPA mode so we don't need to kick of router.load()\n if (!hasSsrFalseMatches && !isSpaMode) {\n matches.forEach((match) => {\n // remove the dehydrated flag since we won't run router.load() which would remove it\n match._nonReactive.dehydrated = undefined\n })\n return routeChunkPromise\n }\n\n // schedule router.load() to run after the next tick so we can store the promise in the match before loading starts\n const loadPromise = Promise.resolve()\n .then(() => router.load())\n .catch((err) => {\n console.error('Error during router hydration:', err)\n })\n\n // in SPA mode we need to keep the first match below the root route pending until router.load() is finished\n // this will prevent that other pending components are rendered but hydration is not blocked\n if (isSpaMode) {\n const match = matches[1]\n invariant(\n match,\n 'Expected to find a match below the root match in SPA mode.',\n )\n setMatchForcePending(match)\n\n match._displayPending = true\n match._nonReactive.displayPendingPromise = loadPromise\n\n loadPromise.then(() => {\n batch(() => {\n // ensure router is not in status 'pending' anymore\n // this usually happens in Transitioner but if loading synchronously resolves,\n // Transitioner won't be rendered while loading so it cannot track the change from loading:true to loading:false\n if (router.__store.state.status === 'pending') {\n router.__store.setState((s) => ({\n ...s,\n status: 'idle',\n resolvedLocation: s.location,\n }))\n }\n // hide the pending component once the load is finished\n router.updateMatch(match.id, (prev) => {\n return {\n ...prev,\n _displayPending: undefined,\n displayPendingPromise: undefined,\n }\n })\n })\n })\n }\n return routeChunkPromise\n}\n"],"names":["_b","_a","_c"],"mappings":";;;AAqBA,SAAS,aACP,OACA,kBACM;AACN,QAAM,KAAK,iBAAiB;AAC5B,QAAM,sBAAsB,iBAAiB;AAC7C,QAAM,aAAa,iBAAiB;AACpC,QAAM,SAAS,iBAAiB;AAChC,QAAM,MAAM,iBAAiB;AAC7B,QAAM,YAAY,iBAAiB;AACnC,QAAM,QAAQ,iBAAiB;AACjC;AAkBA,eAAsB,QAAQ,QAAiC;;AAC7D;AAAA,KACE,YAAO,UAAP,mBAAc;AAAA,IACd;AAAA,EACF;AAEA,QAAM,EAAE,UAAU,gBAAgB,YAAY,IAAI,OAAO,MAAM;AAE/D,SAAO,MAAM;AAAA,IACX;AAAA,EACF;AAGA,QAAM,UAAU,OAAO,YAAY,OAAO,MAAM,QAAQ;AAGxD,QAAM,oBAAoB,QAAQ;AAAA,IAChC,QAAQ,IAAI,CAAC,UAAU;AACrB,YAAM,QAAQ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AAC,sBAAsB,CAAC,WAAW;AAC7B,YAAA,QAAQ,CAAC,UAAU;AAEzB,YAAM,aAAa,aAAa;AAAA,IAAA,CACjC;AACM,WAAA;AAAA,EAAA;AAIT,QAAM,cAAc,QAAQ,QAAQ,EACjC,KAAK,MAAM,OAAO,KAAM,CAAA,EACxB,MAAM,CAAC,QAAQ;AACN,YAAA,MAAM,kCAAkC,GAAG;AAAA,EAAA,CACpD;AAIH,MAAI,WAAW;AACP,UAAA,QAAQ,QAAQ,CAAC;AACvB;AAAA,MACE;AAAA,MACA;AAAA,IACF;AACA,yBAAqB,KAAK;AAE1B,UAAM,kBAAkB;AACxB,UAAM,aAAa,wBAAwB;AAE3C,gBAAY,KAAK,MAAM;AACrB,YAAM,MAAM;AAIV,YAAI,OAAO,QAAQ,MAAM,WAAW,WAAW;AACtC,iBAAA,QAAQ,SAAS,CAAC,OAAO;AAAA,YAC9B,GAAG;AAAA,YACH,QAAQ;AAAA,YACR,kBAAkB,EAAE;AAAA,UAAA,EACpB;AAAA,QAAA;AAGJ,eAAO,YAAY,MAAM,IAAI,CAAC,SAAS;AAC9B,iBAAA;AAAA,YACL,GAAG;AAAA,YACH,iBAAiB;AAAA,YACjB,uBAAuB;AAAA,UACzB;AAAA,QAAA,CACD;AAAA,MAAA,CACF;AAAA,IAAA,CACF;AAAA,EAAA;AAEI,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.131.4",
3
+ "version": "1.131.7",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/Matches.ts CHANGED
@@ -150,7 +150,7 @@ export interface RouteMatch<
150
150
  }
151
151
  loaderData?: TLoaderData
152
152
  /** @internal */
153
- __routeContext: Record<string, unknown>
153
+ __routeContext?: Record<string, unknown>
154
154
  /** @internal */
155
155
  __beforeLoadContext?: Record<string, unknown>
156
156
  context: TAllContext
package/src/router.ts CHANGED
@@ -1146,8 +1146,8 @@ export class RouterCore<
1146
1146
  const parentMatchId = parentMatch?.id
1147
1147
 
1148
1148
  const parentContext = !parentMatchId
1149
- ? ((this.options.context as any) ?? {})
1150
- : (parentMatch.context ?? this.options.context ?? {})
1149
+ ? ((this.options.context as any) ?? undefined)
1150
+ : (parentMatch.context ?? this.options.context ?? undefined)
1151
1151
 
1152
1152
  return parentContext
1153
1153
  }
@@ -1169,12 +1169,12 @@ export class RouterCore<
1169
1169
  ] = (() => {
1170
1170
  // Validate the search params and stabilize them
1171
1171
  const parentSearch = parentMatch?.search ?? next.search
1172
- const parentStrictSearch = parentMatch?._strictSearch ?? {}
1172
+ const parentStrictSearch = parentMatch?._strictSearch ?? undefined
1173
1173
 
1174
1174
  try {
1175
1175
  const strictSearch =
1176
1176
  validateSearch(route.options.validateSearch, { ...parentSearch }) ??
1177
- {}
1177
+ undefined
1178
1178
 
1179
1179
  return [
1180
1180
  {
@@ -1284,7 +1284,7 @@ export class RouterCore<
1284
1284
  isFetching: false,
1285
1285
  error: undefined,
1286
1286
  paramsError: parseErrors[index],
1287
- __routeContext: {},
1287
+ __routeContext: undefined,
1288
1288
  _nonReactive: {
1289
1289
  loadPromise: createControlledPromise(),
1290
1290
  },
@@ -1337,22 +1337,25 @@ export class RouterCore<
1337
1337
  const parentContext = getParentContext(parentMatch)
1338
1338
 
1339
1339
  // Update the match's context
1340
- const contextFnContext: RouteContextOptions<any, any, any, any> = {
1341
- deps: match.loaderDeps,
1342
- params: match.params,
1343
- context: parentContext,
1344
- location: next,
1345
- navigate: (opts: any) =>
1346
- this.navigate({ ...opts, _fromLocation: next }),
1347
- buildLocation: this.buildLocation,
1348
- cause: match.cause,
1349
- abortController: match.abortController,
1350
- preload: !!match.preload,
1351
- matches,
1352
- }
1353
1340
 
1354
- // Get the route context
1355
- match.__routeContext = route.options.context?.(contextFnContext) ?? {}
1341
+ if (route.options.context) {
1342
+ const contextFnContext: RouteContextOptions<any, any, any, any> = {
1343
+ deps: match.loaderDeps,
1344
+ params: match.params,
1345
+ context: parentContext ?? {},
1346
+ location: next,
1347
+ navigate: (opts: any) =>
1348
+ this.navigate({ ...opts, _fromLocation: next }),
1349
+ buildLocation: this.buildLocation,
1350
+ cause: match.cause,
1351
+ abortController: match.abortController,
1352
+ preload: !!match.preload,
1353
+ matches,
1354
+ }
1355
+ // Get the route context
1356
+ match.__routeContext =
1357
+ route.options.context(contextFnContext) ?? undefined
1358
+ }
1356
1359
 
1357
1360
  match.context = {
1358
1361
  ...parentContext,
@@ -1417,7 +1420,7 @@ export class RouterCore<
1417
1420
 
1418
1421
  // First let's find the starting pathname
1419
1422
  // By default, start with the current location
1420
- let fromPath = lastMatch.fullPath
1423
+ let fromPath = this.resolvePathWithBase(lastMatch.fullPath, '.')
1421
1424
  const toPath = dest.to
1422
1425
  ? this.resolvePathWithBase(fromPath, `${dest.to}`)
1423
1426
  : this.resolvePathWithBase(fromPath, '.')
@@ -1458,6 +1461,8 @@ export class RouterCore<
1458
1461
  }
1459
1462
  }
1460
1463
 
1464
+ fromPath = this.resolvePathWithBase(fromPath, '.')
1465
+
1461
1466
  // From search should always use the current location
1462
1467
  const fromSearch = lastMatch.search
1463
1468
  // Same with params. It can't hurt to provide as many as possible
@@ -1486,13 +1491,9 @@ export class RouterCore<
1486
1491
  parseCache: this.parsePathnameCache,
1487
1492
  }).interpolatedPath
1488
1493
 
1489
- const destRoutes = this.matchRoutes(
1490
- interpolatedNextTo,
1491
- {},
1492
- {
1493
- _buildLocation: true,
1494
- },
1495
- ).map((d) => this.looseRoutesById[d.routeId]!)
1494
+ const destRoutes = this.matchRoutes(interpolatedNextTo, undefined, {
1495
+ _buildLocation: true,
1496
+ }).map((d) => this.looseRoutesById[d.routeId]!)
1496
1497
 
1497
1498
  // If there are any params, we need to stringify them
1498
1499
  if (Object.keys(nextParams).length > 0) {
@@ -2378,7 +2379,7 @@ export class RouterCore<
2378
2379
  const abortController = new AbortController()
2379
2380
 
2380
2381
  const parentMatchContext =
2381
- parentMatch?.context ?? this.options.context ?? {}
2382
+ parentMatch?.context ?? this.options.context ?? undefined
2382
2383
 
2383
2384
  updateMatch(matchId, (prev) => ({
2384
2385
  ...prev,
@@ -2787,7 +2788,7 @@ export class RouterCore<
2787
2788
  invalid: true,
2788
2789
  ...(opts?.forcePending || d.status === 'error'
2789
2790
  ? ({ status: 'pending', error: undefined } as const)
2790
- : {}),
2791
+ : undefined),
2791
2792
  }
2792
2793
  }
2793
2794
  return d
@@ -3558,7 +3559,8 @@ function applySearchMiddleware({
3558
3559
  try {
3559
3560
  const validatedSearch = {
3560
3561
  ...result,
3561
- ...(validateSearch(route.options.validateSearch, result) ?? {}),
3562
+ ...(validateSearch(route.options.validateSearch, result) ??
3563
+ undefined),
3562
3564
  }
3563
3565
  return validatedSearch
3564
3566
  } catch {
@@ -139,24 +139,27 @@ export async function hydrate(router: AnyRouter): Promise<any> {
139
139
  const route = router.looseRoutesById[match.routeId]!
140
140
 
141
141
  const parentMatch = router.state.matches[match.index - 1]
142
- const parentContext = parentMatch?.context ?? router.options.context ?? {}
142
+ const parentContext = parentMatch?.context ?? router.options.context
143
143
 
144
144
  // `context()` was already executed by `matchRoutes`, however route context was not yet fully reconstructed
145
145
  // so run it again and merge route context
146
- const contextFnContext: RouteContextOptions<any, any, any, any> = {
147
- deps: match.loaderDeps,
148
- params: match.params,
149
- context: parentContext,
150
- location: router.state.location,
151
- navigate: (opts: any) =>
152
- router.navigate({ ...opts, _fromLocation: router.state.location }),
153
- buildLocation: router.buildLocation,
154
- cause: match.cause,
155
- abortController: match.abortController,
156
- preload: false,
157
- matches,
146
+ if (route.options.context) {
147
+ const contextFnContext: RouteContextOptions<any, any, any, any> = {
148
+ deps: match.loaderDeps,
149
+ params: match.params,
150
+ context: parentContext ?? {},
151
+ location: router.state.location,
152
+ navigate: (opts: any) =>
153
+ router.navigate({ ...opts, _fromLocation: router.state.location }),
154
+ buildLocation: router.buildLocation,
155
+ cause: match.cause,
156
+ abortController: match.abortController,
157
+ preload: false,
158
+ matches,
159
+ }
160
+ match.__routeContext =
161
+ route.options.context(contextFnContext) ?? undefined
158
162
  }
159
- match.__routeContext = route.options.context?.(contextFnContext) ?? {}
160
163
 
161
164
  match.context = {
162
165
  ...parentContext,