@tanstack/solid-router 2.0.0-alpha.1 → 2.0.0-alpha.3

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 (207) hide show
  1. package/dist/cjs/Asset.cjs +124 -167
  2. package/dist/cjs/Asset.cjs.map +1 -1
  3. package/dist/cjs/CatchBoundary.cjs +52 -68
  4. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  5. package/dist/cjs/ClientOnly.cjs +61 -39
  6. package/dist/cjs/ClientOnly.cjs.map +1 -1
  7. package/dist/cjs/HeadContent.cjs +35 -27
  8. package/dist/cjs/HeadContent.cjs.map +1 -1
  9. package/dist/cjs/HeadContent.dev.cjs +48 -41
  10. package/dist/cjs/HeadContent.dev.cjs.map +1 -1
  11. package/dist/cjs/Match.cjs +367 -442
  12. package/dist/cjs/Match.cjs.map +1 -1
  13. package/dist/cjs/Matches.cjs +114 -158
  14. package/dist/cjs/Matches.cjs.map +1 -1
  15. package/dist/cjs/RouterProvider.cjs +29 -41
  16. package/dist/cjs/RouterProvider.cjs.map +1 -1
  17. package/dist/cjs/SafeFragment.cjs +7 -5
  18. package/dist/cjs/SafeFragment.cjs.map +1 -1
  19. package/dist/cjs/ScriptOnce.cjs +20 -22
  20. package/dist/cjs/ScriptOnce.cjs.map +1 -1
  21. package/dist/cjs/Scripts.cjs +43 -58
  22. package/dist/cjs/Scripts.cjs.map +1 -1
  23. package/dist/cjs/ScrollRestoration.cjs +26 -28
  24. package/dist/cjs/ScrollRestoration.cjs.map +1 -1
  25. package/dist/cjs/Transitioner.cjs +91 -124
  26. package/dist/cjs/Transitioner.cjs.map +1 -1
  27. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  28. package/dist/cjs/awaited.cjs +31 -53
  29. package/dist/cjs/awaited.cjs.map +1 -1
  30. package/dist/cjs/fileRoute.cjs +96 -91
  31. package/dist/cjs/fileRoute.cjs.map +1 -1
  32. package/dist/cjs/fileRoute.d.cts +2 -2
  33. package/dist/cjs/headContentUtils.cjs +132 -170
  34. package/dist/cjs/headContentUtils.cjs.map +1 -1
  35. package/dist/cjs/index.cjs +245 -176
  36. package/dist/cjs/index.dev.cjs +245 -176
  37. package/dist/cjs/lazyRouteComponent.cjs +48 -54
  38. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  39. package/dist/cjs/link.cjs +310 -345
  40. package/dist/cjs/link.cjs.map +1 -1
  41. package/dist/cjs/matchContext.cjs +9 -23
  42. package/dist/cjs/matchContext.cjs.map +1 -1
  43. package/dist/cjs/not-found.cjs +26 -34
  44. package/dist/cjs/not-found.cjs.map +1 -1
  45. package/dist/cjs/renderRouteNotFound.cjs +23 -16
  46. package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
  47. package/dist/cjs/route.cjs +200 -215
  48. package/dist/cjs/route.cjs.map +1 -1
  49. package/dist/cjs/router.cjs +18 -16
  50. package/dist/cjs/router.cjs.map +1 -1
  51. package/dist/cjs/routerContext.cjs +8 -22
  52. package/dist/cjs/routerContext.cjs.map +1 -1
  53. package/dist/cjs/scroll-restoration.cjs +25 -35
  54. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  55. package/dist/cjs/ssr/RouterClient.cjs +18 -23
  56. package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
  57. package/dist/cjs/ssr/RouterServer.cjs +10 -10
  58. package/dist/cjs/ssr/RouterServer.cjs.map +1 -1
  59. package/dist/cjs/ssr/client.cjs +2 -4
  60. package/dist/cjs/ssr/defaultRenderHandler.cjs +12 -16
  61. package/dist/cjs/ssr/defaultRenderHandler.cjs.map +1 -1
  62. package/dist/cjs/ssr/defaultStreamHandler.cjs +13 -18
  63. package/dist/cjs/ssr/defaultStreamHandler.cjs.map +1 -1
  64. package/dist/cjs/ssr/renderRouterToStream.cjs +26 -54
  65. package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
  66. package/dist/cjs/ssr/renderRouterToString.cjs +33 -57
  67. package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
  68. package/dist/cjs/ssr/server.cjs +18 -18
  69. package/dist/cjs/useBlocker.cjs +140 -177
  70. package/dist/cjs/useBlocker.cjs.map +1 -1
  71. package/dist/cjs/useBlocker.d.cts +8 -5
  72. package/dist/cjs/useCanGoBack.cjs +6 -5
  73. package/dist/cjs/useCanGoBack.cjs.map +1 -1
  74. package/dist/cjs/useLoaderData.cjs +12 -11
  75. package/dist/cjs/useLoaderData.cjs.map +1 -1
  76. package/dist/cjs/useLoaderDeps.cjs +12 -14
  77. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  78. package/dist/cjs/useLocation.cjs +6 -7
  79. package/dist/cjs/useLocation.cjs.map +1 -1
  80. package/dist/cjs/useMatch.cjs +25 -46
  81. package/dist/cjs/useMatch.cjs.map +1 -1
  82. package/dist/cjs/useNavigate.cjs +20 -38
  83. package/dist/cjs/useNavigate.cjs.map +1 -1
  84. package/dist/cjs/useParams.cjs +14 -13
  85. package/dist/cjs/useParams.cjs.map +1 -1
  86. package/dist/cjs/useRouteContext.cjs +9 -8
  87. package/dist/cjs/useRouteContext.cjs.map +1 -1
  88. package/dist/cjs/useRouter.cjs +13 -26
  89. package/dist/cjs/useRouter.cjs.map +1 -1
  90. package/dist/cjs/useRouterState.cjs +40 -43
  91. package/dist/cjs/useRouterState.cjs.map +1 -1
  92. package/dist/cjs/useSearch.cjs +13 -12
  93. package/dist/cjs/useSearch.cjs.map +1 -1
  94. package/dist/cjs/utils.cjs +57 -49
  95. package/dist/cjs/utils.cjs.map +1 -1
  96. package/dist/esm/Asset.js +122 -166
  97. package/dist/esm/Asset.js.map +1 -1
  98. package/dist/esm/CatchBoundary.js +48 -50
  99. package/dist/esm/CatchBoundary.js.map +1 -1
  100. package/dist/esm/ClientOnly.js +58 -22
  101. package/dist/esm/ClientOnly.js.map +1 -1
  102. package/dist/esm/HeadContent.dev.js +46 -40
  103. package/dist/esm/HeadContent.dev.js.map +1 -1
  104. package/dist/esm/HeadContent.js +33 -26
  105. package/dist/esm/HeadContent.js.map +1 -1
  106. package/dist/esm/Match.js +359 -422
  107. package/dist/esm/Match.js.map +1 -1
  108. package/dist/esm/Matches.js +107 -142
  109. package/dist/esm/Matches.js.map +1 -1
  110. package/dist/esm/RouterProvider.js +26 -40
  111. package/dist/esm/RouterProvider.js.map +1 -1
  112. package/dist/esm/SafeFragment.js +6 -5
  113. package/dist/esm/SafeFragment.js.map +1 -1
  114. package/dist/esm/ScriptOnce.js +18 -21
  115. package/dist/esm/ScriptOnce.js.map +1 -1
  116. package/dist/esm/Scripts.js +42 -58
  117. package/dist/esm/Scripts.js.map +1 -1
  118. package/dist/esm/ScrollRestoration.js +25 -29
  119. package/dist/esm/ScrollRestoration.js.map +1 -1
  120. package/dist/esm/Transitioner.js +87 -105
  121. package/dist/esm/Transitioner.js.map +1 -1
  122. package/dist/esm/awaited.js +28 -36
  123. package/dist/esm/awaited.js.map +1 -1
  124. package/dist/esm/fileRoute.d.ts +2 -2
  125. package/dist/esm/fileRoute.js +90 -92
  126. package/dist/esm/fileRoute.js.map +1 -1
  127. package/dist/esm/headContentUtils.js +129 -152
  128. package/dist/esm/headContentUtils.js.map +1 -1
  129. package/dist/esm/index.dev.js +15 -115
  130. package/dist/esm/index.js +17 -116
  131. package/dist/esm/lazyRouteComponent.js +46 -53
  132. package/dist/esm/lazyRouteComponent.js.map +1 -1
  133. package/dist/esm/link.js +306 -329
  134. package/dist/esm/link.js.map +1 -1
  135. package/dist/esm/matchContext.js +7 -7
  136. package/dist/esm/matchContext.js.map +1 -1
  137. package/dist/esm/not-found.js +23 -33
  138. package/dist/esm/not-found.js.map +1 -1
  139. package/dist/esm/renderRouteNotFound.js +20 -15
  140. package/dist/esm/renderRouteNotFound.js.map +1 -1
  141. package/dist/esm/route.js +193 -218
  142. package/dist/esm/route.js.map +1 -1
  143. package/dist/esm/router.js +17 -17
  144. package/dist/esm/router.js.map +1 -1
  145. package/dist/esm/routerContext.js +6 -5
  146. package/dist/esm/routerContext.js.map +1 -1
  147. package/dist/esm/scroll-restoration.js +23 -34
  148. package/dist/esm/scroll-restoration.js.map +1 -1
  149. package/dist/esm/ssr/RouterClient.js +16 -22
  150. package/dist/esm/ssr/RouterClient.js.map +1 -1
  151. package/dist/esm/ssr/RouterServer.js +9 -10
  152. package/dist/esm/ssr/RouterServer.js.map +1 -1
  153. package/dist/esm/ssr/client.js +1 -4
  154. package/dist/esm/ssr/defaultRenderHandler.js +11 -15
  155. package/dist/esm/ssr/defaultRenderHandler.js.map +1 -1
  156. package/dist/esm/ssr/defaultStreamHandler.js +12 -17
  157. package/dist/esm/ssr/defaultStreamHandler.js.map +1 -1
  158. package/dist/esm/ssr/renderRouterToStream.js +23 -36
  159. package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
  160. package/dist/esm/ssr/renderRouterToString.js +31 -40
  161. package/dist/esm/ssr/renderRouterToString.js.map +1 -1
  162. package/dist/esm/ssr/server.js +3 -10
  163. package/dist/esm/useBlocker.d.ts +8 -5
  164. package/dist/esm/useBlocker.js +136 -159
  165. package/dist/esm/useBlocker.js.map +1 -1
  166. package/dist/esm/useCanGoBack.js +6 -5
  167. package/dist/esm/useCanGoBack.js.map +1 -1
  168. package/dist/esm/useLoaderData.js +12 -11
  169. package/dist/esm/useLoaderData.js.map +1 -1
  170. package/dist/esm/useLoaderDeps.js +12 -14
  171. package/dist/esm/useLoaderDeps.js.map +1 -1
  172. package/dist/esm/useLocation.js +6 -7
  173. package/dist/esm/useLocation.js.map +1 -1
  174. package/dist/esm/useMatch.js +21 -28
  175. package/dist/esm/useMatch.js.map +1 -1
  176. package/dist/esm/useNavigate.js +18 -22
  177. package/dist/esm/useNavigate.js.map +1 -1
  178. package/dist/esm/useParams.js +14 -13
  179. package/dist/esm/useParams.js.map +1 -1
  180. package/dist/esm/useRouteContext.js +9 -8
  181. package/dist/esm/useRouteContext.js.map +1 -1
  182. package/dist/esm/useRouter.js +9 -8
  183. package/dist/esm/useRouter.js.map +1 -1
  184. package/dist/esm/useRouterState.js +38 -42
  185. package/dist/esm/useRouterState.js.map +1 -1
  186. package/dist/esm/useSearch.js +13 -12
  187. package/dist/esm/useSearch.js.map +1 -1
  188. package/dist/esm/utils.js +55 -33
  189. package/dist/esm/utils.js.map +1 -1
  190. package/dist/source/fileRoute.d.ts +2 -2
  191. package/dist/source/useBlocker.d.ts +8 -5
  192. package/dist/source/useBlocker.jsx +2 -2
  193. package/dist/source/useBlocker.jsx.map +1 -1
  194. package/dist/source/useRouterState.jsx +7 -0
  195. package/dist/source/useRouterState.jsx.map +1 -1
  196. package/package.json +3 -3
  197. package/src/fileRoute.ts +2 -2
  198. package/src/useBlocker.tsx +15 -10
  199. package/src/useRouterState.tsx +10 -0
  200. package/dist/cjs/index.cjs.map +0 -1
  201. package/dist/cjs/index.dev.cjs.map +0 -1
  202. package/dist/cjs/ssr/client.cjs.map +0 -1
  203. package/dist/cjs/ssr/server.cjs.map +0 -1
  204. package/dist/esm/index.dev.js.map +0 -1
  205. package/dist/esm/index.js.map +0 -1
  206. package/dist/esm/ssr/client.js.map +0 -1
  207. package/dist/esm/ssr/server.js.map +0 -1
