@tanstack/solid-router 2.0.0-alpha.9 → 2.0.0-beta.10

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 (110) hide show
  1. package/dist/cjs/HeadContent.cjs +2 -2
  2. package/dist/cjs/HeadContent.cjs.map +1 -1
  3. package/dist/cjs/HeadContent.d.cts +5 -1
  4. package/dist/cjs/HeadContent.dev.cjs +2 -2
  5. package/dist/cjs/HeadContent.dev.cjs.map +1 -1
  6. package/dist/cjs/HeadContent.dev.d.cts +2 -1
  7. package/dist/cjs/Match.cjs +19 -11
  8. package/dist/cjs/Match.cjs.map +1 -1
  9. package/dist/cjs/Matches.cjs +2 -4
  10. package/dist/cjs/Matches.cjs.map +1 -1
  11. package/dist/cjs/ScrollRestoration.cjs +1 -11
  12. package/dist/cjs/ScrollRestoration.cjs.map +1 -1
  13. package/dist/cjs/fileRoute.cjs +4 -5
  14. package/dist/cjs/fileRoute.cjs.map +1 -1
  15. package/dist/cjs/headContentUtils.cjs +5 -2
  16. package/dist/cjs/headContentUtils.cjs.map +1 -1
  17. package/dist/cjs/headContentUtils.d.cts +2 -2
  18. package/dist/cjs/not-found.cjs +9 -2
  19. package/dist/cjs/not-found.cjs.map +1 -1
  20. package/dist/cjs/not-found.d.cts +4 -1
  21. package/dist/cjs/renderRouteNotFound.cjs +4 -4
  22. package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
  23. package/dist/cjs/router.cjs +0 -8
  24. package/dist/cjs/router.cjs.map +1 -1
  25. package/dist/cjs/scroll-restoration.cjs +4 -17
  26. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  27. package/dist/cjs/useBlocker.cjs.map +1 -1
  28. package/dist/cjs/useBlocker.d.cts +2 -2
  29. package/dist/cjs/useMatch.cjs +4 -3
  30. package/dist/cjs/useMatch.cjs.map +1 -1
  31. package/dist/cjs/useRouter.cjs +3 -3
  32. package/dist/cjs/useRouter.cjs.map +1 -1
  33. package/dist/esm/HeadContent.d.ts +5 -1
  34. package/dist/esm/HeadContent.dev.d.ts +2 -1
  35. package/dist/esm/HeadContent.dev.js +2 -2
  36. package/dist/esm/HeadContent.dev.js.map +1 -1
  37. package/dist/esm/HeadContent.js +2 -2
  38. package/dist/esm/HeadContent.js.map +1 -1
  39. package/dist/esm/Match.js +21 -11
  40. package/dist/esm/Match.js.map +1 -1
  41. package/dist/esm/Matches.js +2 -3
  42. package/dist/esm/Matches.js.map +1 -1
  43. package/dist/esm/ScrollRestoration.js +2 -12
  44. package/dist/esm/ScrollRestoration.js.map +1 -1
  45. package/dist/esm/fileRoute.js +4 -3
  46. package/dist/esm/fileRoute.js.map +1 -1
  47. package/dist/esm/headContentUtils.d.ts +2 -2
  48. package/dist/esm/headContentUtils.js +6 -3
  49. package/dist/esm/headContentUtils.js.map +1 -1
  50. package/dist/esm/not-found.d.ts +4 -1
  51. package/dist/esm/not-found.js +9 -3
  52. package/dist/esm/not-found.js.map +1 -1
  53. package/dist/esm/renderRouteNotFound.js +3 -2
  54. package/dist/esm/renderRouteNotFound.js.map +1 -1
  55. package/dist/esm/router.js +0 -8
  56. package/dist/esm/router.js.map +1 -1
  57. package/dist/esm/scroll-restoration.js +4 -17
  58. package/dist/esm/scroll-restoration.js.map +1 -1
  59. package/dist/esm/useBlocker.d.ts +2 -2
  60. package/dist/esm/useBlocker.js.map +1 -1
  61. package/dist/esm/useMatch.js +5 -3
  62. package/dist/esm/useMatch.js.map +1 -1
  63. package/dist/esm/useRouter.js +3 -2
  64. package/dist/esm/useRouter.js.map +1 -1
  65. package/dist/source/HeadContent.d.ts +5 -1
  66. package/dist/source/HeadContent.dev.d.ts +2 -1
  67. package/dist/source/HeadContent.dev.jsx +2 -2
  68. package/dist/source/HeadContent.dev.jsx.map +1 -1
  69. package/dist/source/HeadContent.jsx +2 -2
  70. package/dist/source/HeadContent.jsx.map +1 -1
  71. package/dist/source/Match.jsx +34 -15
  72. package/dist/source/Match.jsx.map +1 -1
  73. package/dist/source/Matches.jsx +2 -3
  74. package/dist/source/Matches.jsx.map +1 -1
  75. package/dist/source/ScrollRestoration.jsx +2 -18
  76. package/dist/source/ScrollRestoration.jsx.map +1 -1
  77. package/dist/source/fileRoute.js +4 -3
  78. package/dist/source/fileRoute.js.map +1 -1
  79. package/dist/source/headContentUtils.d.ts +2 -2
  80. package/dist/source/headContentUtils.jsx +12 -4
  81. package/dist/source/headContentUtils.jsx.map +1 -1
  82. package/dist/source/not-found.d.ts +4 -1
  83. package/dist/source/not-found.jsx +17 -4
  84. package/dist/source/not-found.jsx.map +1 -1
  85. package/dist/source/renderRouteNotFound.jsx +4 -3
  86. package/dist/source/renderRouteNotFound.jsx.map +1 -1
  87. package/dist/source/router.js +0 -11
  88. package/dist/source/router.js.map +1 -1
  89. package/dist/source/scroll-restoration.jsx +4 -24
  90. package/dist/source/scroll-restoration.jsx.map +1 -1
  91. package/dist/source/useBlocker.d.ts +2 -2
  92. package/dist/source/useMatch.jsx +7 -3
  93. package/dist/source/useMatch.jsx.map +1 -1
  94. package/dist/source/useRouter.jsx +5 -2
  95. package/dist/source/useRouter.jsx.map +1 -1
  96. package/package.json +6 -7
  97. package/src/HeadContent.dev.tsx +3 -2
  98. package/src/HeadContent.tsx +7 -2
  99. package/src/Match.tsx +44 -16
  100. package/src/Matches.tsx +3 -5
  101. package/src/ScrollRestoration.tsx +2 -22
  102. package/src/fileRoute.ts +7 -8
  103. package/src/headContentUtils.tsx +22 -5
  104. package/src/not-found.tsx +25 -5
  105. package/src/renderRouteNotFound.tsx +6 -6
  106. package/src/router.ts +0 -9
  107. package/src/scroll-restoration.tsx +5 -36
  108. package/src/useBlocker.tsx +2 -2
  109. package/src/useMatch.tsx +9 -6
  110. package/src/useRouter.tsx +7 -5
