@tanstack/react-router 1.58.17 → 1.59.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.58.17",
3
+ "version": "1.59.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react'
2
+ import { Outlet } from './Match'
2
3
  import type { AsyncRouteComponent } from './route'
3
4
 
4
5
  // If the load fails due to module not found, it may mean a new version of
@@ -13,12 +14,32 @@ function isModuleNotFoundError(error: any): boolean {
13
14
  )
14
15
  }
15
16
 
17
+ export function ClientOnly({
18
+ children,
19
+ fallback = null,
20
+ }: React.PropsWithChildren<{ fallback?: React.ReactNode }>) {
21
+ return useHydrated() ? <>{children}</> : <>{fallback}</>
22
+ }
23
+
24
+ function subscribe() {
25
+ return () => {}
26
+ }
27
+
28
+ export function useHydrated() {
29
+ return React.useSyncExternalStore(
30
+ subscribe,
31
+ () => true,
32
+ () => false,
33
+ )
34
+ }
35
+
16
36
  export function lazyRouteComponent<
17
37
  T extends Record<string, any>,
18
38
  TKey extends keyof T = 'default',
19
39
  >(
20
40
  importer: () => Promise<T>,
21
41
  exportName?: TKey,
42
+ ssr?: () => boolean,
22
43
  ): T[TKey] extends (props: infer TProps) => any
23
44
  ? AsyncRouteComponent<TProps>
24
45
  : never {
@@ -27,6 +48,10 @@ export function lazyRouteComponent<
27
48
  let error: any
28
49
 
29
50
  const load = () => {
51
+ if (typeof document === 'undefined' && ssr?.() === false) {
52
+ comp = (() => null) as any
53
+ return Promise.resolve()
54
+ }
30
55
  if (!loadPromise) {
31
56
  loadPromise = importer()
32
57
  .then((res) => {
@@ -81,6 +106,13 @@ export function lazyRouteComponent<
81
106
  throw load()
82
107
  }
83
108
 
109
+ if (ssr?.() === false) {
110
+ return (
111
+ <ClientOnly fallback={<Outlet />}>
112
+ {React.createElement(comp, props)}
113
+ </ClientOnly>
114
+ )
115
+ }
84
116
  return React.createElement(comp, props)
85
117
  }
86
118
 
package/src/route.ts CHANGED
@@ -321,7 +321,6 @@ export interface UpdatableRouteOptions<
321
321
  in out TRouteContextFn,
322
322
  in out TBeforeLoadFn,
323
323
  > extends UpdatableStaticRouteOption {
324
- // test?: (args: TAllContext) => void
325
324
  // If true, this route will be matched as case-sensitive
326
325
  caseSensitive?: boolean
327
326
  // If true, this route will be forcefully wrapped in a suspense boundary
@@ -439,6 +438,7 @@ export interface UpdatableRouteOptions<
439
438
  headers?: (ctx: {
440
439
  loaderData: ResolveLoaderData<TLoaderFn>
441
440
  }) => Record<string, string>
441
+ ssr?: boolean
442
442
  }
443
443
 
444
444
  interface RequiredStaticDataRouteOption {
package/src/router.ts CHANGED
@@ -581,12 +581,14 @@ export function createRouter<
581
581
  TDehydrated extends Record<string, any> = Record<string, any>,
582
582
  TSerializedError extends Record<string, any> = Record<string, any>,
583
583
  >(
584
- options: RouterConstructorOptions<
585
- TRouteTree,
586
- TTrailingSlashOption,
587
- TDehydrated,
588
- TSerializedError
589
- >,
584
+ options: undefined extends number
585
+ ? 'strictNullChecks must be enabled in tsconfig.json'
586
+ : RouterConstructorOptions<
587
+ TRouteTree,
588
+ TTrailingSlashOption,
589
+ TDehydrated,
590
+ TSerializedError
591
+ >,
590
592
  ) {
591
593
  return new Router<
592
594
  TRouteTree,