package/dist/esm/Match.js CHANGED
@@ -1,432 +1,369 @@
1
- import { createComponent, Dynamic, memo, mergeProps } from "@solidjs/web";
2
- import * as Solid from "solid-js";
3
- import invariant from "tiny-invariant";
4
- import warning from "tiny-warning";
5
- import { isNotFound, rootRouteId, createControlledPromise, isRedirect, getLocationChangeInfo } from "@tanstack/router-core";
6
- import { isServer } from "@tanstack/router-core/isServer";
7
- import { ErrorComponent, CatchBoundary } from "./CatchBoundary.js";
8
- import { useRouterState } from "./useRouterState.js";
1
+ import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
9
2
  import { useRouter } from "./useRouter.js";
10
- import { CatchNotFound } from "./not-found.js";
3
+ import { useRouterState } from "./useRouterState.js";
11
4
  import { matchContext } from "./matchContext.js";
12
5
  import { SafeFragment } from "./SafeFragment.js";
6
+ import { CatchNotFound } from "./not-found.js";
13
7
  import { renderRouteNotFound } from "./renderRouteNotFound.js";
14
8
  import { ScrollRestoration } from "./scroll-restoration.js";
15
- const MatchContext = matchContext;
16
- const Match = (props) => {
17
- const router = useRouter();
18
- const matchState = useRouterState({
19
- select: (s) => {
20
- const match = s.matches.find((d) => d.id === props.matchId);
21
- if (!match) {
22
- return null;
23
- }
24
- return {
25
- routeId: match.routeId,
26
- ssr: match.ssr,
27
- _displayPending: match._displayPending
28
- };
29
- }
30
- });
31
- if (!Solid.untrack(matchState)) return null;
32
- const route = () => router.routesById[matchState().routeId];
33
- const resolvePendingComponent = () => route().options.pendingComponent ?? router.options.defaultPendingComponent;
34
- const routeErrorComponent = () => route().options.errorComponent ?? router.options.defaultErrorComponent;
35
- const routeOnCatch = () => route().options.onCatch ?? router.options.defaultOnCatch;
36
- const routeNotFoundComponent = () => route().isRoot ? (
37
- // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
38
- route().options.notFoundComponent ?? router.options.notFoundRoute?.options.component
39
- ) : route().options.notFoundComponent;
40
- const resolvedNoSsr = Solid.createMemo(() => matchState().ssr === false || matchState().ssr === "data-only");
41
- const ResolvedSuspenseBoundary = () => resolvedNoSsr() ? SafeFragment : Solid.Loading;
42
- const ResolvedCatchBoundary = () => routeErrorComponent() ? CatchBoundary : SafeFragment;
43
- const ResolvedNotFoundBoundary = () => routeNotFoundComponent() ? CatchNotFound : SafeFragment;
44
- const resetKey = useRouterState({
45
- select: (s) => s.loadedAt
46
- });
47
- const parentRouteId = useRouterState({
48
- select: (s) => {
49
- const index = s.matches.findIndex((d) => d.id === props.matchId);
50
- return s.matches[index - 1]?.routeId;
51
- }
52
- });
53
- const ShellComponent = Solid.createMemo(() => route().isRoot ? route().options.shellComponent ?? SafeFragment : SafeFragment);
54
- return createComponent(Dynamic, {
55
- get component() {
56
- return ShellComponent();
57
- },
58
- get children() {
59
- return [createComponent(MatchContext, {
60
- value: () => props.matchId,
61
- get children() {
62
- return createComponent(Dynamic, {
63
- get component() {
64
- return ResolvedSuspenseBoundary();
65
- },
66
- get fallback() {
67
- return (
68
- // Don't show fallback on server when using no-ssr mode to avoid hydration mismatch
69
- memo(() => !!((isServer ?? router.isServer) || resolvedNoSsr()))() ? void 0 : createComponent(Dynamic, {
70
- get component() {
71
- return resolvePendingComponent();
72
- }
73
- })
74
- );
75
- },
76
- get children() {
77
- return createComponent(Dynamic, {
78
- get component() {
79
- return ResolvedCatchBoundary();
80
- },
81
- getResetKey: () => resetKey(),
82
- get errorComponent() {
83
- return routeErrorComponent() || ErrorComponent;
84
- },
85
- onCatch: (error) => {
86
- if (isNotFound(error)) throw error;
87
- warning(false, `Error in route match: ${Solid.untrack(matchState).routeId}`);
88
- routeOnCatch()?.(error);
89
- },
90
- get children() {
91
- return createComponent(Dynamic, {
92
- get component() {
93
- return ResolvedNotFoundBoundary();
94
- },
95
- fallback: (error) => {
96
- if (!routeNotFoundComponent() || error.routeId && error.routeId !== matchState().routeId || !error.routeId && !route().isRoot) throw error;
97
- return createComponent(Dynamic, mergeProps({
98
- get component() {
99
- return routeNotFoundComponent();
100
- }
101
- }, error));
102
- },
103
- get children() {
104
- return createComponent(Solid.Switch, {
105
- get children() {
106
- return [createComponent(Solid.Match, {
107
- get when() {
108
- return resolvedNoSsr();
109
- },
110
- get children() {
111
- return createComponent(Solid.Show, {
112
- get when() {
113
- return !(isServer ?? router.isServer);
114
- },
115
- get fallback() {
116
- return createComponent(Dynamic, {
117
- get component() {
118
- return resolvePendingComponent();
119
- }
120
- });
121
- },
122
- get children() {
123
- return createComponent(MatchInner, {
124
- get matchId() {
125
- return props.matchId;
126
- }
127
- });
128
- }
129
- });
130
- }
131
- }), createComponent(Solid.Match, {
132
- get when() {
133
- return !resolvedNoSsr();
134
- },
135
- get children() {
136
- return createComponent(MatchInner, {
137
- get matchId() {
138
- return props.matchId;
139
- }
140
- });
141
- }
142
- })];
143
- }
144
- });
145
- }
146
- });
147
- }
148
- });
149
- }
150
- });
151
- }
152
- }), memo(() => memo(() => parentRouteId() === rootRouteId)() ? [createComponent(OnRendered, {}), createComponent(ScrollRestoration, {})] : null)];
153
- }
154
- });
9
+ import { createControlledPromise, getLocationChangeInfo, isNotFound, isRedirect, rootRouteId } from "@tanstack/router-core";
10
+ import { Dynamic, createComponent, memo, mergeProps } from "@solidjs/web";
11
+ import * as Solid from "solid-js";
12
+ import warning from "tiny-warning";
13
+ import { isServer } from "@tanstack/router-core/isServer";
14
+ import invariant from "tiny-invariant";
15
+ //#region src/Match.tsx
16
+ var MatchContext = matchContext;
17
+ var Match = (props) => {
18
+ 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;
22
+ return {
23
+ routeId: match.routeId,
24
+ ssr: match.ssr,
25
+ _displayPending: match._displayPending
26
+ };
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();
47
+ },
48
+ get children() {
49
+ return [createComponent(MatchContext, {
50
+ value: () => props.matchId,
51
+ 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
+ },
61
+ get children() {
62
+ return createComponent(Dynamic, {
63
+ get component() {
64
+ return ResolvedCatchBoundary();
65
+ },
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);
74
+ },
75
+ get children() {
76
+ return createComponent(Dynamic, {
77
+ get component() {
78
+ return ResolvedNotFoundBoundary();
79
+ },
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));
85
+ },
86
+ 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, {
94
+ get when() {
95
+ return !(isServer ?? router.isServer);
96
+ },
97
+ get fallback() {
98
+ return createComponent(Dynamic, { get component() {
99
+ return resolvePendingComponent();
100
+ } });
101
+ },
102
+ get children() {
103
+ return createComponent(MatchInner, { get matchId() {
104
+ return props.matchId;
105
+ } });
106
+ }
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
+ } });
120
+ }
121
+ });
122
+ }
123
+ });
124
+ }
125
+ });
126
+ }
127
+ }), memo(() => memo(() => parentRouteId() === rootRouteId)() ? [createComponent(OnRendered, {}), createComponent(ScrollRestoration, {})] : null)];
128
+ }
129
+ });
155
130
  };