package/src/Match.tsx CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as Solid from 'solid-js'
2
- import invariant from 'tiny-invariant'
3
- import warning from 'tiny-warning'
4
2
  import {
5
3
  createControlledPromise,
6
4
  getLocationChangeInfo,
5
+ invariant,
7
6
  isNotFound,
8
7
  isRedirect,
9
8
  rootRouteId,
@@ -12,7 +11,7 @@ import { isServer } from '@tanstack/router-core/isServer'
12
11
  import { Dynamic } from '@solidjs/web'
13
12
  import { CatchBoundary, ErrorComponent } from './CatchBoundary'
14
13
  import { useRouter } from './useRouter'
15
- import { CatchNotFound } from './not-found'
14
+ import { CatchNotFound, getNotFound } from './not-found'
16
15
  import { nearestMatchContext } from './matchContext'
17
16
  import { SafeFragment } from './SafeFragment'
18
17
  import { renderRouteNotFound } from './renderRouteNotFound'
@@ -140,31 +139,43 @@ export const Match = (props: { matchId: string }) => {
140
139
  errorComponent={routeErrorComponent() || ErrorComponent}
141
140
  onCatch={(error: Error) => {
142
141
  // Forward not found errors (we don't want to show the error component for these)
143
- if (isNotFound(error)) throw error
144
- warning(
145
- false,
146
- `Error in route match: ${currentMatchState().routeId}`,
147
- )
142
+ const notFoundError = getNotFound(error)
143
+ if (notFoundError) {
144
+ notFoundError.routeId ??= currentMatchState()
145
+ .routeId as any
146
+ throw notFoundError
147
+ }
148
+ if (process.env.NODE_ENV !== 'production') {
149
+ console.warn(
150
+ `Warning: Error in route match: ${currentMatchState().routeId}`,
151
+ )
152
+ }
148
153
  routeOnCatch()?.(error)
149
154
  }}
150
155
  >
151
156
  <Dynamic
152
157
  component={ResolvedNotFoundBoundary()}
153
158
  fallback={(error: any) => {
159
+ const notFoundError = getNotFound(error) ?? error
160
+
161
+ notFoundError.routeId ??= currentMatchState()
162
+ .routeId as any
163
+
154
164
  // If the current not found handler doesn't exist or it has a
155
165
  // route ID which doesn't match the current route, rethrow the error
156
166
  if (
157
167
  !routeNotFoundComponent() ||
158
- (error.routeId &&
159
- error.routeId !== currentMatchState().routeId) ||
160
- (!error.routeId && !route().isRoot)
168
+ (notFoundError.routeId &&
169
+ notFoundError.routeId !==
170
+ currentMatchState().routeId) ||
171
+ (!notFoundError.routeId && !route().isRoot)
161
172
  )
162
- throw error
173
+ throw notFoundError
163
174
 
164
175
  return (
165
176
  <Dynamic
166
177
  component={routeNotFoundComponent()}
167
- {...error}
178
+ {...notFoundError}
168
179
  />
169
180
  )
170
181
  }}
@@ -192,7 +203,10 @@ export const Match = (props: { matchId: string }) => {
192
203
  {currentMatchState().parentRouteId === rootRouteId ? (
193
204
  <>
194
205
  <OnRendered />
195
- <ScrollRestoration />
206
+ {router.options.scrollRestoration &&
207
+ (isServer ?? router.isServer) ? (
208
+ <ScrollRestoration />
209
+ ) : null}
196
210
  </>
197
211
  ) : null}
198
212
  </Dynamic>
@@ -392,7 +406,14 @@ export const MatchInner = (): any => {
392
406
  <Solid.Match when={currentMatch().status === 'notFound'}>
393
407
  {(_) => {
394
408
  const matchError = Solid.untrack(() => currentMatch().error)
395
- invariant(isNotFound(matchError), 'Expected a notFound error')
409
+ if (!isNotFound(matchError)) {
410
+ if (process.env.NODE_ENV !== 'production') {
411
+ throw new Error(
412
+ 'Invariant failed: Expected a notFound error',
413
+ )
414
+ }
415
+ invariant()
416
+ }
396
417
 
397
418
  // Use Show with keyed to ensure re-render when routeId changes
398
419
  return (
@@ -409,7 +430,14 @@ export const MatchInner = (): any => {
409
430
  <Solid.Match when={currentMatch().status === 'redirected'}>
410
431
  {(_) => {
411
432
  const matchError = Solid.untrack(() => currentMatch().error)
412
- invariant(isRedirect(matchError), 'Expected a redirect error')
433
+ if (!isRedirect(matchError)) {
434
+ if (process.env.NODE_ENV !== 'production') {
435
+ throw new Error(
436
+ 'Invariant failed: Expected a redirect error',
437
+ )
438
+ }
439
+ invariant()
440
+ }
413
441
 
414
442
  return null
415
443
  }}
package/src/Matches.tsx CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as Solid from 'solid-js'
2
- import warning from 'tiny-warning'
3
2
  import { replaceEqualDeep, rootRouteId } from '@tanstack/router-core'
4
3
  import { isServer } from '@tanstack/router-core/isServer'
5
4
  import { CatchBoundary, ErrorComponent } from './CatchBoundary'
@@ -117,11 +116,10 @@ function MatchesInner() {
117
116
  onCatch={
118
117
  process.env.NODE_ENV !== 'production'
119
118
  ? (error) => {
120
- warning(
121
- false,
122
- `The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
119
+ console.warn(
120
+ `Warning: The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
123
121
  )
124
- warning(false, error.message || error.toString())
122
+ console.warn(`Warning: ${error.message || error.toString()}`)
125
123
  }
126
124
  : undefined
127
125
  }
@@ -1,7 +1,5 @@
1
1
  import {
2
- defaultGetScrollRestorationKey,
3
- getCssSelector,
4
- scrollRestorationCache,
2
+ getElementScrollRestorationEntry,
5
3
  setupScrollRestoration,
6
4
  } from '@tanstack/router-core'
7
5
  import { useRouter } from './useRouter'
@@ -47,23 +45,5 @@ export function useElementScrollRestoration(
47
45
  ): ScrollRestorationEntry | undefined {
48
46
  useScrollRestoration()
49
47
 
50
- const router = useRouter()
51
- const getKey = options.getKey || defaultGetScrollRestorationKey
52
-
53
- let elementSelector = ''
54
-
55
- if (options.id) {
56
- elementSelector = `[data-scroll-restoration-id="${options.id}"]`
57
- } else {
58
- const element = options.getElement?.()
59
- if (!element) {
60
- return
61
- }
62
- elementSelector =
63
- element instanceof Window ? 'window' : getCssSelector(element)
64
- }
65
-
66
- const restoreKey = getKey(router.latestLocation)
67
- const byKey = scrollRestorationCache?.state[restoreKey]
68
- return byKey?.[elementSelector]
48
+ return getElementScrollRestorationEntry(useRouter(), options)
69
49
  }
package/src/fileRoute.ts CHANGED
@@ -1,4 +1,3 @@
1
- import warning from 'tiny-warning'
2
1
  import { createRoute } from './route'
3
2
 
4
3
  import { useMatch } from './useMatch'
@@ -140,10 +139,11 @@ export class FileRoute<
140
139
  THandlers
141
140
  > => {
142
141
  if (process.env.NODE_ENV !== 'production') {
143
- warning(
144
- this.silent,
145
- 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
146
- )
142
+ if (!this.silent) {
143
+ console.warn(
144
+ 'Warning: FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
145
+ )
146
+ }
147
147
  }
148
148
  const route = createRoute(options as any)
149
149
  ;(route as any).isRoot = false
@@ -177,9 +177,8 @@ export function FileRouteLoader<
177
177
  >,
178
178
  ) => TLoaderFn {
179
179
  if (process.env.NODE_ENV !== 'production') {
180
- warning(
181
- false,
182
- `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
180
+ console.warn(
181
+ `Warning: FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
183
182
  )
184
183
  }
185
184
  return (loaderFn) => loaderFn as any
@@ -1,13 +1,20 @@
1
1
  import * as Solid from 'solid-js'
2
- import { escapeHtml } from '@tanstack/router-core'
2
+ import {
3
+ escapeHtml,
4
+ getAssetCrossOrigin,
5
+ resolveManifestAssetLink,
6
+ } from '@tanstack/router-core'
3
7
  import { useRouter } from './useRouter'
4
- import type { RouterManagedTag } from '@tanstack/router-core'
8
+ import type {
9
+ AssetCrossOriginConfig,
10
+ RouterManagedTag,
11
+ } from '@tanstack/router-core'
5
12
 
6
13
  /**
7
14
  * Build the list of head/link/meta/script tags to render for active matches.
8
15
  * Used internally by `HeadContent`.
9
16
  */
10
- export const useTags = () => {
17
+ export const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {
11
18
  const router = useRouter()
12
19
  const nonce = router.options.ssr?.nonce
13
20
  const getTagKey = (tag: RouterManagedTag) => JSON.stringify(tag)
@@ -117,7 +124,13 @@ export const useTags = () => {
117
124
  (asset) =>
118
125
  ({
119
126
  tag: 'link',
120
- attrs: { ...asset.attrs, nonce },
127
+ attrs: {
128
+ ...asset.attrs,
129
+ crossOrigin:
130
+ getAssetCrossOrigin(assetCrossOrigin, 'stylesheet') ??
131
+ asset.attrs?.crossOrigin,
132
+ nonce,
133
+ },
121
134
  }) satisfies RouterManagedTag,
122
135
  )
123
136
 
@@ -134,11 +147,15 @@ export const useTags = () => {
134
147
  router.ssr?.manifest?.routes[route.id]?.preloads
135
148
  ?.filter(Boolean)
136
149
  .forEach((preload) => {
150
+ const preloadLink = resolveManifestAssetLink(preload)
137
151
  preloadLinks.push({
138
152
  tag: 'link',
139
153
  attrs: {
140
154
  rel: 'modulepreload',
141
- href: preload,
155
+ href: preloadLink.href,
156
+ crossOrigin:
157
+ getAssetCrossOrigin(assetCrossOrigin, 'modulepreload') ??
158
+ preloadLink.crossOrigin,
142
159
  nonce,
143
160
  },
144
161
  })
package/src/not-found.tsx CHANGED
@@ -4,9 +4,25 @@ import { CatchBoundary } from './CatchBoundary'
4
4
  import { useRouter } from './useRouter'
5
5
  import type { NotFoundError } from '@tanstack/router-core'
6
6
 
7
+ // Solid wraps non-Error throws in an Error and stores the original thrown value
8
+ // on `cause`, so component-thrown `notFound()` needs one extra unwrapping step.
9
+ export function getNotFound(
10
+ error: unknown,
11
+ ): (NotFoundError & { isNotFound: true }) | undefined {
12
+ if (isNotFound(error)) {
13
+ return error as NotFoundError & { isNotFound: true }
14
+ }
15
+
16
+ if (isNotFound((error as any)?.cause)) {
17
+ return (error as any).cause as NotFoundError & { isNotFound: true }
18
+ }
19
+
20
+ return undefined
21
+ }
22
+
7
23
  export function CatchNotFound(props: {
8
24
  fallback?: (error: NotFoundError) => Solid.JSX.Element
9
- onCatch?: (error: Error) => void
25
+ onCatch?: (error: NotFoundError) => void
10
26
  children: Solid.JSX.Element
11
27
  }) {
12
28
  const router = useRouter()
@@ -18,15 +34,19 @@ export function CatchNotFound(props: {
18
34
  <CatchBoundary
19
35
  getResetKey={() => `not-found-${pathname()}-${status()}`}
20
36
  onCatch={(error) => {
21
- if (isNotFound(error)) {
22
- props.onCatch?.(error)
37
+ const notFoundError = getNotFound(error)
38
+
39
+ if (notFoundError) {
40
+ props.onCatch?.(notFoundError)
23
41
  } else {
24
42
  throw error
25
43
  }
26
44
  }}
27
45
  errorComponent={({ error }) => {
28
- if (isNotFound(error)) {
29
- return props.fallback?.(error)
46
+ const notFoundError = getNotFound(error)
47
+
48
+ if (notFoundError) {
49
+ return props.fallback?.(notFoundError)
30
50
  } else {
31
51
  throw error
32
52
  }
@@ -1,4 +1,3 @@
1
- import warning from 'tiny-warning'
2
1
  import { DefaultGlobalNotFound } from './not-found'
3
2
  import type { AnyRoute, AnyRouter } from '@tanstack/router-core'
4
3
 
@@ -20,11 +19,12 @@ export function renderRouteNotFound(
20
19
  return <router.options.defaultNotFoundComponent {...data} />
21
20
  }
22
21
 
23
- if (process.env.NODE_ENV === 'development') {
24
- warning(
25
- route.options.notFoundComponent,
26
- `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,
27
- )
22
+ if (process.env.NODE_ENV !== 'production') {
23
+ if (!route.options.notFoundComponent) {
24
+ console.warn(
25
+ `Warning: A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,
26
+ )
27
+ }
28
28
  }
29
29
 
30
30
  return <DefaultGlobalNotFound />
package/src/router.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { RouterCore } from '@tanstack/router-core'
2
- import { createFileRoute, createLazyFileRoute } from './fileRoute'
3
2
  import { getStoreFactory } from './routerStores'
4
3
  import type { RouterHistory } from '@tanstack/history'
5
4
  import type {
@@ -103,11 +102,3 @@ export class Router<
103
102
  super(options, getStoreFactory)
104
103
  }
105
104
  }
106
-
107
- if (typeof globalThis !== 'undefined') {
108
- ;(globalThis as any).createFileRoute = createFileRoute
109
- ;(globalThis as any).createLazyFileRoute = createLazyFileRoute
110
- } else if (typeof window !== 'undefined') {
111
- ;(window as any).createFileRoute = createFileRoute
112
- ;(window as any).createLazyFileRoute = createLazyFileRoute
113
- }
@@ -1,45 +1,14 @@
1
- import {
2
- defaultGetScrollRestorationKey,
3
- escapeHtml,
4
- restoreScroll,
5
- storageKey,
6
- } from '@tanstack/router-core'
7
- import { isServer } from '@tanstack/router-core/isServer'
1
+ import { getScrollRestorationScriptForRouter } from '@tanstack/router-core/scroll-restoration-script'
8
2
  import { useRouter } from './useRouter'
9
3
  import { ScriptOnce } from './ScriptOnce'
10
4
 
11
5
  export function ScrollRestoration() {
12
6
  const router = useRouter()
13
- if (!router.isScrollRestoring || !(isServer ?? router.isServer)) {
14
- return null
15
- }
16
- if (typeof router.options.scrollRestoration === 'function') {
17
- const shouldRestore = router.options.scrollRestoration({
18
- location: router.latestLocation,
19
- })
20
- if (!shouldRestore) {
21
- return null
22
- }
23
- }
24
- const getKey =
25
- router.options.getScrollRestorationKey || defaultGetScrollRestorationKey
26
- const userKey = getKey(router.latestLocation)
27
- const resolvedKey =
28
- userKey !== defaultGetScrollRestorationKey(router.latestLocation)
29
- ? userKey
30
- : undefined
7
+ const script = getScrollRestorationScriptForRouter(router)
31
8
 
32
- const restoreScrollOptions: Parameters<typeof restoreScroll>[0] = {
33
- storageKey,
34
- shouldScrollRestoration: true,
35
- }
36
- if (resolvedKey) {
37
- restoreScrollOptions.key = resolvedKey
9
+ if (!script) {
10
+ return null
38
11
  }
39
12
 
40
- return (
41
- <ScriptOnce
42
- children={`(${restoreScroll.toString()})(${escapeHtml(JSON.stringify(restoreScrollOptions))})`}
43
- />
44
- )
13
+ return <ScriptOnce children={script} />
45
14
  }
@@ -13,12 +13,12 @@ import type {
13
13
  RegisteredRouter,
14
14
  } from '@tanstack/router-core'
15
15
 
16
- interface ShouldBlockFnLocation<
16
+ type ShouldBlockFnLocation<
17
17
  out TRouteId,
18
18
  out TFullPath,
19
19
  out TAllParams,
20
20
  out TFullSearchSchema,
21
- > {
21
+ > = {
22
22
  routeId: TRouteId
23
23
  fullPath: TFullPath
24
24
  pathname: string
package/src/useMatch.tsx CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as Solid from 'solid-js'
2
- import invariant from 'tiny-invariant'
3
- import { replaceEqualDeep } from '@tanstack/router-core'
2
+ import { invariant, replaceEqualDeep } from '@tanstack/router-core'
4
3
  import { nearestMatchContext } from './matchContext'
5
4
  import { useRouter } from './useRouter'
6
5
  import type {
@@ -100,10 +99,14 @@ export function useMatch<
100
99
  : (nearestMatch?.hasPending() ?? false)
101
100
  const isTransitioning = router.stores.isTransitioning.state
102
101
 
103
- invariant(
104
- !(!hasPendingMatch && !isTransitioning && (opts.shouldThrow ?? true)),
105
- `Could not find ${opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`,
106
- )
102
+ if (!hasPendingMatch && !isTransitioning && (opts.shouldThrow ?? true)) {
103
+ if (process.env.NODE_ENV !== 'production') {
104
+ throw new Error(
105
+ `Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`,
106
+ )
107
+ }
108
+ invariant()
109
+ }
107
110
  return undefined
108
111
  }
109
112
 
package/src/useRouter.tsx CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as Solid from 'solid-js'
2
- import warning from 'tiny-warning'
3
2
  import { routerContext } from './routerContext'
4
3
  import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
5
4
 
@@ -7,9 +6,12 @@ export function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
7
6
  warn?: boolean
8
7
  }): TRouter {
9
8
  const value = Solid.useContext(routerContext as any)
10
- warning(
11
- !((opts?.warn ?? true) && !value),
12
- 'useRouter must be used inside a <RouterProvider> component!',
13
- )
9
+ if (process.env.NODE_ENV !== 'production') {
10
+ if ((opts?.warn ?? true) && !value) {
11
+ console.warn(
12
+ 'Warning: useRouter must be used inside a <RouterProvider> component!',
13
+ )
14
+ }
15
+ }
14
16
  return value as any
15
17
  }