@tanstack/solid-router 1.167.5 → 1.168.0

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