156
- const lastOnRenderedKey = /* @__PURE__ */ new WeakMap();
131
+ var lastOnRenderedKey = /* @__PURE__ */ new WeakMap();
157
132
  function OnRendered() {
158
- const router = useRouter();
159
- const location = useRouterState({
160
- select: (s) => {
161
- return s.resolvedLocation?.state.__TSR_key;
162
- }
163
- });
164
- Solid.createEffect(() => [location()], ([location2]) => {
165
- if (!location2) return;
166
- if (lastOnRenderedKey.get(router) === location2) return;
167
- lastOnRenderedKey.set(router, location2);
168
- router.emit({
169
- type: "onRendered",
170
- ...getLocationChangeInfo(router.state)
171
- });
172
- });
173
- return null;
133
+ const router = useRouter();
134
+ const location = useRouterState({ select: (s) => {
135
+ return s.resolvedLocation?.state.__TSR_key;
136
+ } });
137
+ Solid.createEffect(() => [location()], ([location]) => {
138
+ if (!location) return;
139
+ if (lastOnRenderedKey.get(router) === location) return;
140
+ lastOnRenderedKey.set(router, location);
141
+ router.emit({
142
+ type: "onRendered",
143
+ ...getLocationChangeInfo(router.state)
144
+ });
145
+ });
146
+ return null;
174
147
  }
