@tanstack/solid-router 2.0.0-alpha.6 → 2.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/dist/cjs/Asset.cjs +2 -2
  2. package/dist/cjs/Asset.cjs.map +1 -1
  3. package/dist/cjs/HeadContent.cjs +11 -1
  4. package/dist/cjs/HeadContent.cjs.map +1 -1
  5. package/dist/cjs/HeadContent.dev.cjs +11 -1
  6. package/dist/cjs/HeadContent.dev.cjs.map +1 -1
  7. package/dist/cjs/Match.cjs +265 -248
  8. package/dist/cjs/Match.cjs.map +1 -1
  9. package/dist/cjs/Match.d.cts +1 -3
  10. package/dist/cjs/Matches.cjs +35 -34
  11. package/dist/cjs/Matches.cjs.map +1 -1
  12. package/dist/cjs/RouterProvider.cjs +12 -8
  13. package/dist/cjs/RouterProvider.cjs.map +1 -1
  14. package/dist/cjs/RouterProvider.d.cts +1 -1
  15. package/dist/cjs/Scripts.cjs +23 -12
  16. package/dist/cjs/Scripts.cjs.map +1 -1
  17. package/dist/cjs/Scripts.d.cts +2 -1
  18. package/dist/cjs/Transitioner.cjs +55 -34
  19. package/dist/cjs/Transitioner.cjs.map +1 -1
  20. package/dist/cjs/headContentUtils.cjs +26 -23
  21. package/dist/cjs/headContentUtils.cjs.map +1 -1
  22. package/dist/cjs/headContentUtils.d.cts +2 -1
  23. package/dist/cjs/index.cjs +1 -1
  24. package/dist/cjs/index.dev.cjs +1 -1
  25. package/dist/cjs/link.cjs +143 -101
  26. package/dist/cjs/link.cjs.map +1 -1
  27. package/dist/cjs/matchContext.cjs +7 -5
  28. package/dist/cjs/matchContext.cjs.map +1 -1
  29. package/dist/cjs/matchContext.d.cts +8 -2
  30. package/dist/cjs/not-found.cjs +8 -4
  31. package/dist/cjs/not-found.cjs.map +1 -1
  32. package/dist/cjs/not-found.d.cts +1 -1
  33. package/dist/cjs/router.cjs +2 -1
  34. package/dist/cjs/router.cjs.map +1 -1
  35. package/dist/cjs/routerStores.cjs +75 -0
  36. package/dist/cjs/routerStores.cjs.map +1 -0
  37. package/dist/cjs/routerStores.d.cts +10 -0
  38. package/dist/cjs/ssr/RouterClient.cjs +1 -1
  39. package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
  40. package/dist/cjs/ssr/renderRouterToStream.cjs +1 -1
  41. package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
  42. package/dist/cjs/ssr/renderRouterToString.cjs +1 -1
  43. package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
  44. package/dist/cjs/useBlocker.cjs +12 -3
  45. package/dist/cjs/useBlocker.cjs.map +1 -1
  46. package/dist/cjs/useCanGoBack.cjs +6 -2
  47. package/dist/cjs/useCanGoBack.cjs.map +1 -1
  48. package/dist/cjs/useCanGoBack.d.cts +2 -1
  49. package/dist/cjs/useLoaderDeps.cjs +2 -3
  50. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  51. package/dist/cjs/useLocation.cjs +13 -2
  52. package/dist/cjs/useLocation.cjs.map +1 -1
  53. package/dist/cjs/useMatch.cjs +27 -15
  54. package/dist/cjs/useMatch.cjs.map +1 -1
  55. package/dist/cjs/useParams.cjs +1 -1
  56. package/dist/cjs/useParams.cjs.map +1 -1
  57. package/dist/cjs/useRouterState.cjs +12 -30
  58. package/dist/cjs/useRouterState.cjs.map +1 -1
  59. package/dist/cjs/useSearch.cjs +2 -1
  60. package/dist/cjs/useSearch.cjs.map +1 -1
  61. package/dist/cjs/utils.cjs +3 -17
  62. package/dist/cjs/utils.cjs.map +1 -1
  63. package/dist/cjs/utils.d.cts +0 -5
  64. package/dist/esm/Asset.js +6 -6
  65. package/dist/esm/Asset.js.map +1 -1
  66. package/dist/esm/HeadContent.dev.js +12 -2
  67. package/dist/esm/HeadContent.dev.js.map +1 -1
  68. package/dist/esm/HeadContent.js +12 -2
  69. package/dist/esm/HeadContent.js.map +1 -1
  70. package/dist/esm/Match.d.ts +1 -3
  71. package/dist/esm/Match.js +267 -250
  72. package/dist/esm/Match.js.map +1 -1
  73. package/dist/esm/Matches.js +40 -39
  74. package/dist/esm/Matches.js.map +1 -1
  75. package/dist/esm/RouterProvider.d.ts +1 -1
  76. package/dist/esm/RouterProvider.js +10 -7
  77. package/dist/esm/RouterProvider.js.map +1 -1
  78. package/dist/esm/ScriptOnce.js +2 -2
  79. package/dist/esm/ScriptOnce.js.map +1 -1
  80. package/dist/esm/Scripts.d.ts +2 -1
  81. package/dist/esm/Scripts.js +21 -11
  82. package/dist/esm/Scripts.js.map +1 -1
  83. package/dist/esm/Transitioner.js +56 -35
  84. package/dist/esm/Transitioner.js.map +1 -1
  85. package/dist/esm/headContentUtils.d.ts +2 -1
  86. package/dist/esm/headContentUtils.js +26 -23
  87. package/dist/esm/headContentUtils.js.map +1 -1
  88. package/dist/esm/index.dev.js +1 -1
  89. package/dist/esm/index.js +1 -1
  90. package/dist/esm/link.js +146 -104
  91. package/dist/esm/link.js.map +1 -1
  92. package/dist/esm/matchContext.d.ts +8 -2
  93. package/dist/esm/matchContext.js +7 -4
  94. package/dist/esm/matchContext.js.map +1 -1
  95. package/dist/esm/not-found.d.ts +1 -1
  96. package/dist/esm/not-found.js +6 -3
  97. package/dist/esm/not-found.js.map +1 -1
  98. package/dist/esm/router.js +2 -1
  99. package/dist/esm/router.js.map +1 -1
  100. package/dist/esm/routerStores.d.ts +10 -0
  101. package/dist/esm/routerStores.js +73 -0
  102. package/dist/esm/routerStores.js.map +1 -0
  103. package/dist/esm/scroll-restoration.js +2 -2
  104. package/dist/esm/scroll-restoration.js.map +1 -1
  105. package/dist/esm/ssr/RouterClient.js +1 -1
  106. package/dist/esm/ssr/RouterClient.js.map +1 -1
  107. package/dist/esm/ssr/renderRouterToStream.js +1 -1
  108. package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
  109. package/dist/esm/ssr/renderRouterToString.js +1 -1
  110. package/dist/esm/ssr/renderRouterToString.js.map +1 -1
  111. package/dist/esm/useBlocker.js +12 -3
  112. package/dist/esm/useBlocker.js.map +1 -1
  113. package/dist/esm/useCanGoBack.d.ts +2 -1
  114. package/dist/esm/useCanGoBack.js +4 -2
  115. package/dist/esm/useCanGoBack.js.map +1 -1
  116. package/dist/esm/useLoaderDeps.js +2 -3
  117. package/dist/esm/useLoaderDeps.js.map +1 -1
  118. package/dist/esm/useLocation.js +11 -2
  119. package/dist/esm/useLocation.js.map +1 -1
  120. package/dist/esm/useMatch.js +28 -16
  121. package/dist/esm/useMatch.js.map +1 -1
  122. package/dist/esm/useParams.js +1 -1
  123. package/dist/esm/useParams.js.map +1 -1
  124. package/dist/esm/useRouterState.js +11 -30
  125. package/dist/esm/useRouterState.js.map +1 -1
  126. package/dist/esm/useSearch.js +2 -1
  127. package/dist/esm/useSearch.js.map +1 -1
  128. package/dist/esm/utils.d.ts +0 -5
  129. package/dist/esm/utils.js +4 -17
  130. package/dist/esm/utils.js.map +1 -1
  131. package/dist/source/Asset.jsx +3 -3
  132. package/dist/source/Asset.jsx.map +1 -1
  133. package/dist/source/HeadContent.dev.jsx +5 -1
  134. package/dist/source/HeadContent.dev.jsx.map +1 -1
  135. package/dist/source/HeadContent.jsx +5 -1
  136. package/dist/source/HeadContent.jsx.map +1 -1
  137. package/dist/source/Match.d.ts +1 -3
  138. package/dist/source/Match.jsx +260 -264
  139. package/dist/source/Match.jsx.map +1 -1
  140. package/dist/source/Matches.jsx +46 -46
  141. package/dist/source/Matches.jsx.map +1 -1
  142. package/dist/source/RouterProvider.d.ts +1 -1
  143. package/dist/source/RouterProvider.jsx +13 -9
  144. package/dist/source/RouterProvider.jsx.map +1 -1
  145. package/dist/source/Scripts.d.ts +2 -1
  146. package/dist/source/Scripts.jsx +46 -47
  147. package/dist/source/Scripts.jsx.map +1 -1
  148. package/dist/source/Transitioner.jsx +78 -42
  149. package/dist/source/Transitioner.jsx.map +1 -1
  150. package/dist/source/headContentUtils.d.ts +2 -1
  151. package/dist/source/headContentUtils.jsx +79 -80
  152. package/dist/source/headContentUtils.jsx.map +1 -1
  153. package/dist/source/link.jsx +145 -112
  154. package/dist/source/link.jsx.map +1 -1
  155. package/dist/source/matchContext.d.ts +8 -2
  156. package/dist/source/matchContext.jsx +7 -3
  157. package/dist/source/matchContext.jsx.map +1 -1
  158. package/dist/source/not-found.d.ts +1 -1
  159. package/dist/source/not-found.jsx +6 -5
  160. package/dist/source/not-found.jsx.map +1 -1
  161. package/dist/source/router.js +2 -1
  162. package/dist/source/router.js.map +1 -1
  163. package/dist/source/routerStores.d.ts +10 -0
  164. package/dist/source/routerStores.js +82 -0
  165. package/dist/source/routerStores.js.map +1 -0
  166. package/dist/source/ssr/RouterClient.jsx +1 -1
  167. package/dist/source/ssr/RouterClient.jsx.map +1 -1
  168. package/dist/source/ssr/renderRouterToStream.jsx +1 -1
  169. package/dist/source/ssr/renderRouterToStream.jsx.map +1 -1
  170. package/dist/source/ssr/renderRouterToString.jsx +1 -1
  171. package/dist/source/ssr/renderRouterToString.jsx.map +1 -1
  172. package/dist/source/useBlocker.jsx +19 -8
  173. package/dist/source/useBlocker.jsx.map +1 -1
  174. package/dist/source/useCanGoBack.d.ts +2 -1
  175. package/dist/source/useCanGoBack.js +4 -2
  176. package/dist/source/useCanGoBack.js.map +1 -1
  177. package/dist/source/useLoaderDeps.jsx +2 -3
  178. package/dist/source/useLoaderDeps.jsx.map +1 -1
  179. package/dist/source/useLocation.jsx +13 -3
  180. package/dist/source/useLocation.jsx.map +1 -1
  181. package/dist/source/useMatch.jsx +33 -23
  182. package/dist/source/useMatch.jsx.map +1 -1
  183. package/dist/source/useParams.jsx +1 -1
  184. package/dist/source/useParams.jsx.map +1 -1
  185. package/dist/source/useRouterState.jsx +14 -55
  186. package/dist/source/useRouterState.jsx.map +1 -1
  187. package/dist/source/useSearch.jsx +2 -1
  188. package/dist/source/useSearch.jsx.map +1 -1
  189. package/dist/source/utils.d.ts +0 -5
  190. package/dist/source/utils.js +2 -15
  191. package/dist/source/utils.js.map +1 -1
  192. package/package.json +2 -2
  193. package/skills/solid-router/SKILL.md +2 -0
  194. package/src/Asset.tsx +3 -3
  195. package/src/HeadContent.dev.tsx +10 -1
  196. package/src/HeadContent.tsx +10 -1
  197. package/src/Match.tsx +395 -349
  198. package/src/Matches.tsx +55 -54
  199. package/src/RouterProvider.tsx +13 -10
  200. package/src/Scripts.tsx +55 -54
  201. package/src/Transitioner.tsx +101 -58
  202. package/src/headContentUtils.tsx +104 -96
  203. package/src/link.tsx +188 -146
  204. package/src/matchContext.tsx +16 -7
  205. package/src/not-found.tsx +6 -6
  206. package/src/router.ts +2 -1
  207. package/src/routerStores.ts +119 -0
  208. package/src/ssr/RouterClient.tsx +1 -1
  209. package/src/ssr/renderRouterToStream.tsx +1 -1
  210. package/src/ssr/renderRouterToString.tsx +1 -1
  211. package/src/useBlocker.tsx +80 -63
  212. package/src/useCanGoBack.ts +6 -2
  213. package/src/useLoaderDeps.tsx +2 -3
  214. package/src/useLocation.tsx +18 -5
  215. package/src/useMatch.tsx +37 -38
  216. package/src/useParams.tsx +2 -3
  217. package/src/useRouterState.tsx +21 -67
  218. package/src/useSearch.tsx +2 -1
  219. package/src/utils.ts +2 -24
