@tanstack/react-router 1.168.1 → 1.168.2
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.
- package/dist/cjs/Match.cjs +37 -14
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +2 -4
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +4 -6
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/renderRouteNotFound.cjs +3 -3
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
- package/dist/cjs/route.cjs +0 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +8 -4
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useRouter.cjs +3 -3
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/esm/Match.js +38 -13
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +2 -3
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.js +4 -4
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/renderRouteNotFound.js +3 -2
- package/dist/esm/renderRouteNotFound.js.map +1 -1
- package/dist/esm/route.js +0 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/useMatch.js +9 -4
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useRouter.js +3 -2
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/llms/rules/api.d.ts +1 -1
- package/dist/llms/rules/api.js +10 -10
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +27 -6
- package/package.json +2 -4
- package/src/Match.tsx +77 -24
- package/src/Matches.tsx +3 -5
- package/src/fileRoute.ts +7 -9
- package/src/renderRouteNotFound.tsx +6 -6
- package/src/route.tsx +0 -2
- package/src/useMatch.tsx +19 -10
- package/src/useRouter.tsx +7 -5
package/dist/cjs/useMatch.cjs
CHANGED
|
@@ -6,8 +6,6 @@ let react = require("react");
|
|
|
6
6
|
react = require_runtime.__toESM(react);
|
|
7
7
|
let _tanstack_react_store = require("@tanstack/react-store");
|
|
8
8
|
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
9
|
-
let tiny_invariant = require("tiny-invariant");
|
|
10
|
-
tiny_invariant = require_runtime.__toESM(tiny_invariant);
|
|
11
9
|
//#region src/useMatch.tsx
|
|
12
10
|
var dummyStore = {
|
|
13
11
|
state: void 0,
|
|
@@ -25,13 +23,19 @@ function useMatch(opts) {
|
|
|
25
23
|
const matchStore = key ? opts.from ? router.stores.getMatchStoreByRouteId(key) : router.stores.activeMatchStoresById.get(key) : void 0;
|
|
26
24
|
if (_tanstack_router_core_isServer.isServer ?? router.isServer) {
|
|
27
25
|
const match = matchStore?.state;
|
|
28
|
-
|
|
26
|
+
if ((opts.shouldThrow ?? true) && !match) {
|
|
27
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
|
|
28
|
+
(0, _tanstack_router_core.invariant)();
|
|
29
|
+
}
|
|
29
30
|
if (match === void 0) return;
|
|
30
31
|
return opts.select ? opts.select(match) : match;
|
|
31
32
|
}
|
|
32
33
|
const previousResult = react.useRef(void 0);
|
|
33
34
|
return (0, _tanstack_react_store.useStore)(matchStore ?? dummyStore, (match) => {
|
|
34
|
-
|
|
35
|
+
if ((opts.shouldThrow ?? true) && !match) {
|
|
36
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
|
|
37
|
+
(0, _tanstack_router_core.invariant)();
|
|
38
|
+
}
|
|
35
39
|
if (match === void 0) return;
|
|
36
40
|
const selected = opts.select ? opts.select(match) : match;
|
|
37
41
|
if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.cjs","names":[],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport
|
|
1
|
+
{"version":3,"file":"useMatch.cjs","names":[],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { invariant, replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport { useRouter } from './useRouter'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n MakeRouteMatch,\n MakeRouteMatchUnion,\n RegisteredRouter,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n} from '@tanstack/router-core'\n\nconst dummyStore = {\n state: undefined,\n get: () => undefined,\n subscribe: () => () => {},\n} as any\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\n/**\n * Read and select the nearest or targeted route match.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook\n */\nexport function useMatch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const router = useRouter<TRouter>()\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const key = opts.from ?? nearestMatchId\n const matchStore = key\n ? opts.from\n ? router.stores.getMatchStoreByRouteId(key)\n : router.stores.activeMatchStoresById.get(key)\n : undefined\n\n if (isServer ?? router.isServer) {\n const match = matchStore?.state\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined as any\n }\n\n return (opts.select ? opts.select(match as any) : match) as any\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(matchStore ?? dummyStore, (match) => {\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined\n }\n\n const selected = (\n opts.select ? opts.select(match as any) : match\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as any\n}\n"],"mappings":";;;;;;;;;AAoBA,IAAM,aAAa;CACjB,OAAO,KAAA;CACP,WAAW,KAAA;CACX,uBAAuB;CACxB;;;;;AAiED,SAAgB,SAQd,MAQ6E;CAC7E,MAAM,SAAS,kBAAA,WAAoB;CACnC,MAAM,iBAAiB,MAAM,WAC3B,KAAK,OAAO,qBAAA,oBAAoB,qBAAA,aACjC;CAED,MAAM,MAAM,KAAK,QAAQ;CACzB,MAAM,aAAa,MACf,KAAK,OACH,OAAO,OAAO,uBAAuB,IAAI,GACzC,OAAO,OAAO,sBAAsB,IAAI,IAAI,GAC9C,KAAA;AAEJ,KAAI,+BAAA,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,YAAY;AAC1B,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,IAAA,GAAA,sBAAA,YAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;AAGF,SAAQ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;;CAGpD,MAAM,iBAEJ,MAAM,OACJ,KAAA,EACD;AAGH,SAAA,GAAA,sBAAA,UAAgB,cAAc,aAAa,UAAU;AACnD,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,IAAA,GAAA,sBAAA,YAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;EAGF,MAAM,WACJ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;AAG5C,MAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;GACrE,MAAM,UAAA,GAAA,sBAAA,kBAA0B,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
|
package/dist/cjs/useRouter.cjs
CHANGED
|
@@ -2,8 +2,6 @@ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
|
2
2
|
const require_routerContext = require("./routerContext.cjs");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
react = require_runtime.__toESM(react);
|
|
5
|
-
let tiny_warning = require("tiny-warning");
|
|
6
|
-
tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
7
5
|
//#region src/useRouter.tsx
|
|
8
6
|
/**
|
|
9
7
|
* Access the current TanStack Router instance from React context.
|
|
@@ -17,7 +15,9 @@ tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
|
17
15
|
*/
|
|
18
16
|
function useRouter(opts) {
|
|
19
17
|
const value = react.useContext(require_routerContext.routerContext);
|
|
20
|
-
(
|
|
18
|
+
if (process.env.NODE_ENV !== "production") {
|
|
19
|
+
if ((opts?.warn ?? true) && !value) console.warn("Warning: useRouter must be used inside a <RouterProvider> component!");
|
|
20
|
+
}
|
|
21
21
|
return value;
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.cjs","names":[],"sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport
|
|
1
|
+
{"version":3,"file":"useRouter.cjs","names":[],"sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(routerContext)\n if (process.env.NODE_ENV !== 'production') {\n if ((opts?.warn ?? true) && !value) {\n console.warn(\n 'Warning: useRouter must be used inside a <RouterProvider> component!',\n )\n }\n }\n return value as any\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,UAAwD,MAE5D;CACV,MAAM,QAAQ,MAAM,WAAW,sBAAA,cAAc;AAC7C,KAAA,QAAA,IAAA,aAA6B;OACtB,MAAM,QAAQ,SAAS,CAAC,MAC3B,SAAQ,KACN,uEACD;;AAGL,QAAO"}
|
package/dist/esm/Match.js
CHANGED
|
@@ -6,19 +6,20 @@ import { CatchNotFound } from "./not-found.js";
|
|
|
6
6
|
import { SafeFragment } from "./SafeFragment.js";
|
|
7
7
|
import { renderRouteNotFound } from "./renderRouteNotFound.js";
|
|
8
8
|
import { ScrollRestoration } from "./scroll-restoration.js";
|
|
9
|
-
import { createControlledPromise, getLocationChangeInfo, isNotFound, isRedirect, rootRouteId } from "@tanstack/router-core";
|
|
9
|
+
import { createControlledPromise, getLocationChangeInfo, invariant, isNotFound, isRedirect, rootRouteId } from "@tanstack/router-core";
|
|
10
10
|
import * as React$1 from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
import warning from "tiny-warning";
|
|
13
12
|
import { useStore } from "@tanstack/react-store";
|
|
14
13
|
import { isServer } from "@tanstack/router-core/isServer";
|
|
15
|
-
import invariant from "tiny-invariant";
|
|
16
14
|
//#region src/Match.tsx
|
|
17
15
|
var Match = React$1.memo(function MatchImpl({ matchId }) {
|
|
18
16
|
const router = useRouter();
|
|
19
17
|
if (isServer ?? router.isServer) {
|
|
20
18
|
const match = router.stores.activeMatchStoresById.get(matchId)?.state;
|
|
21
|
-
|
|
19
|
+
if (!match) {
|
|
20
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find match for matchId "${matchId}". Please file an issue!`);
|
|
21
|
+
invariant();
|
|
22
|
+
}
|
|
22
23
|
const routeId = match.routeId;
|
|
23
24
|
const parentRouteId = router.routesById[routeId].parentRoute?.id;
|
|
24
25
|
return /* @__PURE__ */ jsx(MatchView, {
|
|
@@ -34,7 +35,10 @@ var Match = React$1.memo(function MatchImpl({ matchId }) {
|
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
const matchStore = router.stores.activeMatchStoresById.get(matchId);
|
|
37
|
-
|
|
38
|
+
if (!matchStore) {
|
|
39
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find match for matchId "${matchId}". Please file an issue!`);
|
|
40
|
+
invariant();
|
|
41
|
+
}
|
|
38
42
|
const resetKey = useStore(router.stores.loadedAt, (loadedAt) => loadedAt);
|
|
39
43
|
const match = useStore(matchStore, (value) => value);
|
|
40
44
|
return /* @__PURE__ */ jsx(MatchView, {
|
|
@@ -78,7 +82,7 @@ function MatchView({ router, matchId, resetKey, matchState }) {
|
|
|
78
82
|
errorComponent: routeErrorComponent || ErrorComponent,
|
|
79
83
|
onCatch: (error, errorInfo) => {
|
|
80
84
|
if (isNotFound(error)) throw error;
|
|
81
|
-
|
|
85
|
+
if (process.env.NODE_ENV !== "production") console.warn(`Warning: Error in route match: ${matchId}`);
|
|
82
86
|
routeOnCatch?.(error, errorInfo);
|
|
83
87
|
},
|
|
84
88
|
children: /* @__PURE__ */ jsx(ResolvedNotFoundBoundary, {
|
|
@@ -115,7 +119,10 @@ var MatchInner = React$1.memo(function MatchInnerImpl({ matchId }) {
|
|
|
115
119
|
const router = useRouter();
|
|
116
120
|
if (isServer ?? router.isServer) {
|
|
117
121
|
const match = router.stores.activeMatchStoresById.get(matchId)?.state;
|
|
118
|
-
|
|
122
|
+
if (!match) {
|
|
123
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find match for matchId "${matchId}". Please file an issue!`);
|
|
124
|
+
invariant();
|
|
125
|
+
}
|
|
119
126
|
const routeId = match.routeId;
|
|
120
127
|
const route = router.routesById[routeId];
|
|
121
128
|
const remountDeps = (router.routesById[routeId].options.remountDeps ?? router.options.defaultRemountDeps)?.({
|
|
@@ -131,11 +138,17 @@ var MatchInner = React$1.memo(function MatchInnerImpl({ matchId }) {
|
|
|
131
138
|
if (match._forcePending) throw router.getMatch(match.id)?._nonReactive.minPendingPromise;
|
|
132
139
|
if (match.status === "pending") throw router.getMatch(match.id)?._nonReactive.loadPromise;
|
|
133
140
|
if (match.status === "notFound") {
|
|
134
|
-
|
|
141
|
+
if (!isNotFound(match.error)) {
|
|
142
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected a notFound error");
|
|
143
|
+
invariant();
|
|
144
|
+
}
|
|
135
145
|
return renderRouteNotFound(router, route, match.error);
|
|
136
146
|
}
|
|
137
147
|
if (match.status === "redirected") {
|
|
138
|
-
|
|
148
|
+
if (!isRedirect(match.error)) {
|
|
149
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected a redirect error");
|
|
150
|
+
invariant();
|
|
151
|
+
}
|
|
139
152
|
throw router.getMatch(match.id)?._nonReactive.loadPromise;
|
|
140
153
|
}
|
|
141
154
|
if (match.status === "error") return /* @__PURE__ */ jsx((route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent, {
|
|
@@ -146,7 +159,10 @@ var MatchInner = React$1.memo(function MatchInnerImpl({ matchId }) {
|
|
|
146
159
|
return out;
|
|
147
160
|
}
|
|
148
161
|
const matchStore = router.stores.activeMatchStoresById.get(matchId);
|
|
149
|
-
|
|
162
|
+
if (!matchStore) {
|
|
163
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find match for matchId "${matchId}". Please file an issue!`);
|
|
164
|
+
invariant();
|
|
165
|
+
}
|
|
150
166
|
const match = useStore(matchStore, (value) => value);
|
|
151
167
|
const routeId = match.routeId;
|
|
152
168
|
const route = router.routesById[routeId];
|
|
@@ -195,11 +211,17 @@ var MatchInner = React$1.memo(function MatchInnerImpl({ matchId }) {
|
|
|
195
211
|
throw router.getMatch(match.id)?._nonReactive.loadPromise;
|
|
196
212
|
}
|
|
197
213
|
if (match.status === "notFound") {
|
|
198
|
-
|
|
214
|
+
if (!isNotFound(match.error)) {
|
|
215
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected a notFound error");
|
|
216
|
+
invariant();
|
|
217
|
+
}
|
|
199
218
|
return renderRouteNotFound(router, route, match.error);
|
|
200
219
|
}
|
|
201
220
|
if (match.status === "redirected") {
|
|
202
|
-
|
|
221
|
+
if (!isRedirect(match.error)) {
|
|
222
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected a redirect error");
|
|
223
|
+
invariant();
|
|
224
|
+
}
|
|
203
225
|
throw router.getMatch(match.id)?._nonReactive.loadPromise;
|
|
204
226
|
}
|
|
205
227
|
if (match.status === "error") {
|
|
@@ -241,7 +263,10 @@ var Outlet = React$1.memo(function OutletImpl() {
|
|
|
241
263
|
const route = routeId ? router.routesById[routeId] : void 0;
|
|
242
264
|
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsx(router.options.defaultPendingComponent, {}) : null;
|
|
243
265
|
if (parentGlobalNotFound) {
|
|
244
|
-
|
|
266
|
+
if (!route) {
|
|
267
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Could not resolve route for Outlet render");
|
|
268
|
+
invariant();
|
|
269
|
+
}
|
|
245
270
|
return renderRouteNotFound(router, route, void 0);
|
|
246
271
|
}
|
|
247
272
|
if (!childMatchId) return null;
|
package/dist/esm/Match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Match.js","names":[],"sources":["../../src/Match.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport {\n createControlledPromise,\n getLocationChangeInfo,\n isNotFound,\n isRedirect,\n rootRouteId,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { CatchNotFound } from './not-found'\nimport { matchContext } from './matchContext'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { ScrollRestoration } from './scroll-restoration'\nimport { ClientOnly } from './ClientOnly'\nimport type {\n AnyRoute,\n ParsedLocation,\n RootRouteOptions,\n} from '@tanstack/router-core'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.activeMatchStoresById.get(matchId)?.state\n invariant(\n match,\n `Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={router.stores.loadedAt.state}\n matchState={{\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId,\n }}\n />\n )\n }\n\n // Subscribe directly to the match store from the pool.\n // The matchId prop is stable for this component's lifetime (set by Outlet),\n // and reconcileMatchPool reuses stores for the same matchId.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchStore = router.stores.activeMatchStoresById.get(matchId)\n invariant(\n matchStore,\n `Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const resetKey = useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchState = React.useMemo(() => {\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return {\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId: parentRouteId as string | undefined,\n } satisfies MatchViewState\n }, [match._displayPending, match.routeId, match.ssr, router.routesById])\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={resetKey}\n matchState={matchState}\n />\n )\n})\n\ntype MatchViewState = {\n routeId: string\n ssr: boolean | 'data-only' | undefined\n _displayPending: boolean | undefined\n parentRouteId: string | undefined\n}\n\nfunction MatchView({\n router,\n matchId,\n resetKey,\n matchState,\n}: {\n router: ReturnType<typeof useRouter>\n matchId: string\n resetKey: number\n matchState: MatchViewState\n}) {\n const route: AnyRoute = router.routesById[matchState.routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const resolvedNoSsr =\n matchState.ssr === false || matchState.ssr === 'data-only'\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n ((route.options.errorComponent as any)?.preload || resolvedNoSsr))\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const ShellComponent = route.isRoot\n ? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)\n : SafeFragment\n return (\n <ShellComponent>\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== matchState.routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n {resolvedNoSsr || matchState._displayPending ? (\n <ClientOnly fallback={pendingElement}>\n <MatchInner matchId={matchId} />\n </ClientOnly>\n ) : (\n <MatchInner matchId={matchId} />\n )}\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n {matchState.parentRouteId === rootRouteId &&\n router.options.scrollRestoration ? (\n <>\n <OnRendered />\n <ScrollRestoration />\n </>\n ) : null}\n </ShellComponent>\n )\n}\n\n// On Rendered can't happen above the root layout because it actually\n// renders a dummy dom element to track the rendered state of the app.\n// We render a script tag with a key that changes based on the current\n// location state.__TSR_key. Also, because it's below the root layout, it\n// allows us to fire onRendered events even after a hydration mismatch\n// error that occurred above the root layout (like bad head/link tags,\n// which is common).\nfunction OnRendered() {\n const router = useRouter()\n\n const prevLocationRef = React.useRef<undefined | ParsedLocation<{}>>(\n undefined,\n )\n\n return (\n <script\n key={router.latestLocation.state.__TSR_key}\n suppressHydrationWarning\n ref={(el) => {\n if (\n el &&\n (prevLocationRef.current === undefined ||\n prevLocationRef.current.href !== router.latestLocation.href)\n ) {\n router.emit({\n type: 'onRendered',\n ...getLocationChangeInfo(\n router.stores.location.state,\n router.stores.resolvedLocation.state,\n ),\n })\n prevLocationRef.current = router.latestLocation\n }\n }}\n />\n )\n}\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n matchId,\n}: {\n matchId: string\n}): any {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.activeMatchStoresById.get(matchId)?.state\n invariant(\n match,\n `Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n const key = remountDeps ? JSON.stringify(remountDeps) : undefined\n const Comp = route.options.component ?? router.options.defaultComponent\n const out = Comp ? <Comp key={key} /> : <Outlet />\n\n if (match._displayPending) {\n throw router.getMatch(match.id)?._nonReactive.displayPendingPromise\n }\n\n if (match._forcePending) {\n throw router.getMatch(match.id)?._nonReactive.minPendingPromise\n }\n\n if (match.status === 'pending') {\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'notFound') {\n invariant(isNotFound(match.error), 'Expected a notFound error')\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n invariant(isRedirect(match.error), 'Expected a redirect error')\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'error') {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n return out\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchStore = router.stores.activeMatchStoresById.get(matchId)\n invariant(\n matchStore,\n `Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const key = React.useMemo(() => {\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n return remountDeps ? JSON.stringify(remountDeps) : undefined\n }, [\n routeId,\n match.loaderDeps,\n match._strictParams,\n match._strictSearch,\n router.options.defaultRemountDeps,\n router.routesById,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n if (Comp) {\n return <Comp key={key} />\n }\n return <Outlet />\n }, [key, route.options.component, router.options.defaultComponent])\n\n if (match._displayPending) {\n throw router.getMatch(match.id)?._nonReactive.displayPendingPromise\n }\n\n if (match._forcePending) {\n throw router.getMatch(match.id)?._nonReactive.minPendingPromise\n }\n\n // see also hydrate() in packages/router-core/src/ssr/ssr-client.ts\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const routerMatch = router.getMatch(match.id)\n if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!(isServer ?? router.isServer)) {\n const minPendingPromise = createControlledPromise<void>()\n\n routerMatch._nonReactive.minPendingPromise = minPendingPromise\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n routerMatch._nonReactive.minPendingPromise = undefined\n }, pendingMinMs)\n }\n }\n }\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'notFound') {\n invariant(isNotFound(match.error), 'Expected a notFound error')\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (isServer ?? router.isServer) {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n throw match.error\n }\n\n return out\n})\n\n/**\n * Render the next child match in the route tree. Typically used inside\n * a route component to render nested routes.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent\n */\nexport const Outlet = React.memo(function OutletImpl() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n\n let routeId: string | undefined\n let parentGlobalNotFound = false\n let childMatchId: string | undefined\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.activeMatchesSnapshot.state\n const parentIndex = matchId\n ? matches.findIndex((match) => match.id === matchId)\n : -1\n const parentMatch = parentIndex >= 0 ? matches[parentIndex] : undefined\n routeId = parentMatch?.routeId as string | undefined\n parentGlobalNotFound = parentMatch?.globalNotFound ?? false\n childMatchId =\n parentIndex >= 0 ? (matches[parentIndex + 1]?.id as string) : undefined\n } else {\n // Subscribe directly to the match store from the pool instead of\n // the two-level byId → matchStore pattern.\n const parentMatchStore = matchId\n ? router.stores.activeMatchStoresById.get(matchId)\n : undefined\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n ;[routeId, parentGlobalNotFound] = useStore(parentMatchStore, (match) => [\n match?.routeId as string | undefined,\n match?.globalNotFound ?? false,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n childMatchId = useStore(router.stores.matchesId, (ids) => {\n const index = ids.findIndex((id) => id === matchId)\n return ids[index + 1]\n })\n }\n\n const route = routeId ? router.routesById[routeId] : undefined\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (parentGlobalNotFound) {\n invariant(route, 'Could not resolve route for Outlet render')\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n if (routeId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,IAAa,QAAQ,QAAM,KAAK,SAAS,UAAU,EACjD,WAGC;CACD,MAAM,SAAS,WAAW;AAE1B,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,OAAO,OAAO,sBAAsB,IAAI,QAAQ,EAAE;AAChE,YACE,OACA,qCAAqC,QAAQ,0BAC9C;EAED,MAAM,UAAU,MAAM;EACtB,MAAM,gBAAiB,OAAO,WAAW,SAAsB,aAC3D;AAEJ,SACE,oBAAC,WAAD;GACU;GACC;GACT,UAAU,OAAO,OAAO,SAAS;GACjC,YAAY;IACV;IACA,KAAK,MAAM;IACX,iBAAiB,MAAM;IACvB;IACD;GACD,CAAA;;CAQN,MAAM,aAAa,OAAO,OAAO,sBAAsB,IAAI,QAAQ;AACnE,WACE,YACA,qCAAqC,QAAQ,0BAC9C;CAED,MAAM,WAAW,SAAS,OAAO,OAAO,WAAW,aAAa,SAAS;CAEzE,MAAM,QAAQ,SAAS,aAAa,UAAU,MAAM;AAepD,QACE,oBAAC,WAAD;EACU;EACC;EACC;EACE,YAlBG,QAAM,cAAc;GACrC,MAAM,UAAU,MAAM;GACtB,MAAM,gBAAiB,OAAO,WAAW,SAA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I,YAAY,YACd,QACE,oBAAC,QAAM,UAAP;EAAgB,UAAU;YAAiB;EAA2B,CAAA;AAI1E,QAAO;EACP"}
|
|
1
|
+
{"version":3,"file":"Match.js","names":[],"sources":["../../src/Match.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport {\n createControlledPromise,\n getLocationChangeInfo,\n invariant,\n isNotFound,\n isRedirect,\n rootRouteId,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { CatchNotFound } from './not-found'\nimport { matchContext } from './matchContext'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { ScrollRestoration } from './scroll-restoration'\nimport { ClientOnly } from './ClientOnly'\nimport type {\n AnyRoute,\n ParsedLocation,\n RootRouteOptions,\n} from '@tanstack/router-core'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.activeMatchStoresById.get(matchId)?.state\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={router.stores.loadedAt.state}\n matchState={{\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId,\n }}\n />\n )\n }\n\n // Subscribe directly to the match store from the pool.\n // The matchId prop is stable for this component's lifetime (set by Outlet),\n // and reconcileMatchPool reuses stores for the same matchId.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchStore = router.stores.activeMatchStoresById.get(matchId)\n if (!matchStore) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const resetKey = useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchState = React.useMemo(() => {\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return {\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId: parentRouteId as string | undefined,\n } satisfies MatchViewState\n }, [match._displayPending, match.routeId, match.ssr, router.routesById])\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={resetKey}\n matchState={matchState}\n />\n )\n})\n\ntype MatchViewState = {\n routeId: string\n ssr: boolean | 'data-only' | undefined\n _displayPending: boolean | undefined\n parentRouteId: string | undefined\n}\n\nfunction MatchView({\n router,\n matchId,\n resetKey,\n matchState,\n}: {\n router: ReturnType<typeof useRouter>\n matchId: string\n resetKey: number\n matchState: MatchViewState\n}) {\n const route: AnyRoute = router.routesById[matchState.routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const resolvedNoSsr =\n matchState.ssr === false || matchState.ssr === 'data-only'\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n ((route.options.errorComponent as any)?.preload || resolvedNoSsr))\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const ShellComponent = route.isRoot\n ? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)\n : SafeFragment\n return (\n <ShellComponent>\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Warning: Error in route match: ${matchId}`)\n }\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== matchState.routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n {resolvedNoSsr || matchState._displayPending ? (\n <ClientOnly fallback={pendingElement}>\n <MatchInner matchId={matchId} />\n </ClientOnly>\n ) : (\n <MatchInner matchId={matchId} />\n )}\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n {matchState.parentRouteId === rootRouteId &&\n router.options.scrollRestoration ? (\n <>\n <OnRendered />\n <ScrollRestoration />\n </>\n ) : null}\n </ShellComponent>\n )\n}\n\n// On Rendered can't happen above the root layout because it actually\n// renders a dummy dom element to track the rendered state of the app.\n// We render a script tag with a key that changes based on the current\n// location state.__TSR_key. Also, because it's below the root layout, it\n// allows us to fire onRendered events even after a hydration mismatch\n// error that occurred above the root layout (like bad head/link tags,\n// which is common).\nfunction OnRendered() {\n const router = useRouter()\n\n const prevLocationRef = React.useRef<undefined | ParsedLocation<{}>>(\n undefined,\n )\n\n return (\n <script\n key={router.latestLocation.state.__TSR_key}\n suppressHydrationWarning\n ref={(el) => {\n if (\n el &&\n (prevLocationRef.current === undefined ||\n prevLocationRef.current.href !== router.latestLocation.href)\n ) {\n router.emit({\n type: 'onRendered',\n ...getLocationChangeInfo(\n router.stores.location.state,\n router.stores.resolvedLocation.state,\n ),\n })\n prevLocationRef.current = router.latestLocation\n }\n }}\n />\n )\n}\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n matchId,\n}: {\n matchId: string\n}): any {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.activeMatchStoresById.get(matchId)?.state\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n const key = remountDeps ? JSON.stringify(remountDeps) : undefined\n const Comp = route.options.component ?? router.options.defaultComponent\n const out = Comp ? <Comp key={key} /> : <Outlet />\n\n if (match._displayPending) {\n throw router.getMatch(match.id)?._nonReactive.displayPendingPromise\n }\n\n if (match._forcePending) {\n throw router.getMatch(match.id)?._nonReactive.minPendingPromise\n }\n\n if (match.status === 'pending') {\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'notFound') {\n if (!isNotFound(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a notFound error')\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n if (!isRedirect(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a redirect error')\n }\n\n invariant()\n }\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'error') {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n return out\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchStore = router.stores.activeMatchStoresById.get(matchId)\n if (!matchStore) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const key = React.useMemo(() => {\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n return remountDeps ? JSON.stringify(remountDeps) : undefined\n }, [\n routeId,\n match.loaderDeps,\n match._strictParams,\n match._strictSearch,\n router.options.defaultRemountDeps,\n router.routesById,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n if (Comp) {\n return <Comp key={key} />\n }\n return <Outlet />\n }, [key, route.options.component, router.options.defaultComponent])\n\n if (match._displayPending) {\n throw router.getMatch(match.id)?._nonReactive.displayPendingPromise\n }\n\n if (match._forcePending) {\n throw router.getMatch(match.id)?._nonReactive.minPendingPromise\n }\n\n // see also hydrate() in packages/router-core/src/ssr/ssr-client.ts\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const routerMatch = router.getMatch(match.id)\n if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!(isServer ?? router.isServer)) {\n const minPendingPromise = createControlledPromise<void>()\n\n routerMatch._nonReactive.minPendingPromise = minPendingPromise\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n routerMatch._nonReactive.minPendingPromise = undefined\n }, pendingMinMs)\n }\n }\n }\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'notFound') {\n if (!isNotFound(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a notFound error')\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n if (!isRedirect(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a redirect error')\n }\n\n invariant()\n }\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (isServer ?? router.isServer) {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n throw match.error\n }\n\n return out\n})\n\n/**\n * Render the next child match in the route tree. Typically used inside\n * a route component to render nested routes.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent\n */\nexport const Outlet = React.memo(function OutletImpl() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n\n let routeId: string | undefined\n let parentGlobalNotFound = false\n let childMatchId: string | undefined\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.activeMatchesSnapshot.state\n const parentIndex = matchId\n ? matches.findIndex((match) => match.id === matchId)\n : -1\n const parentMatch = parentIndex >= 0 ? matches[parentIndex] : undefined\n routeId = parentMatch?.routeId as string | undefined\n parentGlobalNotFound = parentMatch?.globalNotFound ?? false\n childMatchId =\n parentIndex >= 0 ? (matches[parentIndex + 1]?.id as string) : undefined\n } else {\n // Subscribe directly to the match store from the pool instead of\n // the two-level byId → matchStore pattern.\n const parentMatchStore = matchId\n ? router.stores.activeMatchStoresById.get(matchId)\n : undefined\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n ;[routeId, parentGlobalNotFound] = useStore(parentMatchStore, (match) => [\n match?.routeId as string | undefined,\n match?.globalNotFound ?? false,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n childMatchId = useStore(router.stores.matchesId, (ids) => {\n const index = ids.findIndex((id) => id === matchId)\n return ids[index + 1]\n })\n }\n\n const route = routeId ? router.routesById[routeId] : undefined\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (parentGlobalNotFound) {\n if (!route) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Could not resolve route for Outlet render',\n )\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n if (routeId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"mappings":";;;;;;;;;;;;;;AAyBA,IAAa,QAAQ,QAAM,KAAK,SAAS,UAAU,EACjD,WAGC;CACD,MAAM,SAAS,WAAW;AAE1B,KAAI,YAAY,OAAO,UAAU;EAC/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;;AAGtD,KAAI,CAAC,aACH,QAAO;CAGT,MAAM,YAAY,oBAAC,OAAD,EAAO,SAAS,cAAgB,CAAA;AAElD,KAAI,YAAY,YACd,QACE,oBAAC,QAAM,UAAP;EAAgB,UAAU;YAAiB;EAA2B,CAAA;AAI1E,QAAO;EACP"}
|
package/dist/esm/Matches.js
CHANGED
|
@@ -7,7 +7,6 @@ import { Match } from "./Match.js";
|
|
|
7
7
|
import { replaceEqualDeep, rootRouteId } from "@tanstack/router-core";
|
|
8
8
|
import * as React$1 from "react";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import warning from "tiny-warning";
|
|
11
10
|
import { useStore } from "@tanstack/react-store";
|
|
12
11
|
import { isServer } from "@tanstack/router-core/isServer";
|
|
13
12
|
//#region src/Matches.tsx
|
|
@@ -37,8 +36,8 @@ function MatchesInner() {
|
|
|
37
36
|
getResetKey: () => resetKey,
|
|
38
37
|
errorComponent: ErrorComponent,
|
|
39
38
|
onCatch: process.env.NODE_ENV !== "production" ? (error) => {
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
console.warn(`Warning: The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`);
|
|
40
|
+
console.warn(`Warning: ${error.message || error.toString()}`);
|
|
42
41
|
} : void 0,
|
|
43
42
|
children: matchComponent
|
|
44
43
|
})
|
package/dist/esm/Matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matches.js","names":[],"sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { useStore } from '@tanstack/react-store'\nimport { replaceEqualDeep, rootRouteId } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { Transitioner } from './Transitioner'\nimport { matchContext } from './matchContext'\nimport { Match } from './Match'\nimport { SafeFragment } from './SafeFragment'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRoute,\n AnyRouter,\n DeepPartial,\n Expand,\n MakeOptionalPathParams,\n MakeOptionalSearchParams,\n MakeRouteMatchUnion,\n MaskOptions,\n MatchRouteOptions,\n NoInfer,\n RegisteredRouter,\n ResolveRelativePath,\n ResolveRoute,\n RouteByPath,\n ToSubOptionsProps,\n} from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouteMatchExtensions {\n meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>\n links?: Array<React.JSX.IntrinsicElements['link'] | undefined>\n scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n styles?: Array<React.JSX.IntrinsicElements['style'] | undefined>\n headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n }\n}\n\n/**\n * Internal component that renders the router's active match tree with\n * suspense, error, and not-found boundaries. Rendered by `RouterProvider`.\n */\nexport function Matches() {\n const router = useRouter()\n const rootRoute: AnyRoute = router.routesById[rootRouteId]\n\n const PendingComponent =\n rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n // Do not render a root Suspense during SSR or hydrating from SSR\n const ResolvedSuspense =\n (isServer ?? router.isServer) ||\n (typeof document !== 'undefined' && router.ssr)\n ? SafeFragment\n : React.Suspense\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n {!(isServer ?? router.isServer) && <Transitioner />}\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const router = useRouter()\n const _isServer = isServer ?? router.isServer\n const matchId = _isServer\n ? router.stores.firstMatchId.state\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.firstMatchId, (id) => id)\n const resetKey = _isServer\n ? router.stores.loadedAt.state\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n\n const matchComponent = matchId ? <Match matchId={matchId} /> : null\n\n return (\n <matchContext.Provider value={matchId}>\n {router.options.disableGlobalCatchBoundary ? (\n matchComponent\n ) : (\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={\n process.env.NODE_ENV !== 'production'\n ? (error) => {\n warning(\n false,\n `The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n warning(false, error.message || error.toString())\n }\n : undefined\n }\n >\n {matchComponent}\n </CatchBoundary>\n )}\n </matchContext.Provider>\n )\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> &\n DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> &\n MaskOptions<TRouter, TMaskFrom, TMaskTo> &\n MatchRouteOptions\n\n/**\n * Create a matcher function for testing locations against route definitions.\n *\n * The returned function accepts standard navigation options (`to`, `params`,\n * `search`, etc.) and returns either `false` (no match) or the matched params\n * object when the route matches the current or pending location.\n *\n * Useful for conditional rendering and active UI states.\n *\n * @returns A `matchRoute(options)` function that returns `false` or params.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook\n */\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n if (!(isServer ?? router.isServer)) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.matchRouteReactivity, (d) => d)\n }\n\n return React.useCallback(\n <\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | Expand<ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']> => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouter['routeTree'],\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => React.ReactNode)\n | React.ReactNode\n}\n\n/**\n * Component that conditionally renders its children based on whether a route\n * matches the provided `from`/`to` options. If `children` is a function, it\n * receives the matched params object.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/matchRouteComponent\n */\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any) as boolean\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return params ? props.children : null\n}\n\nexport interface UseMatchesBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n matches: Array<MakeRouteMatchUnion<TRouter>>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseMatchesResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? Array<MakeRouteMatchUnion<TRouter>> : TSelected\n\nexport function useMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n const previousResult =\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.activeMatchesSnapshot.state as Array<\n MakeRouteMatchUnion<TRouter>\n >\n return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<\n TRouter,\n TSelected\n >\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.stores.activeMatchesSnapshot, (matches) => {\n const selected = opts?.select\n ? opts.select(matches as Array<MakeRouteMatchUnion<TRouter>>)\n : (matches as any)\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseMatchesResult<TRouter, TSelected>\n}\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @returns The array of matches (or the selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\nexport function useParentMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n\n/**\n * Read the array of active route matches that are children of the current\n * match (or selected parent) in the match tree.\n */\nexport function useChildMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+CA,SAAgB,UAAU;CACxB,MAAM,SAAS,WAAW;CAG1B,MAAM,mBAFsB,OAAO,WAAW,aAGlC,QAAQ,oBAAoB,OAAO,QAAQ;CAEvD,MAAM,iBAAiB,mBAAmB,oBAAC,kBAAD,EAAoB,CAAA,GAAG;CASjE,MAAM,QACJ,sBANC,YAAY,OAAO,aACnB,OAAO,aAAa,eAAe,OAAO,MACvC,eACA,QAAM,UAGV;EAAkB,UAAU;YAA5B,CACG,EAAE,YAAY,OAAO,aAAa,oBAAC,cAAD,EAAgB,CAAA,EACnD,oBAAC,cAAD,EAAgB,CAAA,CACC;;AAGrB,QAAO,OAAO,QAAQ,YACpB,oBAAC,OAAO,QAAQ,WAAhB,EAAA,UAA2B,OAAiC,CAAA,GAE5D;;AAIJ,SAAS,eAAe;CACtB,MAAM,SAAS,WAAW;CAC1B,MAAM,YAAY,YAAY,OAAO;CACrC,MAAM,UAAU,YACZ,OAAO,OAAO,aAAa,QAE3B,SAAS,OAAO,OAAO,eAAe,OAAO,GAAG;CAC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,MAAI,MAAM,qBAAqB,OAAO,QAAQ,0BAA0B;GACtE,MAAM,SAAS,iBAAiB,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP;;;;;;;;;;;;;;;;;AAmBJ,SAAgB,iBAKd,MAEsC;CACtC,MAAM,iBAAiB,QAAM,WAAW,aAAa;AAErD,QAAO,WAAW;EAChB,SAAS,YAAiD;AACxD,aAAU,QAAQ,MAChB,GACA,QAAQ,WAAW,MAAM,EAAE,OAAO,eAAe,CAClD;AACD,UAAO,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;EAE/C,mBAAmB,MAAM;EAC1B,CAAQ;;;;;;AAOX,SAAgB,gBAKd,MAEsC;CACtC,MAAM,iBAAiB,QAAM,WAAW,aAAa;AAErD,QAAO,WAAW;EAChB,SAAS,YAAiD;AACxD,aAAU,QAAQ,MAChB,QAAQ,WAAW,MAAM,EAAE,OAAO,eAAe,GAAG,EACrD;AACD,UAAO,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;EAE/C,mBAAmB,MAAM;EAC1B,CAAQ"}
|
|
1
|
+
{"version":3,"file":"Matches.js","names":[],"sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { replaceEqualDeep, rootRouteId } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { Transitioner } from './Transitioner'\nimport { matchContext } from './matchContext'\nimport { Match } from './Match'\nimport { SafeFragment } from './SafeFragment'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRoute,\n AnyRouter,\n DeepPartial,\n Expand,\n MakeOptionalPathParams,\n MakeOptionalSearchParams,\n MakeRouteMatchUnion,\n MaskOptions,\n MatchRouteOptions,\n NoInfer,\n RegisteredRouter,\n ResolveRelativePath,\n ResolveRoute,\n RouteByPath,\n ToSubOptionsProps,\n} from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouteMatchExtensions {\n meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>\n links?: Array<React.JSX.IntrinsicElements['link'] | undefined>\n scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n styles?: Array<React.JSX.IntrinsicElements['style'] | undefined>\n headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n }\n}\n\n/**\n * Internal component that renders the router's active match tree with\n * suspense, error, and not-found boundaries. Rendered by `RouterProvider`.\n */\nexport function Matches() {\n const router = useRouter()\n const rootRoute: AnyRoute = router.routesById[rootRouteId]\n\n const PendingComponent =\n rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n // Do not render a root Suspense during SSR or hydrating from SSR\n const ResolvedSuspense =\n (isServer ?? router.isServer) ||\n (typeof document !== 'undefined' && router.ssr)\n ? SafeFragment\n : React.Suspense\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n {!(isServer ?? router.isServer) && <Transitioner />}\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const router = useRouter()\n const _isServer = isServer ?? router.isServer\n const matchId = _isServer\n ? router.stores.firstMatchId.state\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.firstMatchId, (id) => id)\n const resetKey = _isServer\n ? router.stores.loadedAt.state\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n\n const matchComponent = matchId ? <Match matchId={matchId} /> : null\n\n return (\n <matchContext.Provider value={matchId}>\n {router.options.disableGlobalCatchBoundary ? (\n matchComponent\n ) : (\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={\n process.env.NODE_ENV !== 'production'\n ? (error) => {\n console.warn(\n `Warning: The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n console.warn(`Warning: ${error.message || error.toString()}`)\n }\n : undefined\n }\n >\n {matchComponent}\n </CatchBoundary>\n )}\n </matchContext.Provider>\n )\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> &\n DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> &\n MaskOptions<TRouter, TMaskFrom, TMaskTo> &\n MatchRouteOptions\n\n/**\n * Create a matcher function for testing locations against route definitions.\n *\n * The returned function accepts standard navigation options (`to`, `params`,\n * `search`, etc.) and returns either `false` (no match) or the matched params\n * object when the route matches the current or pending location.\n *\n * Useful for conditional rendering and active UI states.\n *\n * @returns A `matchRoute(options)` function that returns `false` or params.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook\n */\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n if (!(isServer ?? router.isServer)) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.matchRouteReactivity, (d) => d)\n }\n\n return React.useCallback(\n <\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | Expand<ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']> => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouter['routeTree'],\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => React.ReactNode)\n | React.ReactNode\n}\n\n/**\n * Component that conditionally renders its children based on whether a route\n * matches the provided `from`/`to` options. If `children` is a function, it\n * receives the matched params object.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/matchRouteComponent\n */\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any) as boolean\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return params ? props.children : null\n}\n\nexport interface UseMatchesBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n matches: Array<MakeRouteMatchUnion<TRouter>>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseMatchesResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? Array<MakeRouteMatchUnion<TRouter>> : TSelected\n\nexport function useMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n const previousResult =\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.activeMatchesSnapshot.state as Array<\n MakeRouteMatchUnion<TRouter>\n >\n return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<\n TRouter,\n TSelected\n >\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.stores.activeMatchesSnapshot, (matches) => {\n const selected = opts?.select\n ? opts.select(matches as Array<MakeRouteMatchUnion<TRouter>>)\n : (matches as any)\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseMatchesResult<TRouter, TSelected>\n}\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @returns The array of matches (or the selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\nexport function useParentMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n\n/**\n * Read the array of active route matches that are children of the current\n * match (or selected parent) in the match tree.\n */\nexport function useChildMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8CA,SAAgB,UAAU;CACxB,MAAM,SAAS,WAAW;CAG1B,MAAM,mBAFsB,OAAO,WAAW,aAGlC,QAAQ,oBAAoB,OAAO,QAAQ;CAEvD,MAAM,iBAAiB,mBAAmB,oBAAC,kBAAD,EAAoB,CAAA,GAAG;CASjE,MAAM,QACJ,sBANC,YAAY,OAAO,aACnB,OAAO,aAAa,eAAe,OAAO,MACvC,eACA,QAAM,UAGV;EAAkB,UAAU;YAA5B,CACG,EAAE,YAAY,OAAO,aAAa,oBAAC,cAAD,EAAgB,CAAA,EACnD,oBAAC,cAAD,EAAgB,CAAA,CACC;;AAGrB,QAAO,OAAO,QAAQ,YACpB,oBAAC,OAAO,QAAQ,WAAhB,EAAA,UAA2B,OAAiC,CAAA,GAE5D;;AAIJ,SAAS,eAAe;CACtB,MAAM,SAAS,WAAW;CAC1B,MAAM,YAAY,YAAY,OAAO;CACrC,MAAM,UAAU,YACZ,OAAO,OAAO,aAAa,QAE3B,SAAS,OAAO,OAAO,eAAe,OAAO,GAAG;CACpD,MAAM,WAAW,YACb,OAAO,OAAO,SAAS,QAEvB,SAAS,OAAO,OAAO,WAAW,aAAa,SAAS;CAE5D,MAAM,iBAAiB,UAAU,oBAAC,OAAD,EAAgB,SAAW,CAAA,GAAG;AAE/D,QACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;YAC3B,OAAO,QA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BAAiB,QAAM,WAAW,aAAa;AAErD,QAAO,WAAW;EAChB,SAAS,YAAiD;AACxD,aAAU,QAAQ,MAChB,GACA,QAAQ,WAAW,MAAM,EAAE,OAAO,eAAe,CAClD;AACD,UAAO,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;EAE/C,mBAAmB,MAAM;EAC1B,CAAQ;;;;;;AAOX,SAAgB,gBAKd,MAEsC;CACtC,MAAM,iBAAiB,QAAM,WAAW,aAAa;AAErD,QAAO,WAAW;EAChB,SAAS,YAAiD;AACxD,aAAU,QAAQ,MAChB,QAAQ,WAAW,MAAM,EAAE,OAAO,eAAe,GAAG,EACrD;AACD,UAAO,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;EAE/C,mBAAmB,MAAM;EAC1B,CAAQ"}
|
package/dist/esm/fileRoute.js
CHANGED
|
@@ -7,7 +7,6 @@ import { useSearch } from "./useSearch.js";
|
|
|
7
7
|
import { useNavigate } from "./useNavigate.js";
|
|
8
8
|
import { useRouteContext } from "./useRouteContext.js";
|
|
9
9
|
import { createRoute } from "./route.js";
|
|
10
|
-
import warning from "tiny-warning";
|
|
11
10
|
//#region src/fileRoute.ts
|
|
12
11
|
/**
|
|
13
12
|
* Creates a file-based Route factory for a given path.
|
|
@@ -32,7 +31,9 @@ var FileRoute = class {
|
|
|
32
31
|
constructor(path, _opts) {
|
|
33
32
|
this.path = path;
|
|
34
33
|
this.createRoute = (options) => {
|
|
35
|
-
if (process.env.NODE_ENV !== "production")
|
|
34
|
+
if (process.env.NODE_ENV !== "production") {
|
|
35
|
+
if (!this.silent) console.warn("Warning: FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.");
|
|
36
|
+
}
|
|
36
37
|
const route = createRoute(options);
|
|
37
38
|
route.isRoot = false;
|
|
38
39
|
return route;
|
|
@@ -45,7 +46,7 @@ var FileRoute = class {
|
|
|
45
46
|
Instead, place the loader function in the main route file via `createFileRoute`.
|
|
46
47
|
*/
|
|
47
48
|
function FileRouteLoader(_path) {
|
|
48
|
-
if (process.env.NODE_ENV !== "production")
|
|
49
|
+
if (process.env.NODE_ENV !== "production") console.warn(`Warning: FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`);
|
|
49
50
|
return (loaderFn) => loaderFn;
|
|
50
51
|
}
|
|
51
52
|
var LazyRoute = class {
|
|
@@ -93,7 +94,6 @@ var LazyRoute = class {
|
|
|
93
94
|
return useNavigate({ from: useRouter().routesById[this.options.id].fullPath });
|
|
94
95
|
};
|
|
95
96
|
this.options = opts;
|
|
96
|
-
this.$$typeof = Symbol.for("react.memo");
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileRoute.js","names":[],"sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\n\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport { useRouter } from './useRouter'\nimport { useRouteContext } from './useRouteContext'\nimport type { UseParamsRoute } from './useParams'\nimport type { UseMatchRoute } from './useMatch'\nimport type { UseSearchRoute } from './useSearch'\nimport type {\n AnyContext,\n AnyRoute,\n AnyRouter,\n Constrain,\n ConstrainLiteral,\n FileBaseRouteOptions,\n FileRoutesByPath,\n LazyRouteOptions,\n Register,\n RegisteredRouter,\n ResolveParams,\n Route,\n RouteById,\n RouteConstraints,\n RouteIds,\n RouteLoaderEntry,\n UpdatableRouteOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { UseLoaderDepsRoute } from './useLoaderDeps'\nimport type { UseLoaderDataRoute } from './useLoaderData'\nimport type { UseRouteContextRoute } from './useRouteContext'\n\n/**\n * Creates a file-based Route factory for a given path.\n *\n * Used by TanStack Router's file-based routing to associate a file with a\n * route. The returned function accepts standard route options. In normal usage\n * the `path` string is inserted and maintained by the `tsr` generator.\n *\n * @param path File path literal for the route (usually auto-generated).\n * @returns A function that accepts Route options and returns a Route instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction\n */\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends RouteConstraints['TFullPath'] =\n FileRoutesByPath[TFilePath]['fullPath'],\n>(\n path?: TFilePath,\n): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {\n if (typeof path === 'object') {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute(path) as any\n }\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends RouteConstraints['TFullPath'] =\n FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path?: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TRegister = Register,\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n TSSR = unknown,\n const TMiddlewares = unknown,\n THandlers = undefined,\n >(\n options?: FileBaseRouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n AnyContext,\n TSSR,\n TMiddlewares,\n THandlers\n > &\n UpdatableRouteOptions<\n TParentRoute,\n TId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n unknown,\n TSSR,\n TMiddlewares,\n THandlers\n > => {\n if (process.env.NODE_ENV !== 'production') {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n }\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/**\n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the main route file via `createFileRoute`.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderFn>(\n loaderFn: Constrain<\n TLoaderFn,\n RouteLoaderEntry<\n Register,\n TRoute['parentRoute'],\n TRoute['types']['id'],\n TRoute['types']['params'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['routerContext'],\n TRoute['types']['routeContextFn'],\n TRoute['types']['beforeLoadFn']\n >\n >,\n) => TLoaderFn {\n if (process.env.NODE_ENV !== 'production') {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n }\n return (loaderFn) => loaderFn as any\n}\n\ndeclare module '@tanstack/router-core' {\n export interface LazyRoute<in out TRoute extends AnyRoute> {\n useMatch: UseMatchRoute<TRoute['id']>\n useRouteContext: UseRouteContextRoute<TRoute['id']>\n useSearch: UseSearchRoute<TRoute['id']>\n useParams: UseParamsRoute<TRoute['id']>\n useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>\n useLoaderData: UseLoaderDataRoute<TRoute['id']>\n useNavigate: () => UseNavigateResult<TRoute['fullPath']>\n }\n}\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch: UseMatchRoute<TRoute['id']> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.options.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TRoute['id']> = (opts) => {\n return useRouteContext({ ...(opts as any), from: this.options.id })\n }\n\n useSearch: UseSearchRoute<TRoute['id']> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.options.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TRoute['id']> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.options.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TRoute['id']> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TRoute['id']> = (opts) => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {\n const router = useRouter()\n return useNavigate({ from: router.routesById[this.options.id].fullPath })\n }\n}\n\n/**\n * Creates a lazily-configurable code-based route stub by ID.\n *\n * Use this for code-splitting with code-based routes. The returned function\n * accepts only non-critical route options like `component`, `pendingComponent`,\n * `errorComponent`, and `notFoundComponent` which are applied when the route\n * is matched.\n *\n * @param id Route ID string literal to associate with the lazy route.\n * @returns A function that accepts lazy route options and returns a `LazyRoute`.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction\n */\nexport function createLazyRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n TId extends string = string,\n TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,\n>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({\n id: id,\n ...opts,\n })\n }\n}\n\n/**\n * Creates a lazily-configurable file-based route stub by file path.\n *\n * Use this for code-splitting with file-based routes (eg. `.lazy.tsx` files).\n * The returned function accepts only non-critical route options like\n * `component`, `pendingComponent`, `errorComponent`, and `notFoundComponent`.\n *\n * @param id File path literal for the route file.\n * @returns A function that accepts lazy route options and returns a `LazyRoute`.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyFileRouteFunction\n */\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute> {\n if (typeof id === 'object') {\n return new LazyRoute<TRoute>(id) as any\n }\n\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,gBAQd,MAC0E;AAC1E,KAAI,OAAO,SAAS,SAClB,QAAO,IAAI,UAA0D,MAAM,EACzE,QAAQ,MACT,CAAC,CAAC,YAAY,KAAK;AAEtB,QAAO,IAAI,UAA0D,MAAM,EACzE,QAAQ,MACT,CAAC,CAAC;;;;;;AAOL,IAAa,YAAb,MAOE;C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BAGd,IAA8D;AAC9D,KAAI,OAAO,OAAO,SAChB,QAAO,IAAI,UAAkB,GAAG;AAGlC,SAAQ,SAA2B,IAAI,UAAkB;EAAE;EAAI,GAAG;EAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"fileRoute.js","names":[],"sources":["../../src/fileRoute.ts"],"sourcesContent":["import { createRoute } from './route'\n\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport { useRouter } from './useRouter'\nimport { useRouteContext } from './useRouteContext'\nimport type { UseParamsRoute } from './useParams'\nimport type { UseMatchRoute } from './useMatch'\nimport type { UseSearchRoute } from './useSearch'\nimport type {\n AnyContext,\n AnyRoute,\n AnyRouter,\n Constrain,\n ConstrainLiteral,\n FileBaseRouteOptions,\n FileRoutesByPath,\n LazyRouteOptions,\n Register,\n RegisteredRouter,\n ResolveParams,\n Route,\n RouteById,\n RouteConstraints,\n RouteIds,\n RouteLoaderEntry,\n UpdatableRouteOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { UseLoaderDepsRoute } from './useLoaderDeps'\nimport type { UseLoaderDataRoute } from './useLoaderData'\nimport type { UseRouteContextRoute } from './useRouteContext'\n\n/**\n * Creates a file-based Route factory for a given path.\n *\n * Used by TanStack Router's file-based routing to associate a file with a\n * route. The returned function accepts standard route options. In normal usage\n * the `path` string is inserted and maintained by the `tsr` generator.\n *\n * @param path File path literal for the route (usually auto-generated).\n * @returns A function that accepts Route options and returns a Route instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction\n */\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends RouteConstraints['TFullPath'] =\n FileRoutesByPath[TFilePath]['fullPath'],\n>(\n path?: TFilePath,\n): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {\n if (typeof path === 'object') {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute(path) as any\n }\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends RouteConstraints['TFullPath'] =\n FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path?: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TRegister = Register,\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n TSSR = unknown,\n const TMiddlewares = unknown,\n THandlers = undefined,\n >(\n options?: FileBaseRouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n AnyContext,\n TSSR,\n TMiddlewares,\n THandlers\n > &\n UpdatableRouteOptions<\n TParentRoute,\n TId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n unknown,\n TSSR,\n TMiddlewares,\n THandlers\n > => {\n if (process.env.NODE_ENV !== 'production') {\n if (!this.silent) {\n console.warn(\n 'Warning: FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n }\n }\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/**\n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the main route file via `createFileRoute`.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderFn>(\n loaderFn: Constrain<\n TLoaderFn,\n RouteLoaderEntry<\n Register,\n TRoute['parentRoute'],\n TRoute['types']['id'],\n TRoute['types']['params'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['routerContext'],\n TRoute['types']['routeContextFn'],\n TRoute['types']['beforeLoadFn']\n >\n >,\n) => TLoaderFn {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `Warning: FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n }\n return (loaderFn) => loaderFn as any\n}\n\ndeclare module '@tanstack/router-core' {\n export interface LazyRoute<in out TRoute extends AnyRoute> {\n useMatch: UseMatchRoute<TRoute['id']>\n useRouteContext: UseRouteContextRoute<TRoute['id']>\n useSearch: UseSearchRoute<TRoute['id']>\n useParams: UseParamsRoute<TRoute['id']>\n useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>\n useLoaderData: UseLoaderDataRoute<TRoute['id']>\n useNavigate: () => UseNavigateResult<TRoute['fullPath']>\n }\n}\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n }\n\n useMatch: UseMatchRoute<TRoute['id']> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.options.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TRoute['id']> = (opts) => {\n return useRouteContext({ ...(opts as any), from: this.options.id })\n }\n\n useSearch: UseSearchRoute<TRoute['id']> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.options.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TRoute['id']> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.options.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TRoute['id']> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TRoute['id']> = (opts) => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {\n const router = useRouter()\n return useNavigate({ from: router.routesById[this.options.id].fullPath })\n }\n}\n\n/**\n * Creates a lazily-configurable code-based route stub by ID.\n *\n * Use this for code-splitting with code-based routes. The returned function\n * accepts only non-critical route options like `component`, `pendingComponent`,\n * `errorComponent`, and `notFoundComponent` which are applied when the route\n * is matched.\n *\n * @param id Route ID string literal to associate with the lazy route.\n * @returns A function that accepts lazy route options and returns a `LazyRoute`.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction\n */\nexport function createLazyRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n TId extends string = string,\n TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,\n>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({\n id: id,\n ...opts,\n })\n }\n}\n\n/**\n * Creates a lazily-configurable file-based route stub by file path.\n *\n * Use this for code-splitting with file-based routes (eg. `.lazy.tsx` files).\n * The returned function accepts only non-critical route options like\n * `component`, `pendingComponent`, `errorComponent`, and `notFoundComponent`.\n *\n * @param id File path literal for the route file.\n * @returns A function that accepts lazy route options and returns a `LazyRoute`.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyFileRouteFunction\n */\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute> {\n if (typeof id === 'object') {\n return new LazyRoute<TRoute>(id) as any\n }\n\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,gBAQd,MAC0E;AAC1E,KAAI,OAAO,SAAS,SAClB,QAAO,IAAI,UAA0D,MAAM,EACzE,QAAQ,MACT,CAAC,CAAC,YAAY,KAAK;AAEtB,QAAO,IAAI,UAA0D,MAAM,EACzE,QAAQ,MACT,CAAC,CAAC;;;;;;AAOL,IAAa,YAAb,MAOE;CAGA,YACE,MACA,OACA;AAFO,OAAA,OAAA;sBAmBP,YAgDG;AACH,OAAA,QAAA,IAAA,aAA6B;QACvB,CAAC,KAAK,OACR,SAAQ,KACN,2IACD;;GAGL,MAAM,QAAQ,YAAY,QAAe;AACvC,SAAc,SAAS;AACzB,UAAO;;AA1EP,OAAK,SAAS,OAAO;;;;;;;AAkFzB,SAAgB,gBAId,OAea;AACb,KAAA,QAAA,IAAA,aAA6B,aAC3B,SAAQ,KACN,sNACD;AAEH,SAAQ,aAAa;;AAevB,IAAa,YAAb,MAAgD;CAK9C,YACE,MAGA;mBAIuC,SAAS;AAChD,UAAO,SAAS;IACd,QAAQ,MAAM;IACd,MAAM,KAAK,QAAQ;IACnB,mBAAmB,MAAM;IAC1B,CAAQ;;0BAG4C,SAAS;AAC9D,UAAO,gBAAgB;IAAE,GAAI;IAAc,MAAM,KAAK,QAAQ;IAAI,CAAC;;oBAG1B,SAAS;AAElD,UAAO,UAAU;IACf,QAAQ,MAAM;IACd,mBAAmB,MAAM;IACzB,MAAM,KAAK,QAAQ;IACpB,CAAQ;;oBAGgC,SAAS;AAElD,UAAO,UAAU;IACf,QAAQ,MAAM;IACd,mBAAmB,MAAM;IACzB,MAAM,KAAK,QAAQ;IACpB,CAAQ;;wBAGwC,SAAS;AAC1D,UAAO,cAAc;IAAE,GAAG;IAAM,MAAM,KAAK,QAAQ;IAAI,CAAQ;;wBAGd,SAAS;AAC1D,UAAO,cAAc;IAAE,GAAG;IAAM,MAAM,KAAK,QAAQ;IAAI,CAAQ;;2BAGN;AAEzD,UAAO,YAAY,EAAE,MADN,WAAW,CACQ,WAAW,KAAK,QAAQ,IAAI,UAAU,CAAC;;AA3CzE,OAAK,UAAU;;;;;;;;;;;;;;;AA2DnB,SAAgB,gBAId,IAA2D;AAC3D,SAAQ,SAA2B;AACjC,SAAO,IAAI,UAAkB;GACvB;GACJ,GAAG;GACJ,CAAC;;;;;;;;;;;;;;AAeN,SAAgB,oBAGd,IAA8D;AAC9D,KAAI,OAAO,OAAO,SAChB,QAAO,IAAI,UAAkB,GAAG;AAGlC,SAAQ,SAA2B,IAAI,UAAkB;EAAE;EAAI,GAAG;EAAM,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DefaultGlobalNotFound } from "./not-found.js";
|
|
2
2
|
import "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import warning from "tiny-warning";
|
|
5
4
|
//#region src/renderRouteNotFound.tsx
|
|
6
5
|
/**
|
|
7
6
|
* Renders a not found component for a route when no matching route is found.
|
|
@@ -14,7 +13,9 @@ import warning from "tiny-warning";
|
|
|
14
13
|
function renderRouteNotFound(router, route, data) {
|
|
15
14
|
if (!route.options.notFoundComponent) {
|
|
16
15
|
if (router.options.defaultNotFoundComponent) return /* @__PURE__ */ jsx(router.options.defaultNotFoundComponent, { ...data });
|
|
17
|
-
if (process.env.NODE_ENV
|
|
16
|
+
if (process.env.NODE_ENV !== "production") {
|
|
17
|
+
if (!route.options.notFoundComponent) console.warn(`Warning: A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`);
|
|
18
|
+
}
|
|
18
19
|
return /* @__PURE__ */ jsx(DefaultGlobalNotFound, {});
|
|
19
20
|
}
|
|
20
21
|
return /* @__PURE__ */ jsx(route.options.notFoundComponent, { ...data });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouteNotFound.js","names":[],"sources":["../../src/renderRouteNotFound.tsx"],"sourcesContent":["import * as React from 'react'\nimport
|
|
1
|
+
{"version":3,"file":"renderRouteNotFound.js","names":[],"sources":["../../src/renderRouteNotFound.tsx"],"sourcesContent":["import * as React from 'react'\nimport { DefaultGlobalNotFound } from './not-found'\nimport type { AnyRoute, AnyRouter } from '@tanstack/router-core'\n\n/**\n * Renders a not found component for a route when no matching route is found.\n *\n * @param router - The router instance containing the route configuration\n * @param route - The route that triggered the not found state\n * @param data - Additional data to pass to the not found component\n * @returns The rendered not found component or a default fallback component\n */\nexport function renderRouteNotFound(\n router: AnyRouter,\n route: AnyRoute,\n data: any,\n) {\n if (!route.options.notFoundComponent) {\n if (router.options.defaultNotFoundComponent) {\n return <router.options.defaultNotFoundComponent {...data} />\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!route.options.notFoundComponent) {\n console.warn(\n `Warning: A notFoundError was encountered on the route with ID \"${route.id}\", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,\n )\n }\n }\n\n return <DefaultGlobalNotFound />\n }\n\n return <route.options.notFoundComponent {...data} />\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,oBACd,QACA,OACA,MACA;AACA,KAAI,CAAC,MAAM,QAAQ,mBAAmB;AACpC,MAAI,OAAO,QAAQ,yBACjB,QAAO,oBAAC,OAAO,QAAQ,0BAAhB,EAAyC,GAAI,MAAQ,CAAA;AAG9D,MAAA,QAAA,IAAA,aAA6B;OACvB,CAAC,MAAM,QAAQ,kBACjB,SAAQ,KACN,kEAAkE,MAAM,GAAG,oPAC5E;;AAIL,SAAO,oBAAC,uBAAD,EAAyB,CAAA;;AAGlC,QAAO,oBAAC,MAAM,QAAQ,mBAAf,EAAiC,GAAI,MAAQ,CAAA"}
|
package/dist/esm/route.js
CHANGED
|
@@ -144,7 +144,6 @@ var Route = class extends BaseRoute {
|
|
|
144
144
|
...props
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
-
this.$$typeof = Symbol.for("react.memo");
|
|
148
147
|
}
|
|
149
148
|
};
|
|
150
149
|
/**
|
|
@@ -234,7 +233,6 @@ var RootRoute = class extends BaseRootRoute {
|
|
|
234
233
|
...props
|
|
235
234
|
});
|
|
236
235
|
});
|
|
237
|
-
this.$$typeof = Symbol.for("react.memo");
|
|
238
236
|
}
|
|
239
237
|
};
|
|
240
238
|
/**
|