175
- const MatchInner = (props) => {
176
- const router = useRouter();
177
- const matchState = useRouterState({
178
- select: (s) => {
179
- const match2 = s.matches.find((d) => d.id === props.matchId);
180
- if (!match2) {
181
- return null;
182
- }
183
- const routeId = match2.routeId;
184
- const remountFn = router.routesById[routeId].options.remountDeps ?? router.options.defaultRemountDeps;
185
- const remountDeps = remountFn?.({
186
- routeId,
187
- loaderDeps: match2.loaderDeps,
188
- params: match2._strictParams,
189
- search: match2._strictSearch
190
- });
191
- const key = remountDeps ? JSON.stringify(remountDeps) : void 0;
192
- return {
193
- key,
194
- routeId,
195
- match: {
196
- id: match2.id,
197
- status: match2.status,
198
- error: match2.error,
199
- _forcePending: match2._forcePending,
200
- _displayPending: match2._displayPending
201
- }
202
- };
203
- }
204
- });
205
- if (!Solid.untrack(matchState)) return null;
206
- const route = () => router.routesById[matchState().routeId];
207
- const match = () => matchState().match;
208
- const componentKey = () => matchState().key ?? matchState().match.id;
209
- const out = () => {
210
- const currentRoute = Solid.untrack(route);
211
- const Comp = currentRoute.options.component ?? router.options.defaultComponent;
212
- if (Comp) {
213
- return createComponent(Comp, {});
214
- }
215
- return createComponent(Outlet, {});
216
- };
217
- const keyedOut = () => createComponent(Solid.Show, {
218
- get when() {
219
- return componentKey();
220
- },
221
- keyed: true,
222
- children: (_key) => out()
223
- });
224
- return createComponent(Solid.Switch, {
225
- get children() {
226
- return [createComponent(Solid.Match, {
227
- get when() {
228
- return match()._displayPending;
229
- },
230
- children: (_) => {
231
- const matchId = Solid.untrack(() => match().id);
232
- const displayPendingResult = Solid.createMemo(() => router.getMatch(matchId)?._nonReactive.displayPendingPromise);
233
- return memo(displayPendingResult);
234
- }
235
- }), createComponent(Solid.Match, {
236
- get when() {
237
- return match()._forcePending;
238
- },
239
- children: (_) => {
240
- const matchId = Solid.untrack(() => match().id);
241
- const minPendingResult = Solid.createMemo(() => router.getMatch(matchId)?._nonReactive.minPendingPromise);
242
- return memo(minPendingResult);
243
- }
244
- }), createComponent(Solid.Match, {
245
- get when() {
246
- return match().status === "pending";
247
- },
248
- children: (_) => {
249
- const currentMatch = Solid.untrack(match);
250
- const currentRoute = Solid.untrack(route);
251
- const pendingMinMs = currentRoute.options.pendingMinMs ?? router.options.defaultPendingMinMs;
252
- if (pendingMinMs) {
253
- const routerMatch = router.getMatch(currentMatch.id);
254
- if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {
255
- if (!(isServer ?? router.isServer)) {
256
- const minPendingPromise = createControlledPromise();
257
- routerMatch._nonReactive.minPendingPromise = minPendingPromise;
258
- setTimeout(() => {
259
- minPendingPromise.resolve();
260
- routerMatch._nonReactive.minPendingPromise = void 0;
261
- }, pendingMinMs);
262
- }
263
- }
264
- }
265
- const loaderResult = Solid.createMemo(async () => {
266
- await new Promise((r) => setTimeout(r, 0));
267
- return router.getMatch(currentMatch.id)?._nonReactive.loadPromise;
268
- });
269
- const FallbackComponent = currentRoute.options.pendingComponent ?? router.options.defaultPendingComponent;
270
- return [FallbackComponent && pendingMinMs > 0 ? createComponent(Dynamic, {
271
- component: FallbackComponent
272
- }) : null, memo(loaderResult)];
273
- }
274
- }), createComponent(Solid.Match, {
275
- get when() {
276
- return match().status === "notFound";
277
- },
278
- children: (_) => {
279
- const currentMatch = Solid.untrack(match);
280
- const currentRoute = Solid.untrack(route);
281
- const currentRouteId = Solid.untrack(() => matchState().routeId);
282
- invariant(isNotFound(currentMatch.error), "Expected a notFound error");
283
- return createComponent(Solid.Show, {
284
- when: currentRouteId,
285
- keyed: true,
286
- children: (_routeId) => renderRouteNotFound(router, currentRoute, currentMatch.error)
287
- });
288
- }
289
- }), createComponent(Solid.Match, {
290
- get when() {
291
- return match().status === "redirected";
292
- },
293
- children: (_) => {
294
- const matchId = Solid.untrack(() => match().id);
295
- invariant(isRedirect(Solid.untrack(match).error), "Expected a redirect error");
296
- const loaderResult = Solid.createMemo(async () => {
297
- await new Promise((r) => setTimeout(r, 0));
298
- return router.getMatch(matchId)?._nonReactive.loadPromise;
299
- });
300
- return memo(loaderResult);
301
- }
302
- }), createComponent(Solid.Match, {
303
- get when() {
304
- return match().status === "error";
305
- },
306
- children: (_) => {
307
- if (isServer ?? router.isServer) {
308
- const currentMatch = Solid.untrack(match);
309
- const RouteErrorComponent = (Solid.untrack(route).options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
310
- return createComponent(RouteErrorComponent, {
311
- get error() {
312
- return currentMatch.error;
313
- },
314
- info: {
315
- componentStack: ""
316
- }
317
- });
318
- }
319
- throw Solid.untrack(match).error;
320
- }
321
- }), createComponent(Solid.Match, {
322
- get when() {
323
- return match().status === "success";
324
- },
325
- get children() {
326
- return keyedOut();
327
- }
328
- })];
329
- }
330
- });
331
- };
332
- const Outlet = () => {
333
- const router = useRouter();
334
- const matchId = Solid.useContext(matchContext);
335
- const routeId = useRouterState({
336
- select: (s) => s.matches.find((d) => d.id === matchId())?.routeId
337
- });
338
- const route = () => router.routesById[routeId()];
339
- const parentGlobalNotFound = useRouterState({
340
- select: (s) => {
341
- const matches = s.matches;
342
- const parentMatch = matches.find((d) => d.id === matchId());
343
- if (!parentMatch) {
344
- return false;
345
- }
346
- return parentMatch.globalNotFound;
347
- }
348
- });
349
- const childMatchId = useRouterState({
350
- select: (s) => {
351
- const matches = s.matches;
352
- const index = matches.findIndex((d) => d.id === matchId());
353
- const v = matches[index + 1]?.id;
354
- return v;
355
- }
356
- });
357
- const childRouteId = useRouterState({
358
- select: (s) => {
359
- const matches = s.matches;
360
- const index = matches.findIndex((d) => d.id === matchId());
361
- return matches[index + 1]?.routeId;
362
- }
363
- });
364
- const childMatchStatus = useRouterState({
365
- select: (s) => {
366
- const matches = s.matches;
367
- const index = matches.findIndex((d) => d.id === matchId());
368
- return matches[index + 1]?.status;
369
- }
370
- });
371
- const shouldShowNotFound = () => childMatchStatus() !== "redirected" && parentGlobalNotFound();
372
- return createComponent(Solid.Show, {
373
- get when() {
374
- return memo(() => !!!shouldShowNotFound())() && childMatchId();
375
- },
376
- get fallback() {
377
- return createComponent(Solid.Show, {
378
- get when() {
379
- return shouldShowNotFound();
380
- },
381
- get children() {
382
- return renderRouteNotFound(router, route(), void 0);
383
- }
384
- });
385
- },
386
- children: (matchIdAccessor) => {
387
- const currentMatchId = Solid.createMemo(() => matchIdAccessor());
388
- return createComponent(Solid.Show, {
389
- get when() {
390
- return routeId() === rootRouteId;
391
- },
392
- get fallback() {
393
- return createComponent(Match, {
394
- get matchId() {
395
- return currentMatchId();
396
- }
397
- });
398
- },
399
- get children() {
400
- return createComponent(Solid.Show, {
401
- get when() {
402
- return childRouteId();
403
- },
404
- keyed: true,
405
- children: (_routeId) => createComponent(Solid.Loading, {
406
- get fallback() {
407
- return createComponent(Dynamic, {
408
- get component() {
409
- return router.options.defaultPendingComponent;
410
- }
411
- });
412
- },
413
- get children() {
414
- return createComponent(Match, {
415
- get matchId() {
416
- return currentMatchId();
417
- }
418
- });
419
- }
420
- })
421
- });
422
- }
423
- });
424
- }
425
- });
148
+ var MatchInner = (props) => {
149
+ 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;
154
+ const remountDeps = (router.routesById[routeId].options.remountDeps ?? router.options.defaultRemountDeps)?.({
155
+ routeId,
156
+ loaderDeps: match.loaderDeps,
157
+ params: match._strictParams,
158
+ search: match._strictSearch
159
+ });
160
+ return {
161
+ key: remountDeps ? JSON.stringify(remountDeps) : void 0,
162
+ routeId,
163
+ match: {
164
+ id: match.id,
165
+ status: match.status,
166
+ error: match.error,
167
+ _forcePending: match._forcePending,
168
+ _displayPending: match._displayPending
169
+ }
170
+ };
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, {
182
+ get when() {
183
+ return componentKey();
184
+ },
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, {
209
+ get when() {
210
+ return match().status === "pending";
211
+ },
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);
226
+ }
227
+ }
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
+ } });
426
293
  };
