@tanstack/solid-router 1.121.0 → 1.121.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-router",
3
- "version": "1.121.0",
3
+ "version": "1.121.3",
4
4
  "description": "Modern and scalable routing for Solid applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -61,7 +61,7 @@
61
61
  "tiny-invariant": "^1.3.3",
62
62
  "tiny-warning": "^1.0.3",
63
63
  "@tanstack/history": "1.120.17",
64
- "@tanstack/router-core": "1.121.0"
64
+ "@tanstack/router-core": "1.121.2"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@solidjs/testing-library": "^0.8.10",
package/src/Matches.tsx CHANGED
@@ -170,12 +170,12 @@ export function MatchRoute<
170
170
  {(_) => {
171
171
  const matchRoute = useMatchRoute()
172
172
  const params = matchRoute(props as any)() as boolean
173
-
174
- if (typeof props.children === 'function') {
175
- return (props.children as any)(params)
173
+ const child = props.children
174
+ if (typeof child === 'function') {
175
+ return (child as any)(params)
176
176
  }
177
177
 
178
- return params ? props.children : null
178
+ return params ? child : null
179
179
  }}
180
180
  </Solid.Show>
181
181
  )
package/src/link.tsx CHANGED
@@ -62,7 +62,6 @@ export function useLinkProps<
62
62
  'startTransition',
63
63
  'resetScroll',
64
64
  'viewTransition',
65
- 'children',
66
65
  'target',
67
66
  'disabled',
68
67
  'style',
@@ -250,7 +249,6 @@ export function useLinkProps<
250
249
  },
251
250
  },
252
251
  Solid.splitProps(local, [
253
- 'children',
254
252
  'target',
255
253
  'disabled',
256
254
  'style',
@@ -294,7 +292,7 @@ export function useLinkProps<
294
292
  startTransition: local.startTransition,
295
293
  viewTransition: local.viewTransition,
296
294
  ignoreBlocker: local.ignoreBlocker,
297
- } as any)
295
+ })
298
296
  }
299
297
  }
300
298
 
@@ -545,29 +543,37 @@ export interface LinkComponentRoute<
545
543
  export function createLink<const TComp>(
546
544
  Comp: Constrain<TComp, any, (props: CreateLinkProps) => Solid.JSX.Element>,
547
545
  ): LinkComponent<TComp> {
548
- return (props) => <Link {...(props as any)} _asChild={Comp} />
546
+ return (props) => <Link {...props} _asChild={Comp} />
549
547
  }
550
548
 
551
- export const Link: LinkComponent<'a'> = (props: any) => {
552
- const [local, rest] = Solid.splitProps(props, ['_asChild'])
549
+ export const Link: LinkComponent<'a'> = (props) => {
550
+ const [local, rest] = Solid.splitProps(
551
+ props as typeof props & { _asChild: any },
552
+ ['_asChild', 'children'],
553
+ )
553
554
 
554
555
  const [_, linkProps] = Solid.splitProps(
555
556
  useLinkProps(rest as unknown as any),
556
- ['type', 'children'],
557
+ ['type'],
557
558
  )
558
559
 
559
- const children = () =>
560
- typeof rest.children === 'function'
561
- ? rest.children({
562
- get isActive() {
563
- return (linkProps as any)['data-status'] === 'active'
564
- },
565
- })
566
- : rest.children
560
+ const children = Solid.createMemo(() => {
561
+ const ch = local.children
562
+ if (typeof ch === 'function') {
563
+ return ch({
564
+ get isActive() {
565
+ return (linkProps as any)['data-status'] === 'active'
566
+ },
567
+ isTransitioning: false,
568
+ })
569
+ }
570
+
571
+ return ch satisfies Solid.JSX.Element
572
+ })
567
573
 
568
574
  return (
569
575
  <Dynamic component={local._asChild ? local._asChild : 'a'} {...linkProps}>
570
- {children}
576
+ {children()}
571
577
  </Dynamic>
572
578
  )
573
579
  }
@@ -112,20 +112,25 @@ function _resolveBlockerOpts(
112
112
  }
113
113
  }
114
114
 
115
- const shouldBlock = Boolean(opts.condition ?? true)
116
- const fn = opts.blockerFn
115
+ const shouldBlock = Solid.createMemo(() => Boolean(opts.condition ?? true))
117
116
 