package/dist/esm/Match.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
2
2
  import { useRouter } from "./useRouter.js";
3
- import { useRouterState } from "./useRouterState.js";
4
- import { matchContext } from "./matchContext.js";
3
+ import { nearestMatchContext } from "./matchContext.js";
5
4
  import { SafeFragment } from "./SafeFragment.js";
6
5
  import { CatchNotFound } from "./not-found.js";
7
6
  import { renderRouteNotFound } from "./renderRouteNotFound.js";
@@ -10,309 +9,329 @@ import { createControlledPromise, getLocationChangeInfo, isNotFound, isRedirect,
10
9
  import { Dynamic, createComponent, memo, mergeProps } from "@solidjs/web";
11
10
  import * as Solid from "solid-js";
12
11
  import warning from "tiny-warning";
13
- import { isServer } from "@tanstack/router-core/isServer";
12
+ import { isServer as isServer$1 } from "@tanstack/router-core/isServer";
14
13
  import invariant from "tiny-invariant";
15
14
  //#region src/Match.tsx
16
- var MatchContext = matchContext;
15
+ var NearestMatchContext = nearestMatchContext;
17
16
  var Match = (props) => {
18
17
  const router = useRouter();
19
- const matchState = useRouterState({ select: (s) => {
20
- const match = s.matches.find((d) => d.id === props.matchId);
21
- if (!match) return null;
18
+ const match = Solid.createMemo(() => {
19
+ const id = props.matchId;
20
+ if (!id) return void 0;
21
+ return router.stores.activeMatchStoresById.get(id)?.state;
22
+ });
23
+ const rawMatchState = Solid.createMemo(() => {
24
+ const currentMatch = match();
25
+ if (!currentMatch) return null;
26
+ const routeId = currentMatch.routeId;
27
+ const parentRouteId = router.routesById[routeId]?.parentRoute?.id;
22
28
  return {
23
- routeId: match.routeId,
24
- ssr: match.ssr,
25
- _displayPending: match._displayPending
29
+ matchId: currentMatch.id,
30
+ routeId,
31
+ ssr: currentMatch.ssr,
32
+ _displayPending: currentMatch._displayPending,
33
+ parentRouteId
26
34
  };
27
- } });
28
- if (!Solid.untrack(matchState)) return null;
29
- const route = () => router.routesById[matchState().routeId];
30
- const resolvePendingComponent = () => route().options.pendingComponent ?? router.options.defaultPendingComponent;
31
- const routeErrorComponent = () => route().options.errorComponent ?? router.options.defaultErrorComponent;
32
- const routeOnCatch = () => route().options.onCatch ?? router.options.defaultOnCatch;
33
- const routeNotFoundComponent = () => route().isRoot ? route().options.notFoundComponent ?? router.options.notFoundRoute?.options.component : route().options.notFoundComponent;
34
- const resolvedNoSsr = Solid.createMemo(() => matchState().ssr === false || matchState().ssr === "data-only");
35
- const ResolvedSuspenseBoundary = () => resolvedNoSsr() ? SafeFragment : Solid.Loading;
36
- const ResolvedCatchBoundary = () => routeErrorComponent() ? CatchBoundary : SafeFragment;
37
- const ResolvedNotFoundBoundary = () => routeNotFoundComponent() ? CatchNotFound : SafeFragment;
38
- const resetKey = useRouterState({ select: (s) => s.loadedAt });
39
- const parentRouteId = useRouterState({ select: (s) => {
40
- const index = s.matches.findIndex((d) => d.id === props.matchId);
41
- return s.matches[index - 1]?.routeId;
42
- } });
43
- const ShellComponent = Solid.createMemo(() => route().isRoot ? route().options.shellComponent ?? SafeFragment : SafeFragment);
44
- return createComponent(Dynamic, {
45
- get component() {
46
- return ShellComponent();
35
+ });
36
+ const nearestMatch = {
37
+ matchId: () => rawMatchState()?.matchId,
38
+ routeId: () => rawMatchState()?.routeId,
39
+ match,
40
+ hasPending: Solid.createMemo(() => {
41
+ const currentRouteId = rawMatchState()?.routeId;
42
+ return currentRouteId ? Boolean(router.stores.pendingRouteIds.state[currentRouteId]) : false;
43
+ })
44
+ };
45
+ return createComponent(Solid.Show, {
46
+ get when() {
47
+ return rawMatchState();
47
48
  },
48
- get children() {
49
- return [createComponent(MatchContext, {
50
- value: () => props.matchId,
49
+ children: (currentMatchState) => {
50
+ const route = Solid.createMemo(() => router.routesById[currentMatchState().routeId]);
51
+ const resolvePendingComponent = Solid.createMemo(() => route().options.pendingComponent ?? router.options.defaultPendingComponent);
52
+ const routeErrorComponent = Solid.createMemo(() => route().options.errorComponent ?? router.options.defaultErrorComponent);
53
+ const routeOnCatch = Solid.createMemo(() => route().options.onCatch ?? router.options.defaultOnCatch);
54
+ const routeNotFoundComponent = Solid.createMemo(() => route().isRoot ? route().options.notFoundComponent ?? router.options.notFoundRoute?.options.component : route().options.notFoundComponent);
55
+ const resolvedNoSsr = Solid.createMemo(() => currentMatchState().ssr === false || currentMatchState().ssr === "data-only");
56
+ const ResolvedSuspenseBoundary = Solid.createMemo(() => resolvedNoSsr() ? SafeFragment : Solid.Loading);
57
+ const ResolvedCatchBoundary = Solid.createMemo(() => routeErrorComponent() ? CatchBoundary : SafeFragment);
58
+ const ResolvedNotFoundBoundary = Solid.createMemo(() => routeNotFoundComponent() ? CatchNotFound : SafeFragment);
59
+ const ShellComponent = Solid.createMemo(() => route().isRoot ? route().options.shellComponent ?? SafeFragment : SafeFragment);
60
+ return createComponent(Dynamic, {
61
+ get component() {
62
+ return ShellComponent();
63
+ },
51
64
  get children() {
52
- return createComponent(Dynamic, {
53
- get component() {
54
- return ResolvedSuspenseBoundary();
55
- },
56
- get fallback() {
57
- return memo(() => !!((isServer ?? router.isServer) || resolvedNoSsr()))() ? void 0 : createComponent(Dynamic, { get component() {
58
- return resolvePendingComponent();
59
- } });
60
- },
65
+ return [createComponent(NearestMatchContext, {
66
+ value: nearestMatch,
61
67
  get children() {
62
68
  return createComponent(Dynamic, {
63
69
  get component() {
64
- return ResolvedCatchBoundary();
70
+ return ResolvedSuspenseBoundary();
65
71
  },
66
- getResetKey: () => resetKey(),
67
- get errorComponent() {
68
- return routeErrorComponent() || ErrorComponent;
69
- },
70
- onCatch: (error) => {
71
- if (isNotFound(error)) throw error;
72
- warning(false, `Error in route match: ${Solid.untrack(matchState).routeId}`);
73
- routeOnCatch()?.(error);
72
+ get fallback() {
73
+ return memo(() => !!((isServer$1 ?? router.isServer) && resolvedNoSsr()))() ? void 0 : createComponent(Dynamic, { get component() {
74
+ return resolvePendingComponent();
75
+ } });
74
76
  },
75
77
  get children() {
76
78
  return createComponent(Dynamic, {
77
79
  get component() {
78
- return ResolvedNotFoundBoundary();
80
+ return ResolvedCatchBoundary();
81
+ },
82
+ getResetKey: () => router.stores.loadedAt.state,
83
+ get errorComponent() {
84
+ return routeErrorComponent() || ErrorComponent;
79
85
  },
80
- fallback: (error) => {
81
- if (!routeNotFoundComponent() || error.routeId && error.routeId !== matchState().routeId || !error.routeId && !route().isRoot) throw error;
82
- return createComponent(Dynamic, mergeProps({ get component() {
83
- return routeNotFoundComponent();
84
- } }, error));
86
+ onCatch: (error) => {
87
+ if (isNotFound(error)) throw error;
88
+ warning(false, `Error in route match: ${currentMatchState().routeId}`);
89
+ routeOnCatch()?.(error);
85
90
  },
86
91
  get children() {
87
- return createComponent(Solid.Switch, { get children() {
88
- return [createComponent(Solid.Match, {
89
- get when() {
90
- return resolvedNoSsr();
91
- },
92
- get children() {
93
- return createComponent(Solid.Show, {
92
+ return createComponent(Dynamic, {
93
+ get component() {
94
+ return ResolvedNotFoundBoundary();
95
+ },
96
+ fallback: (error) => {
97
+ if (!routeNotFoundComponent() || error.routeId && error.routeId !== currentMatchState().routeId || !error.routeId && !route().isRoot) throw error;
98
+ return createComponent(Dynamic, mergeProps({ get component() {
99
+ return routeNotFoundComponent();
100
+ } }, error));
101
+ },
102
+ get children() {
103
+ return createComponent(Solid.Switch, { get children() {
104
+ return [createComponent(Solid.Match, {
94
105
  get when() {
95
- return !(isServer ?? router.isServer);
106
+ return resolvedNoSsr();
96
107
  },
97
- get fallback() {
98
- return createComponent(Dynamic, { get component() {
99
- return resolvePendingComponent();
100
- } });
108
+ get children() {
109
+ return createComponent(Solid.Show, {
110
+ get when() {
111
+ return !(isServer$1 ?? router.isServer);
112
+ },
113
+ get fallback() {
114
+ return createComponent(Dynamic, { get component() {
115
+ return resolvePendingComponent();
116
+ } });
117
+ },
118
+ get children() {
119
+ return createComponent(MatchInner, {});
120
+ }
121
+ });
122
+ }
123
+ }), createComponent(Solid.Match, {
124
+ get when() {
125
+ return !resolvedNoSsr();
101
126
  },
102
127
  get children() {
103
- return createComponent(MatchInner, { get matchId() {
104
- return props.matchId;
105
- } });
128
+ return createComponent(MatchInner, {});
106
129
  }
107
- });
108
- }
109
- }), createComponent(Solid.Match, {
110
- get when() {
111
- return !resolvedNoSsr();
112
- },
113
- get children() {
114
- return createComponent(MatchInner, { get matchId() {
115
- return props.matchId;
116
- } });
117
- }
118
- })];
119
- } });
130
+ })];
131
+ } });
132
+ }
133
+ });
120
134
  }
121
135
  });
122
136
  }
123
137
  });
124
138
  }
125
- });
139
+ }), memo(() => memo(() => currentMatchState().parentRouteId === rootRouteId)() ? [createComponent(OnRendered, {}), createComponent(ScrollRestoration, {})] : null)];
126
140
  }
127
- }), memo(() => memo(() => parentRouteId() === rootRouteId)() ? [createComponent(OnRendered, {}), createComponent(ScrollRestoration, {})] : null)];
141
+ });
128
142
  }
129
143
  });
130
144
  };
131
145
  var lastOnRenderedKey = /* @__PURE__ */ new WeakMap();
132
146
  function OnRendered() {
133
147
  const router = useRouter();
134
- const location = useRouterState({ select: (s) => {
135
- return s.resolvedLocation?.state.__TSR_key;
136
- } });
137
- Solid.createEffect(() => [location()], ([location]) => {
148
+ const location = Solid.createMemo(() => router.stores.resolvedLocation.state?.state.__TSR_key);
149
+ const locationState = Solid.createMemo(() => router.stores.location.state);
150
+ const resolvedLocationState = Solid.createMemo(() => router.stores.resolvedLocation.state);
151
+ Solid.createEffect(() => [
152
+ location(),
153
+ locationState(),
154
+ resolvedLocationState()
155
+ ], ([location, currentLocationState, currentResolvedLocationState]) => {
138
156
  if (!location) return;
139
157
  if (lastOnRenderedKey.get(router) === location) return;
140
158
  lastOnRenderedKey.set(router, location);
141
159
  router.emit({
142
160
  type: "onRendered",
143
- ...getLocationChangeInfo(router.state)
161
+ ...getLocationChangeInfo(currentLocationState, currentResolvedLocationState)
144
162
  });
145
163
  });
146
164
  return null;
147
165
  }
148
- var MatchInner = (props) => {
166
+ var MatchInner = () => {
149
167
  const router = useRouter();
150
- const matchState = useRouterState({ select: (s) => {
151
- const match = s.matches.find((d) => d.id === props.matchId);
152
- if (!match) return null;
153
- const routeId = match.routeId;
168
+ const match = Solid.useContext(nearestMatchContext).match;
169
+ const rawMatchState = Solid.createMemo(() => {
170
+ const currentMatch = match();
171
+ if (!currentMatch) return null;
172
+ const routeId = currentMatch.routeId;
154
173
  const remountDeps = (router.routesById[routeId].options.remountDeps ?? router.options.defaultRemountDeps)?.({
155
174
  routeId,
156
- loaderDeps: match.loaderDeps,
157
- params: match._strictParams,
158
- search: match._strictSearch
175
+ loaderDeps: currentMatch.loaderDeps,
176
+ params: currentMatch._strictParams,
177
+ search: currentMatch._strictSearch
159
178
  });
160
179
  return {
161
180
  key: remountDeps ? JSON.stringify(remountDeps) : void 0,
162
181
  routeId,
163
182
  match: {
164
- id: match.id,
165
- status: match.status,
166
- error: match.error,
167
- _forcePending: match._forcePending,
168
- _displayPending: match._displayPending
183
+ id: currentMatch.id,
184
+ status: currentMatch.status,
185
+ error: currentMatch.error,
186
+ _forcePending: currentMatch._forcePending ?? false,
187
+ _displayPending: currentMatch._displayPending ?? false
169
188
  }
170
189
  };
171
- } });
172
- if (!Solid.untrack(matchState)) return null;
173
- const route = () => router.routesById[matchState().routeId];
174
- const match = () => matchState().match;
175
- const componentKey = () => matchState().key ?? matchState().match.id;
176
- const out = () => {
177
- const Comp = Solid.untrack(route).options.component ?? router.options.defaultComponent;
178
- if (Comp) return createComponent(Comp, {});
179
- return createComponent(Outlet, {});
180
- };
181
- const keyedOut = () => createComponent(Solid.Show, {
190
+ });
191
+ return createComponent(Solid.Show, {
182
192
  get when() {
183
- return componentKey();
193
+ return rawMatchState();
184
194
  },
185
- keyed: true,
186
- children: (_key) => out()
187
- });
188
- return createComponent(Solid.Switch, { get children() {
189
- return [
190
- createComponent(Solid.Match, {
191
- get when() {
192
- return match()._displayPending;
193
- },
194
- children: (_) => {
195
- const matchId = Solid.untrack(() => match().id);
196
- return memo(Solid.createMemo(() => router.getMatch(matchId)?._nonReactive.displayPendingPromise));
197
- }
198
- }),
199
- createComponent(Solid.Match, {
200
- get when() {
201
- return match()._forcePending;
202
- },
203
- children: (_) => {
204
- const matchId = Solid.untrack(() => match().id);
205
- return memo(Solid.createMemo(() => router.getMatch(matchId)?._nonReactive.minPendingPromise));
206
- }
207
- }),
208
- createComponent(Solid.Match, {
195
+ children: (currentMatchState) => {
196
+ const route = Solid.createMemo(() => router.routesById[currentMatchState().routeId]);
197
+ const currentMatch = Solid.createMemo(() => currentMatchState().match);
198
+ const componentKey = Solid.createMemo(() => currentMatchState().key ?? currentMatchState().match.id);
199
+ const Comp = Solid.createMemo(() => route().options.component ?? router.options.defaultComponent);
200
+ const OutComponent = Solid.createMemo(() => {
201
+ return Comp() || Outlet;
202
+ });
203
+ const RenderOut = () => createComponent(Dynamic, { get component() {
204
+ return OutComponent();
205
+ } });
206
+ const keyedOut = () => createComponent(Solid.Show, {
209
207
  get when() {
210
- return match().status === "pending";
208
+ return componentKey();
211
209
  },
212
- children: (_) => {
213
- const currentMatch = Solid.untrack(match);
214
- const currentRoute = Solid.untrack(route);
215
- const pendingMinMs = currentRoute.options.pendingMinMs ?? router.options.defaultPendingMinMs;
216
- if (pendingMinMs) {
217
- const routerMatch = router.getMatch(currentMatch.id);
218
- if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {
219
- if (!(isServer ?? router.isServer)) {
220
- const minPendingPromise = createControlledPromise();
221
- routerMatch._nonReactive.minPendingPromise = minPendingPromise;
222
- setTimeout(() => {
223
- minPendingPromise.resolve();
224
- routerMatch._nonReactive.minPendingPromise = void 0;
225
- }, pendingMinMs);
210
+ keyed: true,
211
+ children: (_key) => createComponent(RenderOut, {})
212
+ });
213
+ return createComponent(Solid.Switch, { get children() {
214
+ return [
215
+ createComponent(Solid.Match, {
216
+ get when() {
217
+ return currentMatch()._displayPending;
218
+ },
219
+ children: (_) => {
220
+ return memo(Solid.createMemo(() => router.getMatch(currentMatch().id)?._nonReactive.displayPendingPromise));
221
+ }
222
+ }),
223
+ createComponent(Solid.Match, {
224
+ get when() {
225
+ return currentMatch()._forcePending;
226
+ },
227
+ children: (_) => {
228
+ return memo(Solid.createMemo(() => router.getMatch(currentMatch().id)?._nonReactive.minPendingPromise));
229
+ }
230
+ }),
231
+ createComponent(Solid.Match, {
232
+ get when() {
233
+ return currentMatch().status === "pending";
234
+ },
235
+ children: (_) => {
236
+ const pendingMinMs = Solid.untrack(() => route().options.pendingMinMs ?? router.options.defaultPendingMinMs);
237
+ if (pendingMinMs) {
238
+ const routerMatch = Solid.untrack(() => router.getMatch(currentMatch().id));
239
+ if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {
240
+ if (!(isServer$1 ?? router.isServer)) {
241
+ const minPendingPromise = createControlledPromise();
242
+ routerMatch._nonReactive.minPendingPromise = minPendingPromise;
243
+ setTimeout(() => {
244
+ minPendingPromise.resolve();
245
+ routerMatch._nonReactive.minPendingPromise = void 0;
246
+ }, pendingMinMs);
247
+ }
248
+ }
226
249
  }
250
+ const loaderResult = Solid.createMemo(async () => {
251
+ await new Promise((r) => setTimeout(r, 0));
252
+ return router.getMatch(currentMatch().id)?._nonReactive.loadPromise;
253
+ });
254
+ const FallbackComponent = Solid.untrack(() => route().options.pendingComponent ?? router.options.defaultPendingComponent);
255
+ return [FallbackComponent && pendingMinMs > 0 ? createComponent(Dynamic, { component: FallbackComponent }) : null, memo(loaderResult)];
227
256
  }
228
- }
229
- const loaderResult = Solid.createMemo(async () => {
230
- await new Promise((r) => setTimeout(r, 0));
231
- return router.getMatch(currentMatch.id)?._nonReactive.loadPromise;
232
- });
233
- const FallbackComponent = currentRoute.options.pendingComponent ?? router.options.defaultPendingComponent;
234
- return [FallbackComponent && pendingMinMs > 0 ? createComponent(Dynamic, { component: FallbackComponent }) : null, memo(loaderResult)];
235
- }
236
- }),
237
- createComponent(Solid.Match, {
238
- get when() {
239
- return match().status === "notFound";
240
- },
241
- children: (_) => {
242
- const currentMatch = Solid.untrack(match);
243
- const currentRoute = Solid.untrack(route);
244
- const currentRouteId = Solid.untrack(() => matchState().routeId);
245
- invariant(isNotFound(currentMatch.error), "Expected a notFound error");
246
- return createComponent(Solid.Show, {
247
- when: currentRouteId,
248
- keyed: true,
249
- children: (_routeId) => renderRouteNotFound(router, currentRoute, currentMatch.error)
250
- });
251
- }
252
- }),
253
- createComponent(Solid.Match, {
254
- get when() {
255
- return match().status === "redirected";
256
- },
257
- children: (_) => {
258
- const matchId = Solid.untrack(() => match().id);
259
- invariant(isRedirect(Solid.untrack(match).error), "Expected a redirect error");
260
- return memo(Solid.createMemo(async () => {
261
- await new Promise((r) => setTimeout(r, 0));
262
- return router.getMatch(matchId)?._nonReactive.loadPromise;
263
- }));
264
- }
265
- }),
266
- createComponent(Solid.Match, {
267
- get when() {
268
- return match().status === "error";
269
- },
270
- children: (_) => {
271
- if (isServer ?? router.isServer) {
272
- const currentMatch = Solid.untrack(match);
273
- return createComponent((Solid.untrack(route).options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent, {
274
- get error() {
275
- return currentMatch.error;
276
- },
277
- info: { componentStack: "" }
278
- });
279
- }
280
- throw Solid.untrack(match).error;
281
- }
282
- }),
283
- createComponent(Solid.Match, {
284
- get when() {
285
- return match().status === "success";
286
- },
287
- get children() {
288
- return keyedOut();
289
- }
290
- })
291
- ];
292
- } });
257
+ }),
258
+ createComponent(Solid.Match, {
259
+ get when() {
260
+ return currentMatch().status === "notFound";
261
+ },
262
+ children: (_) => {
263
+ const matchError = Solid.untrack(() => currentMatch().error);
264
+ invariant(isNotFound(matchError), "Expected a notFound error");
265
+ return createComponent(Solid.Show, {
266
+ get when() {
267
+ return currentMatchState().routeId;
268
+ },
269
+ keyed: true,
270
+ children: (_routeId) => Solid.untrack(() => renderRouteNotFound(router, route(), matchError))
271
+ });
272
+ }
273
+ }),
274
+ createComponent(Solid.Match, {
275
+ get when() {
276
+ return currentMatch().status === "redirected";
277
+ },
278
+ children: (_) => {
279
+ invariant(isRedirect(Solid.untrack(() => currentMatch().error)), "Expected a redirect error");
280
+ return null;
281
+ }
282
+ }),
283
+ createComponent(Solid.Match, {
284
+ get when() {
285
+ return currentMatch().status === "error";
286
+ },
287
+ children: (_) => {
288
+ const matchError = Solid.untrack(() => currentMatch().error);
289
+ if (isServer$1 ?? router.isServer) return createComponent((route().options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent, {
290
+ error: matchError,
291
+ info: { componentStack: "" }
292
+ });
293
+ throw matchError;
294
+ }
295
+ }),
296
+ createComponent(Solid.Match, {
297
+ get when() {
298
+ return currentMatch().status === "success";
299
+ },
300
+ get children() {
301
+ return keyedOut();
302
+ }
303
+ })
304
+ ];
305
+ } });
306
+ }
307
+ });
293
308
  };
294
309
  var Outlet = () => {
295
310
  const router = useRouter();
296
- const matchId = Solid.useContext(matchContext);
297
- const routeId = useRouterState({ select: (s) => s.matches.find((d) => d.id === matchId())?.routeId });
298
- const route = () => router.routesById[routeId()];
299
- const parentGlobalNotFound = useRouterState({ select: (s) => {
300
- const parentMatch = s.matches.find((d) => d.id === matchId());
301
- if (!parentMatch) return false;
302
- return parentMatch.globalNotFound;
303
- } });
304
- const childMatchId = useRouterState({ select: (s) => {
305
- const matches = s.matches;
306
- return matches[matches.findIndex((d) => d.id === matchId()) + 1]?.id;
307
- } });
308
- const childRouteId = useRouterState({ select: (s) => {
309
- const matches = s.matches;
310
- return matches[matches.findIndex((d) => d.id === matchId()) + 1]?.routeId;
311
- } });
312
- const childMatchStatus = useRouterState({ select: (s) => {
313
- const matches = s.matches;
314
- return matches[matches.findIndex((d) => d.id === matchId()) + 1]?.status;
315
- } });
311
+ const nearestParentMatch = Solid.useContext(nearestMatchContext);
312
+ const parentMatch = nearestParentMatch.match;
313
+ const routeId = nearestParentMatch.routeId;
314
+ const route = Solid.createMemo(() => routeId() ? router.routesById[routeId()] : void 0);
315
+ const parentGlobalNotFound = Solid.createMemo(() => parentMatch()?.globalNotFound ?? false);
316
+ const childMatchId = Solid.createMemo(() => {
317
+ const currentRouteId = routeId();
318
+ return currentRouteId ? router.stores.childMatchIdByRouteId.state[currentRouteId] : void 0;
319
+ });
320
+ const childRouteId = Solid.createMemo(() => {
321
+ const id = childMatchId();
322
+ if (!id) return void 0;
323
+ return router.stores.activeMatchStoresById.get(id)?.state.routeId;
324
+ });
325
+ const childRoute = Solid.createMemo(() => {
326
+ const id = childRouteId();
327
+ return id ? router.routesById[id] : void 0;
328
+ });
329
+ const childPendingComponent = Solid.createMemo(() => childRoute()?.options.pendingComponent ?? router.options.defaultPendingComponent);
330
+ const childMatchStatus = Solid.createMemo(() => {
331
+ const id = childMatchId();
332
+ if (!id) return void 0;
333
+ return router.stores.activeMatchStoresById.get(id)?.state.status;
334
+ });
316
335
  const shouldShowNotFound = () => childMatchStatus() !== "redirected" && parentGlobalNotFound();
317
336
  return createComponent(Solid.Show, {
318
337
  get when() {
@@ -321,15 +340,13 @@ var Outlet = () => {
321
340
  get fallback() {
322
341
  return createComponent(Solid.Show, {
323
342
  get when() {
324
- return shouldShowNotFound();
343
+ return memo(() => !!shouldShowNotFound())() && route();
325
344
  },
326
- get children() {
327
- return renderRouteNotFound(router, route(), void 0);
328
- }
345
+ children: (resolvedRoute) => Solid.untrack(() => renderRouteNotFound(router, resolvedRoute(), void 0))
329
346
  });
330
347
  },
331
- children: (matchIdAccessor) => {
332
- const currentMatchId = Solid.createMemo(() => matchIdAccessor());
348
+ children: (childMatchIdAccessor) => {
349
+ const currentMatchId = Solid.createMemo(() => childMatchIdAccessor());
333
350
  return createComponent(Solid.Show, {
334
351
  get when() {
335
352
  return routeId() === rootRouteId;
@@ -347,9 +364,9 @@ var Outlet = () => {
347
364
  keyed: true,
348
365
  children: (_routeId) => createComponent(Solid.Loading, {
349
366
  get fallback() {
350
- return createComponent(Dynamic, { get component() {
351
- return router.options.defaultPendingComponent;
352
- } });
367
+ return memo(() => !!childPendingComponent())() ? createComponent(Dynamic, { get component() {
368
+ return childPendingComponent();
369
+ } }) : null;
353
370
  },
354
371
  get children() {
355
372
  return createComponent(Match, { get matchId() {