427
- export {
428
- Match,
429
- MatchInner,
430
- Outlet
294
+ var Outlet = () => {
295
+ 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
+ } });
316
+ const shouldShowNotFound = () => childMatchStatus() !== "redirected" && parentGlobalNotFound();
317
+ return createComponent(Solid.Show, {
318
+ get when() {
319
+ return memo(() => !!!shouldShowNotFound())() && childMatchId();
320
+ },
321
+ get fallback() {
322
+ return createComponent(Solid.Show, {
323
+ get when() {
324
+ return shouldShowNotFound();
325
+ },
326
+ get children() {
327
+ return renderRouteNotFound(router, route(), void 0);
328
+ }
329
+ });
330
+ },
331
+ children: (matchIdAccessor) => {
332
+ const currentMatchId = Solid.createMemo(() => matchIdAccessor());
333
+ return createComponent(Solid.Show, {
334
+ get when() {
335
+ return routeId() === rootRouteId;
336
+ },
337
+ get fallback() {
338
+ return createComponent(Match, { get matchId() {
339
+ return currentMatchId();
340
+ } });
341
+ },
342
+ get children() {
343
+ return createComponent(Solid.Show, {
344
+ get when() {
345
+ return childRouteId();
346
+ },
347
+ keyed: true,
348
+ children: (_routeId) => createComponent(Solid.Loading, {
349
+ get fallback() {
350
+ return createComponent(Dynamic, { get component() {
351
+ return router.options.defaultPendingComponent;
352
+ } });
353
+ },
354
+ get children() {
355
+ return createComponent(Match, { get matchId() {
356
+ return currentMatchId();
357
+ } });
358
+ }
359
+ })
360
+ });
361
+ }
362
+ });
363
+ }
364
+ });
431
365
  };
432
- //# sourceMappingURL=Match.js.map
366
+ //#endregion
367
+ export { Match, Outlet };
368
+
369
+ //# sourceMappingURL=Match.js.map