@real-router/react 0.27.1 → 0.27.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/dist/cjs/Await-D2oCO8nH.d.ts.map +1 -1
- package/dist/cjs/HttpStatusProvider-DfsVxZba.d.ts.map +1 -1
- package/dist/cjs/{Link-CyDwbrFA.js → Link-D4K4T0Ef.js} +2 -2
- package/dist/cjs/{Link-CyDwbrFA.js.map → Link-D4K4T0Ef.js.map} +1 -1
- package/dist/cjs/RouterErrorBoundary-3UhUelqY.d.ts.map +1 -1
- package/dist/cjs/{RouterProvider-CPsCmrRw.js → RouterProvider-CAaKExt_.js} +2 -2
- package/dist/cjs/RouterProvider-CAaKExt_.js.map +1 -0
- package/dist/cjs/createHttpStatusSink-ChfBL87y.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/ink.js +1 -1
- package/dist/cjs/ink.js.map +1 -1
- package/dist/cjs/legacy.js +1 -1
- package/dist/cjs/ssr.js.map +1 -1
- package/dist/cjs/useDeferred-2fAqMTwr.d.ts.map +1 -1
- package/dist/cjs/useRoute-D2vAzKWM.js.map +1 -1
- package/dist/cjs/useRouteEnter-CqO9sPPD.d.ts.map +1 -1
- package/dist/cjs/useRouterTransition-D5nwRENd.d.ts.map +1 -1
- package/dist/esm/Await-D2oCO8nH.d.mts.map +1 -1
- package/dist/esm/HttpStatusProvider-DfsVxZba.d.mts.map +1 -1
- package/dist/esm/{Link-uERoM4yk.mjs → Link-PQIMnFd0.mjs} +2 -2
- package/dist/esm/{Link-uERoM4yk.mjs.map → Link-PQIMnFd0.mjs.map} +1 -1
- package/dist/esm/RouterErrorBoundary-3UhUelqY.d.mts.map +1 -1
- package/dist/esm/{RouterProvider-DgHypQTJ.mjs → RouterProvider-DhZoi6au.mjs} +2 -2
- package/dist/esm/RouterProvider-DhZoi6au.mjs.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/ink.mjs +1 -1
- package/dist/esm/ink.mjs.map +1 -1
- package/dist/esm/legacy.mjs +1 -1
- package/dist/esm/useDeferred-2fAqMTwr.d.mts.map +1 -1
- package/dist/esm/useRouteEnter-CqO9sPPD.d.mts.map +1 -1
- package/dist/esm/useRouterTransition-PCwA_qj1.d.mts.map +1 -1
- package/package.json +7 -8
- package/dist/cjs/RouterProvider-CPsCmrRw.js.map +0 -1
- package/dist/esm/RouterProvider-DgHypQTJ.mjs.map +0 -1
- package/src/RouterProvider.tsx +0 -148
- package/src/components/Await.tsx +0 -46
- package/src/components/ClientOnly.tsx +0 -25
- package/src/components/HttpStatusCode.tsx +0 -66
- package/src/components/HttpStatusProvider.tsx +0 -26
- package/src/components/InkLink.tsx +0 -134
- package/src/components/InkRouterProvider.tsx +0 -9
- package/src/components/Link.tsx +0 -117
- package/src/components/RouterErrorBoundary.tsx +0 -69
- package/src/components/ServerOnly.tsx +0 -26
- package/src/components/Streamed.tsx +0 -30
- package/src/components/modern/RouteView/RouteView.tsx +0 -69
- package/src/components/modern/RouteView/components.tsx +0 -19
- package/src/components/modern/RouteView/helpers.tsx +0 -233
- package/src/components/modern/RouteView/index.ts +0 -8
- package/src/components/modern/RouteView/types.ts +0 -38
- package/src/constants.ts +0 -10
- package/src/context.ts +0 -14
- package/src/hooks/useDeferred.tsx +0 -34
- package/src/hooks/useIsActiveRoute.tsx +0 -47
- package/src/hooks/useNavigator.tsx +0 -15
- package/src/hooks/useRoute.tsx +0 -32
- package/src/hooks/useRouteEnter.tsx +0 -148
- package/src/hooks/useRouteExit.tsx +0 -159
- package/src/hooks/useRouteNode.tsx +0 -37
- package/src/hooks/useRouteUtils.tsx +0 -35
- package/src/hooks/useRouter.tsx +0 -15
- package/src/hooks/useRouterTransition.tsx +0 -17
- package/src/index.react-server.ts +0 -33
- package/src/index.ts +0 -61
- package/src/ink-types.ts +0 -25
- package/src/ink.ts +0 -30
- package/src/legacy.ssr.ts +0 -35
- package/src/legacy.ts +0 -35
- package/src/ssr.react-server.ts +0 -21
- package/src/ssr.ts +0 -43
- package/src/types.ts +0 -40
- package/src/utils/createHttpStatusSink.ts +0 -27
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { Text, useFocus, useInput } from "ink";
|
|
2
|
-
import { memo } from "react";
|
|
3
|
-
|
|
4
|
-
import { EMPTY_OPTIONS, EMPTY_PARAMS } from "../constants";
|
|
5
|
-
import { shallowEqual } from "../dom-utils";
|
|
6
|
-
import { useIsActiveRoute } from "../hooks/useIsActiveRoute";
|
|
7
|
-
import { useRouter } from "../hooks/useRouter";
|
|
8
|
-
|
|
9
|
-
import type { InkLinkProps } from "../ink-types";
|
|
10
|
-
import type { FC } from "react";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Pick the most specific value across focus / active / base priority.
|
|
14
|
-
* Focus wins over active; active wins over base. Each layer falls through
|
|
15
|
-
* to the next when its value is undefined, matching the original explicit
|
|
16
|
-
* if/else cascade for both `color` and `inverse`.
|
|
17
|
-
*/
|
|
18
|
-
function pickPriority<T>(
|
|
19
|
-
isFocused: boolean,
|
|
20
|
-
isRouteActive: boolean,
|
|
21
|
-
focusValue: T | undefined,
|
|
22
|
-
activeValue: T | undefined,
|
|
23
|
-
baseValue: T | undefined,
|
|
24
|
-
): T | undefined {
|
|
25
|
-
if (isFocused) {
|
|
26
|
-
return focusValue ?? activeValue ?? baseValue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (isRouteActive) {
|
|
30
|
-
return activeValue ?? baseValue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return baseValue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function areInkLinkPropsEqual(
|
|
37
|
-
prev: Readonly<InkLinkProps>,
|
|
38
|
-
next: Readonly<InkLinkProps>,
|
|
39
|
-
): boolean {
|
|
40
|
-
return (
|
|
41
|
-
prev.routeName === next.routeName &&
|
|
42
|
-
prev.activeStrict === next.activeStrict &&
|
|
43
|
-
prev.ignoreQueryParams === next.ignoreQueryParams &&
|
|
44
|
-
prev.color === next.color &&
|
|
45
|
-
prev.activeColor === next.activeColor &&
|
|
46
|
-
prev.focusColor === next.focusColor &&
|
|
47
|
-
prev.inverse === next.inverse &&
|
|
48
|
-
prev.activeInverse === next.activeInverse &&
|
|
49
|
-
prev.focusInverse === next.focusInverse &&
|
|
50
|
-
prev.id === next.id &&
|
|
51
|
-
prev.autoFocus === next.autoFocus &&
|
|
52
|
-
prev.onSelect === next.onSelect &&
|
|
53
|
-
prev.children === next.children &&
|
|
54
|
-
shallowEqual(prev.routeParams, next.routeParams) &&
|
|
55
|
-
shallowEqual(prev.routeOptions, next.routeOptions)
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const InkLinkImpl: FC<InkLinkProps> = ({
|
|
60
|
-
routeName,
|
|
61
|
-
routeParams = EMPTY_PARAMS,
|
|
62
|
-
routeOptions = EMPTY_OPTIONS,
|
|
63
|
-
activeStrict = false,
|
|
64
|
-
ignoreQueryParams = true,
|
|
65
|
-
color,
|
|
66
|
-
activeColor,
|
|
67
|
-
focusColor,
|
|
68
|
-
inverse,
|
|
69
|
-
activeInverse,
|
|
70
|
-
focusInverse,
|
|
71
|
-
id,
|
|
72
|
-
autoFocus,
|
|
73
|
-
onSelect,
|
|
74
|
-
children,
|
|
75
|
-
}) => {
|
|
76
|
-
const router = useRouter();
|
|
77
|
-
const { isFocused } = useFocus({
|
|
78
|
-
...(id !== undefined && { id }),
|
|
79
|
-
...(autoFocus !== undefined && { autoFocus }),
|
|
80
|
-
});
|
|
81
|
-
const isRouteActive = useIsActiveRoute(
|
|
82
|
-
routeName,
|
|
83
|
-
routeParams,
|
|
84
|
-
activeStrict,
|
|
85
|
-
ignoreQueryParams,
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
// No useCallback: `useInput` consumes the handler via its own internal
|
|
89
|
-
// ref; a stable identity provides no cache-bail-out benefit here. Same
|
|
90
|
-
// reasoning as Link's handleClick.
|
|
91
|
-
useInput(
|
|
92
|
-
(_input, key) => {
|
|
93
|
-
if (key.return) {
|
|
94
|
-
onSelect?.();
|
|
95
|
-
router.navigate(routeName, routeParams, routeOptions).catch(() => {});
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
{ isActive: isFocused },
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const finalColor = pickPriority(
|
|
102
|
-
isFocused,
|
|
103
|
-
isRouteActive,
|
|
104
|
-
focusColor,
|
|
105
|
-
activeColor,
|
|
106
|
-
color,
|
|
107
|
-
);
|
|
108
|
-
const finalInverse = pickPriority(
|
|
109
|
-
isFocused,
|
|
110
|
-
isRouteActive,
|
|
111
|
-
focusInverse,
|
|
112
|
-
activeInverse,
|
|
113
|
-
inverse,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const textProps: { color?: string; inverse?: boolean } = {};
|
|
117
|
-
|
|
118
|
-
if (finalColor !== undefined) {
|
|
119
|
-
textProps.color = finalColor;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (finalInverse !== undefined) {
|
|
123
|
-
textProps.inverse = finalInverse;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return <Text {...textProps}>{children}</Text>;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export const InkLink: FC<InkLinkProps> = memo(
|
|
130
|
-
InkLinkImpl,
|
|
131
|
-
areInkLinkPropsEqual,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
InkLink.displayName = "InkLink";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { RouterProvider } from "../RouterProvider";
|
|
2
|
-
|
|
3
|
-
import type { InkRouterProviderProps } from "../ink-types";
|
|
4
|
-
import type { FC } from "react";
|
|
5
|
-
|
|
6
|
-
export const InkRouterProvider: FC<InkRouterProviderProps> = ({
|
|
7
|
-
router,
|
|
8
|
-
children,
|
|
9
|
-
}) => <RouterProvider router={router}>{children}</RouterProvider>;
|
package/src/components/Link.tsx
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { memo, useMemo } from "react";
|
|
2
|
-
|
|
3
|
-
import { EMPTY_PARAMS, EMPTY_OPTIONS } from "../constants";
|
|
4
|
-
import {
|
|
5
|
-
shouldNavigate,
|
|
6
|
-
buildHref,
|
|
7
|
-
buildActiveClassName,
|
|
8
|
-
navigateWithHash,
|
|
9
|
-
shallowEqual,
|
|
10
|
-
} from "../dom-utils";
|
|
11
|
-
import { useIsActiveRoute } from "../hooks/useIsActiveRoute";
|
|
12
|
-
import { useRouter } from "../hooks/useRouter";
|
|
13
|
-
|
|
14
|
-
import type { LinkProps } from "../types";
|
|
15
|
-
import type { FC, MouseEvent } from "react";
|
|
16
|
-
|
|
17
|
-
function areLinkPropsEqual(
|
|
18
|
-
prev: Readonly<LinkProps>,
|
|
19
|
-
next: Readonly<LinkProps>,
|
|
20
|
-
): boolean {
|
|
21
|
-
return (
|
|
22
|
-
prev.routeName === next.routeName &&
|
|
23
|
-
prev.className === next.className &&
|
|
24
|
-
prev.activeClassName === next.activeClassName &&
|
|
25
|
-
prev.activeStrict === next.activeStrict &&
|
|
26
|
-
prev.ignoreQueryParams === next.ignoreQueryParams &&
|
|
27
|
-
prev.onClick === next.onClick &&
|
|
28
|
-
prev.target === next.target &&
|
|
29
|
-
prev.style === next.style &&
|
|
30
|
-
prev.children === next.children &&
|
|
31
|
-
prev.hash === next.hash &&
|
|
32
|
-
shallowEqual(prev.routeParams, next.routeParams) &&
|
|
33
|
-
shallowEqual(prev.routeOptions, next.routeOptions)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const LinkImpl: FC<LinkProps> = ({
|
|
38
|
-
routeName,
|
|
39
|
-
routeParams = EMPTY_PARAMS,
|
|
40
|
-
routeOptions = EMPTY_OPTIONS,
|
|
41
|
-
className,
|
|
42
|
-
activeClassName = "active",
|
|
43
|
-
activeStrict = false,
|
|
44
|
-
ignoreQueryParams = true,
|
|
45
|
-
hash,
|
|
46
|
-
onClick,
|
|
47
|
-
target,
|
|
48
|
-
children,
|
|
49
|
-
...props
|
|
50
|
-
}) => {
|
|
51
|
-
// memo + areLinkPropsEqual guarantees that on bail-out the component does
|
|
52
|
-
// not render; on render, routeParams/routeOptions either changed reference
|
|
53
|
-
// (true change) or comparator failed (e.g., BigInt fallback to identity),
|
|
54
|
-
// so they're safe to use directly in hook deps.
|
|
55
|
-
|
|
56
|
-
const router = useRouter();
|
|
57
|
-
|
|
58
|
-
// When `hash` prop is set, active state requires both route AND hash to
|
|
59
|
-
// match (#532). Without this, three tab links sharing routeName="settings"
|
|
60
|
-
// would all be marked active by route-name alone, defeating tab semantics.
|
|
61
|
-
const isActive = useIsActiveRoute(
|
|
62
|
-
routeName,
|
|
63
|
-
routeParams,
|
|
64
|
-
activeStrict,
|
|
65
|
-
ignoreQueryParams,
|
|
66
|
-
hash,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// No useMemo: outer memo()+shallowEqual prevents Link re-render unless a
|
|
70
|
-
// prop actually changed. When this body runs, either `hash` differs from
|
|
71
|
-
// last render or another prop changed — in both cases the `{ hash }` alloc
|
|
72
|
-
// is unavoidable. The useMemo wrapper added one closure + deps slot per
|
|
73
|
-
// render without saving an allocation.
|
|
74
|
-
const hashOption = hash === undefined ? undefined : { hash };
|
|
75
|
-
const href = buildHref(router, routeName, routeParams, hashOption);
|
|
76
|
-
|
|
77
|
-
// useCallback was wasteful: 7 deps recreated the closure on every meaningful
|
|
78
|
-
// render anyway, and `<a onClick>` does not benefit from a stable function
|
|
79
|
-
// identity (no child-memo-bail-out chain past it). Inline arrow function is
|
|
80
|
-
// what React Compiler emits automatically for this shape.
|
|
81
|
-
const handleClick = (evt: MouseEvent<HTMLAnchorElement>) => {
|
|
82
|
-
if (onClick) {
|
|
83
|
-
onClick(evt);
|
|
84
|
-
|
|
85
|
-
if (evt.defaultPrevented) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!shouldNavigate(evt.nativeEvent) || target === "_blank") {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
evt.preventDefault();
|
|
95
|
-
navigateWithHash(router, routeName, routeParams, hash, routeOptions).catch(
|
|
96
|
-
() => {},
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// Memoize the joined class string. parseTokens + Set + join on every render
|
|
101
|
-
// adds up on pages with N Links navigating frequently; deps cover every
|
|
102
|
-
// input the function reads so cache invalidation is exact.
|
|
103
|
-
const finalClassName = useMemo(
|
|
104
|
-
() => buildActiveClassName(isActive, activeClassName, className),
|
|
105
|
-
[isActive, activeClassName, className],
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<a {...props} href={href} className={finalClassName} onClick={handleClick}>
|
|
110
|
-
{children}
|
|
111
|
-
</a>
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const Link: FC<LinkProps> = memo(LinkImpl, areLinkPropsEqual);
|
|
116
|
-
|
|
117
|
-
Link.displayName = "Link";
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { createDismissableError } from "@real-router/sources";
|
|
2
|
-
import {
|
|
3
|
-
useEffect,
|
|
4
|
-
useLayoutEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
useSyncExternalStore,
|
|
8
|
-
} from "react";
|
|
9
|
-
|
|
10
|
-
import { useRouter } from "../hooks/useRouter";
|
|
11
|
-
|
|
12
|
-
import type { RouterError, State } from "@real-router/core";
|
|
13
|
-
import type { ReactElement, ReactNode } from "react";
|
|
14
|
-
|
|
15
|
-
export interface RouterErrorBoundaryProps {
|
|
16
|
-
readonly children: ReactNode;
|
|
17
|
-
readonly fallback: (error: RouterError, resetError: () => void) => ReactNode;
|
|
18
|
-
readonly onError?: (
|
|
19
|
-
error: RouterError,
|
|
20
|
-
toRoute: State | null,
|
|
21
|
-
fromRoute: State | null,
|
|
22
|
-
) => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function RouterErrorBoundary({
|
|
26
|
-
children,
|
|
27
|
-
fallback,
|
|
28
|
-
onError,
|
|
29
|
-
}: RouterErrorBoundaryProps): ReactElement {
|
|
30
|
-
const router = useRouter();
|
|
31
|
-
// Per-router cached in @real-router/sources — the WeakMap lookup is cheap,
|
|
32
|
-
// but useMemo avoids it entirely on stable-router re-renders (the common
|
|
33
|
-
// case for boundaries mounted in app shells).
|
|
34
|
-
const store = useMemo(() => createDismissableError(router), [router]);
|
|
35
|
-
const snapshot = useSyncExternalStore(
|
|
36
|
-
store.subscribe,
|
|
37
|
-
store.getSnapshot,
|
|
38
|
-
store.getSnapshot,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const onErrorRef = useRef(onError);
|
|
42
|
-
|
|
43
|
-
// "Latest ref" pattern shared with useRouteEnter/useRouteExit: sync the
|
|
44
|
-
// callback to the ref via useLayoutEffect (synchronous, post-render,
|
|
45
|
-
// pre-paint) so the snapshot effect below reads the freshest callback
|
|
46
|
-
// without listing `onError` as a dep — and StrictMode's double-effect
|
|
47
|
-
// pass writes the same value twice harmlessly.
|
|
48
|
-
useLayoutEffect(() => {
|
|
49
|
-
onErrorRef.current = onError;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (snapshot.error) {
|
|
54
|
-
onErrorRef.current?.(
|
|
55
|
-
snapshot.error,
|
|
56
|
-
snapshot.toRoute,
|
|
57
|
-
snapshot.fromRoute,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
// eslint-disable-next-line @eslint-react/exhaustive-deps -- onError tracked via ref, snapshot fields accessed inside callback
|
|
61
|
-
}, [snapshot.version]);
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<>
|
|
65
|
-
{children}
|
|
66
|
-
{snapshot.error ? fallback(snapshot.error, snapshot.resetError) : null}
|
|
67
|
-
</>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import type { ReactNode } from "react";
|
|
4
|
-
|
|
5
|
-
export interface ServerOnlyProps {
|
|
6
|
-
readonly children: ReactNode;
|
|
7
|
-
readonly fallback?: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function ServerOnly({
|
|
11
|
-
children,
|
|
12
|
-
fallback = null,
|
|
13
|
-
}: ServerOnlyProps): ReactNode {
|
|
14
|
-
const [mounted, setMounted] = useState(false);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
// SSR/hydration boundary: server emits the children branch, client matches
|
|
18
|
-
// it on first paint, then this effect flips state to swap in the fallback
|
|
19
|
-
// (or hide entirely). The intentional re-render keeps markup consistent
|
|
20
|
-
// across renders.
|
|
21
|
-
// eslint-disable-next-line @eslint-react/set-state-in-effect -- intentional post-hydration swap
|
|
22
|
-
setMounted(true);
|
|
23
|
-
}, []);
|
|
24
|
-
|
|
25
|
-
return mounted ? fallback : children;
|
|
26
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Suspense } from "react";
|
|
2
|
-
|
|
3
|
-
import type { ReactNode } from "react";
|
|
4
|
-
|
|
5
|
-
export interface StreamedProps {
|
|
6
|
-
/** Shown while any descendant `use(promise)` / `<Await>` is pending. */
|
|
7
|
-
readonly fallback: ReactNode;
|
|
8
|
-
readonly children: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Cross-adapter alias for `<Suspense fallback={…}>`. Pairs with `<Await>`
|
|
13
|
-
* for symmetry with `<Streamed>` boundaries in the SvelteKit / Solid
|
|
14
|
-
* deferred-data conventions.
|
|
15
|
-
*
|
|
16
|
-
* ```tsx
|
|
17
|
-
* <Streamed fallback={<Spinner />}>
|
|
18
|
-
* <Await<Review[]> name="reviews">
|
|
19
|
-
* {(reviews) => <ReviewList items={reviews} />}
|
|
20
|
-
* </Await>
|
|
21
|
-
* </Streamed>
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* The component is a thin wrapper around React's native `<Suspense>` — no
|
|
25
|
-
* additional behaviour. Use plain `<Suspense>` directly if you don't need
|
|
26
|
-
* the cross-framework naming alignment.
|
|
27
|
-
*/
|
|
28
|
-
export function Streamed({ fallback, children }: StreamedProps): ReactNode {
|
|
29
|
-
return <Suspense fallback={fallback}>{children}</Suspense>;
|
|
30
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { useMemo, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
import { Match, NotFound, Self } from "./components";
|
|
4
|
-
import { buildRenderList, collectElements } from "./helpers";
|
|
5
|
-
import { useRouteNode } from "../../../hooks/useRouteNode";
|
|
6
|
-
|
|
7
|
-
import type { RouteViewProps } from "./types";
|
|
8
|
-
import type { ReactElement } from "react";
|
|
9
|
-
|
|
10
|
-
function RouteViewRoot({
|
|
11
|
-
nodeName,
|
|
12
|
-
children,
|
|
13
|
-
}: Readonly<RouteViewProps>): ReactElement | null {
|
|
14
|
-
const { route } = useRouteNode(nodeName);
|
|
15
|
-
const hasBeenActivatedRef = useRef<Set<string> | null>(null);
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @eslint-react/refs -- lazy init: assign once when null to avoid `new Set()` allocation on every render
|
|
18
|
-
hasBeenActivatedRef.current ??= new Set();
|
|
19
|
-
|
|
20
|
-
// Skip the Children.forEach + collectElements traversal when the children
|
|
21
|
-
// reference is unchanged. The common SPA case is a stable JSX tree across
|
|
22
|
-
// re-renders, so the cache hits on every render except the first.
|
|
23
|
-
//
|
|
24
|
-
// Streaming SSR caveat: with `renderToReadableStream`, React may invoke
|
|
25
|
-
// RouteView multiple times across chunks with a fresh `children` reference
|
|
26
|
-
// each time. The useMemo misses on each new render and the traversal runs
|
|
27
|
-
// again — this is the expected SSR cost; the alternative would be build-
|
|
28
|
-
// time codegen of the static route tree, which is out of scope here.
|
|
29
|
-
const elements = useMemo(() => {
|
|
30
|
-
const collected: ReactElement[] = [];
|
|
31
|
-
|
|
32
|
-
collectElements(children, collected);
|
|
33
|
-
|
|
34
|
-
return collected;
|
|
35
|
-
}, [children]);
|
|
36
|
-
|
|
37
|
-
if (!route) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const { rendered } = buildRenderList(
|
|
42
|
-
elements,
|
|
43
|
-
route.name,
|
|
44
|
-
nodeName,
|
|
45
|
-
// eslint-disable-next-line @eslint-react/refs -- stable Set ref read for keepAlive tracking (never reassigned)
|
|
46
|
-
hasBeenActivatedRef.current,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
if (rendered.length > 0) {
|
|
50
|
-
return <>{rendered}</>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
RouteViewRoot.displayName = "RouteView";
|
|
57
|
-
|
|
58
|
-
export const RouteView = Object.assign(RouteViewRoot, {
|
|
59
|
-
Match,
|
|
60
|
-
Self,
|
|
61
|
-
NotFound,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export type {
|
|
65
|
-
RouteViewProps,
|
|
66
|
-
MatchProps as RouteViewMatchProps,
|
|
67
|
-
SelfProps as RouteViewSelfProps,
|
|
68
|
-
NotFoundProps as RouteViewNotFoundProps,
|
|
69
|
-
} from "./types";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { MatchProps, NotFoundProps, SelfProps } from "./types";
|
|
2
|
-
|
|
3
|
-
export function Match(_props: MatchProps): null {
|
|
4
|
-
return null;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
Match.displayName = "RouteView.Match";
|
|
8
|
-
|
|
9
|
-
export function Self(_props: SelfProps): null {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
Self.displayName = "RouteView.Self";
|
|
14
|
-
|
|
15
|
-
export function NotFound(_props: NotFoundProps): null {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
NotFound.displayName = "RouteView.NotFound";
|