@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/dist/cjs/lazyRouteComponent.cjs +29 -1
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
- package/dist/cjs/lazyRouteComponent.d.cts +6 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -0
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -1
- package/dist/esm/lazyRouteComponent.d.ts +6 -1
- package/dist/esm/lazyRouteComponent.js +30 -2
- package/dist/esm/lazyRouteComponent.js.map +1 -1
- package/dist/esm/route.d.ts +1 -0
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +1 -1
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/lazyRouteComponent.tsx +32 -0
- package/src/route.ts +1 -1
- package/src/router.ts +8 -6
package/package.json
CHANGED
|
@@ -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:
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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,
|