118
117
  const _customBlockerFn = async () => {
119
- if (shouldBlock && fn !== undefined) {
120
- return await fn()
118
+ if (shouldBlock() && opts.blockerFn !== undefined) {
119
+ return await opts.blockerFn()
121
120
  }
122
- return shouldBlock
121
+ return shouldBlock()
123
122
  }
124
123
 
125
124
  return {
126
- shouldBlockFn: _customBlockerFn,
127
- enableBeforeUnload: shouldBlock,
128
- withResolver: fn === undefined,
125
+ get shouldBlockFn() {
126
+ return _customBlockerFn
127
+ },
128
+ get enableBeforeUnload() {
129
+ return shouldBlock()
130
+ },
131
+ get withResolver() {
132
+ return opts.blockerFn === undefined
133
+ },
129
134
  }
130
135
  }
131
136
 
@@ -155,15 +160,16 @@ export function useBlocker(
155
160
  opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,
156
161
  condition?: boolean | any,
157
162
  ): Solid.Accessor<BlockerResolver> | void {
158
- const {
159
- shouldBlockFn,
160
- enableBeforeUnload = true,
161
- disabled = false,
162
- withResolver = false,
163
- } = _resolveBlockerOpts(opts, condition)
163
+ const props = Solid.mergeProps(
164
+ {
165
+ enableBeforeUnload: true,
166
+ disabled: false,
167
+ withResolver: false,
168
+ },
169
+ _resolveBlockerOpts(opts, condition),
170
+ )
164
171
 
165
172
  const router = useRouter()
166
- const { history } = router
167
173
 
168
174
  const [resolver, setResolver] = Solid.createSignal<BlockerResolver>({
169
175
  status: 'idle',
@@ -199,12 +205,12 @@ export function useBlocker(
199
205
  const current = getLocation(blockerFnArgs.currentLocation)
200
206
  const next = getLocation(blockerFnArgs.nextLocation)
201
207
 
202
- const shouldBlock = await shouldBlockFn({
208
+ const shouldBlock = await props.shouldBlockFn({
203
209
  action: blockerFnArgs.action,
204
210
  current,
205
211
  next,
206
212
  })
207
- if (!withResolver) {
213
+ if (!props.withResolver) {
208
214
  return shouldBlock
209
215
  }
210
216
 
@@ -236,9 +242,14 @@ export function useBlocker(
236
242
  return canNavigateAsync
237
243
  }
238
244
 
239
- return disabled
245
+ const disposeBlock = props.disabled
240
246
  ? undefined
241
- : history.block({ blockerFn: blockerFnComposed, enableBeforeUnload })
247
+ : router.history.block({
248
+ blockerFn: blockerFnComposed,
249
+ enableBeforeUnload: props.enableBeforeUnload,
250
+ })
251
+
252
+ Solid.onCleanup(() => disposeBlock?.())
242
253
  })
243
254
 
244
255
  return resolver
@@ -248,23 +259,26 @@ const _resolvePromptBlockerArgs = (
248
259
  props: PromptProps | LegacyPromptProps,
249
260
  ): UseBlockerOpts => {
250
261
  if ('shouldBlockFn' in props) {
251
- return { ...props }
262
+ return props
252
263
  }
253
264
 
254
- const shouldBlock = Boolean(props.condition ?? true)
255
- const fn = props.blockerFn
265
+ const shouldBlock = Solid.createMemo(() => Boolean(props.condition ?? true))
256
266
 
257
267
  const _customBlockerFn = async () => {
258
- if (shouldBlock && fn !== undefined) {
259
- return await fn()
268
+ if (shouldBlock() && props.blockerFn !== undefined) {
269
+ return await props.blockerFn()
260
270
  }
261
271
  return shouldBlock
262
272
  }
263
273
 
264
274
  return {
265
275
  shouldBlockFn: _customBlockerFn,
266
- enableBeforeUnload: shouldBlock,
267
- withResolver: fn === undefined,
276
+ get enableBeforeUnload() {
277
+ return shouldBlock()
278
+ },
279
+ get withResolver() {
280
+ return props.blockerFn === undefined
281
+ },
268
282
  }
269
283
  }
270
284
 
@@ -279,15 +293,17 @@ export function Block<
279
293
  export function Block(opts: LegacyPromptProps): SolidNode
280
294
 
281
295
  export function Block(opts: PromptProps | LegacyPromptProps): SolidNode {
282
- const { children, ...rest } = opts
296
+ const [propsWithChildren, rest] = Solid.splitProps(opts, ['children'])
283
297
  const args = _resolvePromptBlockerArgs(rest)
284
298
 
285
299
  const resolver = useBlocker(args)
286
- return children
287
- ? typeof children === 'function'
288
- ? children(resolver as any)
289
- : children
290
- : null
300
+ const children = Solid.createMemo(() => {
301
+ const child = propsWithChildren.children
302
+ if (resolver && typeof child === 'function') return child(resolver())
303
+ return child
304
+ })
305
+
306
+ return <>{children()}</>
291
307
  }
292
308
 
293
309
  type LegacyPromptProps = {