@real-router/react 0.24.1 → 0.25.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.
Files changed (123) hide show
  1. package/README.md +127 -7
  2. package/dist/cjs/Await-whr-pcvo.d.ts +41 -0
  3. package/dist/cjs/Await-whr-pcvo.d.ts.map +1 -0
  4. package/dist/cjs/HttpStatusProvider-Dh6cMr95.d.ts +143 -0
  5. package/dist/cjs/HttpStatusProvider-Dh6cMr95.d.ts.map +1 -0
  6. package/dist/cjs/Link-BspioC76.js +2 -0
  7. package/dist/cjs/Link-BspioC76.js.map +1 -0
  8. package/dist/cjs/RouterErrorBoundary-BlJmaoyr.d.ts +47 -0
  9. package/dist/cjs/RouterErrorBoundary-BlJmaoyr.d.ts.map +1 -0
  10. package/dist/cjs/{RouterProvider-Bj1_NbpA.d.ts → RouterProvider-DvC9mViF.d.ts} +2 -2
  11. package/dist/cjs/RouterProvider-DvC9mViF.d.ts.map +1 -0
  12. package/dist/cjs/RouterProvider-fJvMO5Tc.js +2 -0
  13. package/dist/cjs/RouterProvider-fJvMO5Tc.js.map +1 -0
  14. package/dist/cjs/createHttpStatusSink-D_6IiR5E.js +2 -0
  15. package/dist/cjs/createHttpStatusSink-D_6IiR5E.js.map +1 -0
  16. package/dist/cjs/index.d.ts +6 -281
  17. package/dist/cjs/index.js +1 -1
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/index.react-server.d.ts +5 -0
  20. package/dist/cjs/index.react-server.js +0 -0
  21. package/dist/cjs/ink.d.ts +2 -1
  22. package/dist/cjs/ink.d.ts.map +1 -1
  23. package/dist/cjs/ink.js +1 -1
  24. package/dist/cjs/ink.js.map +1 -1
  25. package/dist/cjs/legacy.d.ts +3 -2
  26. package/dist/cjs/legacy.js +1 -1
  27. package/dist/cjs/legacy.ssr.d.ts +3 -0
  28. package/dist/cjs/legacy.ssr.js +1 -0
  29. package/dist/cjs/ssr.d.ts +4 -0
  30. package/dist/cjs/ssr.js +2 -0
  31. package/dist/cjs/ssr.js.map +1 -0
  32. package/dist/cjs/ssr.react-server.d.ts +3 -0
  33. package/dist/cjs/ssr.react-server.js +0 -0
  34. package/dist/cjs/useDeferred-DE5YUsfa.d.ts +24 -0
  35. package/dist/cjs/useDeferred-DE5YUsfa.d.ts.map +1 -0
  36. package/dist/cjs/useRoute-Dudo2K_0.js +2 -0
  37. package/dist/cjs/useRoute-Dudo2K_0.js.map +1 -0
  38. package/dist/cjs/useRouteEnter-gfy65W0D.d.ts +279 -0
  39. package/dist/cjs/useRouteEnter-gfy65W0D.d.ts.map +1 -0
  40. package/dist/cjs/useRouterTransition-BfayPs0h.d.ts +56 -0
  41. package/dist/cjs/useRouterTransition-BfayPs0h.d.ts.map +1 -0
  42. package/dist/esm/Await-qSmJ-ZuN.d.mts +41 -0
  43. package/dist/esm/Await-qSmJ-ZuN.d.mts.map +1 -0
  44. package/dist/esm/HttpStatusProvider-Cy9GSANm.d.mts +143 -0
  45. package/dist/esm/HttpStatusProvider-Cy9GSANm.d.mts.map +1 -0
  46. package/dist/esm/Link-BQol2GYb.mjs +2 -0
  47. package/dist/esm/Link-BQol2GYb.mjs.map +1 -0
  48. package/dist/esm/RouterErrorBoundary-C-MH_yrP.d.mts +47 -0
  49. package/dist/esm/RouterErrorBoundary-C-MH_yrP.d.mts.map +1 -0
  50. package/dist/esm/{RouterProvider-Dr3X_vbc.d.mts → RouterProvider-D_ZlPVAC.d.mts} +2 -2
  51. package/dist/esm/RouterProvider-D_ZlPVAC.d.mts.map +1 -0
  52. package/dist/esm/RouterProvider-a9y9bqji.mjs +2 -0
  53. package/dist/esm/RouterProvider-a9y9bqji.mjs.map +1 -0
  54. package/dist/esm/createHttpStatusSink-BXWVamHE.mjs +2 -0
  55. package/dist/esm/createHttpStatusSink-BXWVamHE.mjs.map +1 -0
  56. package/dist/esm/index.d.mts +6 -281
  57. package/dist/esm/index.mjs +1 -1
  58. package/dist/esm/index.mjs.map +1 -1
  59. package/dist/esm/index.react-server.d.mts +5 -0
  60. package/dist/esm/index.react-server.mjs +0 -0
  61. package/dist/esm/ink.d.mts +2 -1
  62. package/dist/esm/ink.d.mts.map +1 -1
  63. package/dist/esm/ink.mjs +1 -1
  64. package/dist/esm/ink.mjs.map +1 -1
  65. package/dist/esm/legacy.d.mts +3 -2
  66. package/dist/esm/legacy.mjs +1 -1
  67. package/dist/esm/legacy.ssr.d.mts +3 -0
  68. package/dist/esm/legacy.ssr.mjs +1 -0
  69. package/dist/esm/ssr.d.mts +4 -0
  70. package/dist/esm/ssr.mjs +2 -0
  71. package/dist/esm/ssr.mjs.map +1 -0
  72. package/dist/esm/ssr.react-server.d.mts +3 -0
  73. package/dist/esm/ssr.react-server.mjs +0 -0
  74. package/dist/esm/useDeferred-B5Qy7ttQ.d.mts +24 -0
  75. package/dist/esm/useDeferred-B5Qy7ttQ.d.mts.map +1 -0
  76. package/dist/esm/useRoute-Bta1jyl2.mjs +2 -0
  77. package/dist/esm/useRoute-Bta1jyl2.mjs.map +1 -0
  78. package/dist/esm/useRouteEnter-CxjYofFa.d.mts +279 -0
  79. package/dist/esm/useRouteEnter-CxjYofFa.d.mts.map +1 -0
  80. package/dist/esm/useRouterTransition-CI1P95ZQ.d.mts +56 -0
  81. package/dist/esm/useRouterTransition-CI1P95ZQ.d.mts.map +1 -0
  82. package/package.json +46 -4
  83. package/src/components/Await.tsx +46 -0
  84. package/src/components/ClientOnly.tsx +25 -0
  85. package/src/components/HttpStatusCode.tsx +66 -0
  86. package/src/components/HttpStatusProvider.tsx +26 -0
  87. package/src/components/InkLink.tsx +44 -22
  88. package/src/components/Link.tsx +32 -36
  89. package/src/components/RouterErrorBoundary.tsx +21 -6
  90. package/src/components/ServerOnly.tsx +26 -0
  91. package/src/components/Streamed.tsx +30 -0
  92. package/src/components/modern/RouteView/RouteView.tsx +9 -3
  93. package/src/components/modern/RouteView/helpers.tsx +26 -16
  94. package/src/constants.ts +7 -8
  95. package/src/context.ts +4 -2
  96. package/src/hooks/useDeferred.tsx +34 -0
  97. package/src/hooks/useIsActiveRoute.tsx +17 -9
  98. package/src/hooks/useNavigator.tsx +0 -2
  99. package/src/hooks/useRoute.tsx +10 -7
  100. package/src/hooks/useRouter.tsx +0 -2
  101. package/src/index.react-server.ts +33 -0
  102. package/src/index.ts +5 -0
  103. package/src/legacy.ssr.ts +35 -0
  104. package/src/legacy.ts +4 -0
  105. package/src/ssr.react-server.ts +21 -0
  106. package/src/ssr.ts +43 -0
  107. package/src/utils/createHttpStatusSink.ts +27 -0
  108. package/dist/cjs/Link-DYvAnJlk.js +0 -2
  109. package/dist/cjs/Link-DYvAnJlk.js.map +0 -1
  110. package/dist/cjs/RouterProvider-Bj1_NbpA.d.ts.map +0 -1
  111. package/dist/cjs/RouterProvider-CfBNR-k7.js +0 -2
  112. package/dist/cjs/RouterProvider-CfBNR-k7.js.map +0 -1
  113. package/dist/cjs/index.d.ts.map +0 -1
  114. package/dist/cjs/useRouterTransition-BYit_9Mt.d.ts +0 -92
  115. package/dist/cjs/useRouterTransition-BYit_9Mt.d.ts.map +0 -1
  116. package/dist/esm/Link-C7upxMc8.mjs +0 -2
  117. package/dist/esm/Link-C7upxMc8.mjs.map +0 -1
  118. package/dist/esm/RouterProvider-CS2ZoONm.mjs +0 -2
  119. package/dist/esm/RouterProvider-CS2ZoONm.mjs.map +0 -1
  120. package/dist/esm/RouterProvider-Dr3X_vbc.d.mts.map +0 -1
  121. package/dist/esm/index.d.mts.map +0 -1
  122. package/dist/esm/useRouterTransition-B65Wvngj.d.mts +0 -92
  123. package/dist/esm/useRouterTransition-B65Wvngj.d.mts.map +0 -1
@@ -0,0 +1,279 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { State } from "@real-router/core";
3
+
4
+ //#region src/components/modern/RouteView/types.d.ts
5
+ interface RouteViewProps {
6
+ /** Route tree node name to subscribe to. "" for root. */
7
+ readonly nodeName: string;
8
+ /** <RouteView.Match>, <RouteView.Self>, and <RouteView.NotFound> elements. */
9
+ readonly children: ReactNode;
10
+ }
11
+ interface MatchProps {
12
+ /** Route segment to match against. */
13
+ readonly segment: string;
14
+ /** Exact match only (no descendants). Defaults to false. */
15
+ readonly exact?: boolean;
16
+ /** Preserve component state when deactivated (React Activity). Defaults to false. */
17
+ readonly keepAlive?: boolean;
18
+ /** Fallback content to show while children are suspended. */
19
+ readonly fallback?: ReactNode;
20
+ /** Content to render when matched. */
21
+ readonly children: ReactNode;
22
+ }
23
+ interface SelfProps {
24
+ /**
25
+ * Fallback content to show while children are suspended.
26
+ *
27
+ * Symmetric with `<RouteView.Match fallback>` — wraps children in
28
+ * `<Suspense>` when defined.
29
+ */
30
+ readonly fallback?: ReactNode;
31
+ /** Content to render when the active route name equals the parent RouteView's nodeName. */
32
+ readonly children: ReactNode;
33
+ }
34
+ interface NotFoundProps {
35
+ /** Content to render on UNKNOWN_ROUTE. */
36
+ readonly children: ReactNode;
37
+ }
38
+ //#endregion
39
+ //#region src/components/modern/RouteView/components.d.ts
40
+ declare function Match(_props: MatchProps): null;
41
+ declare namespace Match {
42
+ var displayName: string;
43
+ }
44
+ declare function Self(_props: SelfProps): null;
45
+ declare namespace Self {
46
+ var displayName: string;
47
+ }
48
+ declare function NotFound(_props: NotFoundProps): null;
49
+ declare namespace NotFound {
50
+ var displayName: string;
51
+ }
52
+ //#endregion
53
+ //#region src/components/modern/RouteView/RouteView.d.ts
54
+ declare function RouteViewRoot({
55
+ nodeName,
56
+ children
57
+ }: Readonly<RouteViewProps>): ReactElement | null;
58
+ declare namespace RouteViewRoot {
59
+ var displayName: string;
60
+ }
61
+ declare const RouteView: typeof RouteViewRoot & {
62
+ Match: typeof Match;
63
+ Self: typeof Self;
64
+ NotFound: typeof NotFound;
65
+ };
66
+ //#endregion
67
+ //#region src/hooks/useRouteExit.d.ts
68
+ interface RouteExitContext {
69
+ /** The route being left. */
70
+ route: State;
71
+ /** The route being navigated to. */
72
+ nextRoute: State;
73
+ /**
74
+ * AbortSignal that fires when this navigation is superseded by a later
75
+ * one (rapid clicks). Already filtered: when the handler runs,
76
+ * `signal.aborted` is guaranteed to be `false`. Use
77
+ * `signal.addEventListener("abort", cleanup, { once: true })` for
78
+ * cleanup that must run on cancellation.
79
+ */
80
+ signal: AbortSignal;
81
+ }
82
+ interface UseRouteExitOptions {
83
+ /**
84
+ * Skip the handler when `route.name === nextRoute.name`
85
+ * (sort/filter/query-only navigations on the same route). Default:
86
+ * `true`.
87
+ */
88
+ skipSameRoute?: boolean;
89
+ }
90
+ type RouteExitHandler = (context: RouteExitContext) => void | Promise<void>;
91
+ /**
92
+ * Subscribe to the router's leave-window with the universal guards baked
93
+ * in. Wraps `router.subscribeLeave` so consumers don't repeat the same
94
+ * boilerplate every time:
95
+ *
96
+ * - **Reentrant abort pre-check**: if `signal.aborted` is already `true`
97
+ * when the handler would run (rapid navigation superseded a slower
98
+ * one), the handler is skipped entirely. `signal.addEventListener(
99
+ * "abort", ...)` does not fire retroactively, so without this guard
100
+ * downstream cleanup would never trigger.
101
+ * - **Same-route skip**: by default, `route.name === nextRoute.name`
102
+ * short-circuits the handler — query-only navigations (sort, filter,
103
+ * pagination) skip the work. Opt out with `skipSameRoute: false`.
104
+ * - **Stable handler reference**: the handler can change identity on
105
+ * every render without causing resubscription — internal ref keeps
106
+ * the latest handler accessible to the long-lived subscription.
107
+ *
108
+ * Returns nothing — the subscription's lifecycle is bound to the
109
+ * component's mount.
110
+ *
111
+ * If the handler returns a Promise, the router blocks on it. If the
112
+ * Promise resolves, navigation proceeds. If it rejects, the router emits
113
+ * `TRANSITION_CANCELLED` (existing core behavior, no change here).
114
+ *
115
+ * @example Animation
116
+ * ```tsx
117
+ * const ref = useRef<HTMLDivElement>(null);
118
+ *
119
+ * useRouteExit(async ({ signal }) => {
120
+ * const el = ref.current;
121
+ * if (!el) return;
122
+ * el.classList.add("fade-out");
123
+ * const cleanup = () => el.classList.remove("fade-out");
124
+ * signal.addEventListener("abort", cleanup, { once: true });
125
+ * try {
126
+ * el.getBoundingClientRect(); // style flush
127
+ * await Promise.allSettled(el.getAnimations().map((a) => a.finished));
128
+ * } finally {
129
+ * cleanup();
130
+ * }
131
+ * });
132
+ * ```
133
+ *
134
+ * @example Auto-save form draft
135
+ * ```tsx
136
+ * useRouteExit(async ({ signal }) => {
137
+ * if (formState.dirty) await api.saveDraft(formState, { signal });
138
+ * });
139
+ * ```
140
+ *
141
+ * @example Cancel inflight requests
142
+ * ```tsx
143
+ * useRouteExit(() => {
144
+ * inflightController.abort();
145
+ * });
146
+ * ```
147
+ *
148
+ * @example Library-coordinated exit (motion / framer-motion)
149
+ * ```tsx
150
+ * const exitResolverRef = useRef<(() => void) | null>(null);
151
+ *
152
+ * useRouteExit(({ signal }) => {
153
+ * return new Promise<void>((resolve) => {
154
+ * exitResolverRef.current = resolve;
155
+ * signal.addEventListener("abort", () => resolve(), { once: true });
156
+ * });
157
+ * });
158
+ *
159
+ * const onExitComplete = () => exitResolverRef.current?.();
160
+ * // pass onExitComplete to <AnimatePresence>
161
+ * ```
162
+ *
163
+ * @example Reading rich transition metadata via `nextRoute.transition`
164
+ * ```tsx
165
+ * useRouteExit(({ route, nextRoute }) => {
166
+ * // nextRoute.transition: TransitionMeta — preview of the upcoming nav
167
+ * if (nextRoute.transition.segments.deactivated.includes("products")) {
168
+ * // leaving the products subtree entirely — flush product-related caches
169
+ * productCache.clear();
170
+ * }
171
+ * if (nextRoute.transition.redirected) {
172
+ * // skip animation when navigation arrived via redirect
173
+ * return;
174
+ * }
175
+ * });
176
+ * ```
177
+ */
178
+ declare function useRouteExit(handler: RouteExitHandler, options?: UseRouteExitOptions): void;
179
+ //#endregion
180
+ //#region src/hooks/useRouteEnter.d.ts
181
+ interface RouteEnterContext {
182
+ /** The route that was just activated. */
183
+ route: State;
184
+ /** The route that was active immediately before this navigation. */
185
+ previousRoute: State;
186
+ }
187
+ type RouteEnterHandler = (context: RouteEnterContext) => void;
188
+ interface UseRouteEnterOptions {
189
+ /**
190
+ * Skip the handler when `route.name === previousRoute.name`
191
+ * (sort/filter/query-only navigations on the same route). Default:
192
+ * `true`. Symmetric with `useRouteExit`'s same-name option.
193
+ */
194
+ skipSameRoute?: boolean;
195
+ }
196
+ /**
197
+ * Fire `handler` once when the component mounts as a result of a
198
+ * navigation. Mirror of `useRouteExit` for the entry side.
199
+ *
200
+ * What this hook covers that ad-hoc `useEffect` + `useRoute()` doesn't:
201
+ *
202
+ * - **Skip-initial**: handler is skipped when there is no
203
+ * `previousRoute` (i.e. first-load mount). Most consumers want to
204
+ * fire side effects only on real navigations, not on hydration.
205
+ * - **Same-route skip** (default): handler is skipped when
206
+ * `route.name === previousRoute.name`. Sort/filter/query-only
207
+ * navigations re-run the effect (because `route` reference changes
208
+ * in `useRoute`'s snapshot), but they are not "entries" in the
209
+ * animation / analytics sense — the component instance has stayed
210
+ * mounted throughout. Opt out with `skipSameRoute: false` when
211
+ * the handler legitimately needs to fire on every navigation
212
+ * (e.g. analytics tracking each query-param flip).
213
+ * - **StrictMode double-mount immunity**: in dev, React's StrictMode
214
+ * runs every effect twice to surface bugs. Without a guard,
215
+ * analytics fire twice, animations restart, focus jumps. The hook
216
+ * tracks the last-handled `route` reference and short-circuits the
217
+ * second pass.
218
+ * - **Latest-handler ref**: the handler can change identity on every
219
+ * render without re-running the effect — the registered wrapper
220
+ * dispatches to whatever `handlerRef.current` points to.
221
+ * - **Mount-time `route` / `previousRoute` snapshot**: the handler
222
+ * receives the values that were live at the moment of mount, not
223
+ * the latest ones (which may have moved on if the user navigated
224
+ * again before the effect drained).
225
+ *
226
+ * Race-safety: `useRoute()` is wired through `useSyncExternalStore` from
227
+ * `@real-router/sources`, so by the time the new component's effect
228
+ * runs, the snapshot is the post-commit one. This is the reason we can
229
+ * read mount-time context from `useRoute()` instead of subscribing to
230
+ * `router.subscribe` directly (which fires before React schedules a
231
+ * re-render — the well-known race in distributed components).
232
+ *
233
+ * @example Direction-aware entry animation
234
+ * ```tsx
235
+ * useRouteEnter(({ route }) => {
236
+ * const direction = route.context.browser?.direction;
237
+ * ref.current?.classList.add(
238
+ * direction === "back" ? "slide-from-left" : "slide-from-right",
239
+ * );
240
+ * });
241
+ * ```
242
+ *
243
+ * @example Source-aware focus management
244
+ * ```tsx
245
+ * useRouteEnter(({ route }) => {
246
+ * if (route.context.browser?.source === "navigate") {
247
+ * headingRef.current?.focus();
248
+ * }
249
+ * });
250
+ * ```
251
+ *
252
+ * @example Analytics page-enter event (skip-initial built-in)
253
+ * ```tsx
254
+ * useRouteEnter(({ route, previousRoute }) => {
255
+ * analytics.track("page_enter", {
256
+ * route: route.name,
257
+ * from: previousRoute.name,
258
+ * });
259
+ * });
260
+ * ```
261
+ *
262
+ * @example Reading rich transition metadata via `route.transition`
263
+ * ```tsx
264
+ * useRouteEnter(({ route }) => {
265
+ * // route.transition: TransitionMeta — populated by core for every state
266
+ * if (route.transition.redirected) {
267
+ * showToast(`Redirected from ${route.transition.from}`);
268
+ * }
269
+ * if (route.transition.segments.activated.includes("products")) {
270
+ * // products subtree just became active (could be products or
271
+ * // products.detail). Useful for subtree-scoped side effects.
272
+ * }
273
+ * });
274
+ * ```
275
+ */
276
+ declare function useRouteEnter(handler: RouteEnterHandler, options?: UseRouteEnterOptions): void;
277
+ //#endregion
278
+ export { RouteExitContext as a, useRouteExit as c, NotFoundProps as d, RouteViewProps as f, useRouteEnter as i, RouteView as l, RouteEnterHandler as n, RouteExitHandler as o, SelfProps as p, UseRouteEnterOptions as r, UseRouteExitOptions as s, RouteEnterContext as t, MatchProps as u };
279
+ //# sourceMappingURL=useRouteEnter-CxjYofFa.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRouteEnter-CxjYofFa.d.mts","names":[],"sources":["../../src/components/modern/RouteView/types.ts","../../src/components/modern/RouteView/components.tsx","../../src/components/modern/RouteView/RouteView.tsx","../../src/hooks/useRouteExit.tsx","../../src/hooks/useRouteEnter.tsx"],"mappings":";;;;UAEiB,cAAA;;WAEN,QAAA;EAFM;EAAA,SAIN,QAAA,EAAU,SAAA;AAAA;AAAA,UAGJ,UAAA;EALN;EAAA,SAOA,OAAA;EALU;EAAA,SAOV,KAAA;EAPmB;EAAA,SASnB,SAAA;EANgB;EAAA,SAQhB,QAAA,GAAW,SAAA;EAEQ;EAAA,SAAnB,QAAA,EAAU,SAAA;AAAA;AAAA,UAGJ,SAAA;EALN;;;;;;EAAA,SAYA,QAAA,GAAW,SAAA;EAPI;EAAA,SASf,QAAA,EAAU,SAAA;AAAA;AAAA,UAGJ,aAAA;EALK;EAAA,SAOX,QAAA,EAAU,SAAA;AAAA;;;iBClCL,KAAA,CAAM,MAAA,EAAQ,UAAA;AAAA,kBAAd,KAAA;EAAA,IAAK,WAAA;AAAA;AAAA,iBAML,IAAA,CAAK,MAAA,EAAQ,SAAA;AAAA,kBAAb,IAAA;EAAA,IAAI,WAAA;AAAA;AAAA,iBAMJ,QAAA,CAAS,MAAA,EAAQ,aAAA;AAAA,kBAAjB,QAAA;EAAA,IAAQ,WAAA;AAAA;;;iBCLf,aAAA,CAAA;EACP,QAAA;EACA;AAAA,GACC,QAAA,CAAS,cAAA,IAAkB,YAAA;AAAA,kBAHrB,aAAA;EAAA,IAAa,WAAA;AAAA;AAAA,cAgDT,SAAA,SAAS,aAAA;;;;;;;UCnDL,gBAAA;;EAEf,KAAA,EAAO,KAAA;EHNQ;EGQf,SAAA,EAAW,KAAA;;;;;;;;EAQX,MAAA,EAAQ,WAAA;AAAA;AAAA,UAGO,mBAAA;EHFa;;;;;EGQ5B,aAAA;AAAA;AAAA,KAGU,gBAAA,IACV,OAAA,EAAS,gBAAA,YACC,OAAA;;;AHVZ;;;;;;;;;;AAYA;;;;;;;;AChCA;;;;;;;;;;AAMA;;;;;;;;;;AAMA;;;;;;;;;;;;;ACP0C;;;;;;;;;;;;;;;;;;;AAKA;;;;;AA6C1C;;;;;;;;;;iBCgEgB,YAAA,CACd,OAAA,EAAS,gBAAA,EACT,OAAA,GAAU,mBAAA;;;UCrHK,iBAAA;;EAEf,KAAA,EAAO,KAAA;EJNQ;EIQf,aAAA,EAAe,KAAA;AAAA;AAAA,KAGL,iBAAA,IAAqB,OAAA,EAAS,iBAAA;AAAA,UAEzB,oBAAA;EJTN;;;;AAGX;EIYE,aAAA;AAAA;;;;;;;;;;;AJCF;;;;;;;;;;AAYA;;;;;;;;AChCA;;;;;;;;;;AAMA;;;;;;;;;;AAMA;;;;;;;;;;;;;ACP0C;;;;;;;;;;;;;;;;;;;iBEiG1B,aAAA,CACd,OAAA,EAAS,iBAAA,EACT,OAAA,GAAU,oBAAA"}
@@ -0,0 +1,56 @@
1
+ import { i as RouteContext } from "./RouterErrorBoundary-C-MH_yrP.mjs";
2
+ import { Navigator, Params, Router, State } from "@real-router/core";
3
+ import { RouteUtils } from "@real-router/route-utils";
4
+ import { RouterTransitionSnapshot } from "@real-router/sources";
5
+
6
+ //#region src/hooks/useRouter.d.ts
7
+ declare const useRouter: () => Router;
8
+ //#endregion
9
+ //#region src/hooks/useNavigator.d.ts
10
+ declare const useNavigator: () => Navigator;
11
+ //#endregion
12
+ //#region src/hooks/useRouteUtils.d.ts
13
+ /**
14
+ * Returns a pre-computed {@link RouteUtils} instance for the current router.
15
+ *
16
+ * `getRouteUtils` is WeakMap-cached per `RouteTreeNode` inside
17
+ * `@real-router/route-utils`, so the same router always returns the same
18
+ * `RouteUtils` instance across renders — no local cache needed in the adapter.
19
+ *
20
+ * @returns RouteUtils instance with pre-computed chains and siblings
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const utils = useRouteUtils();
25
+ *
26
+ * utils.getChain("users.profile");
27
+ * // → ["users", "users.profile"]
28
+ *
29
+ * utils.getSiblings("users");
30
+ * // → ["admin"]
31
+ *
32
+ * utils.isDescendantOf("users.profile", "users");
33
+ * // → true
34
+ * ```
35
+ */
36
+ declare const useRouteUtils: () => RouteUtils;
37
+ //#endregion
38
+ //#region src/hooks/useRoute.d.ts
39
+ /**
40
+ * Return shape of `useRoute<P>()` — the context with `route` narrowed to
41
+ * `State<P>` (non-nullable). Promoting the intersection to a named alias
42
+ * keeps the function signature and the cast site in sync.
43
+ */
44
+ type RouteHookResult<P extends Params = Params> = Omit<RouteContext<P>, "route"> & {
45
+ route: State<P>;
46
+ };
47
+ declare const useRoute: <P extends Params = Params>() => RouteHookResult<P>;
48
+ //#endregion
49
+ //#region src/hooks/useRouteNode.d.ts
50
+ declare function useRouteNode(nodeName: string): RouteContext;
51
+ //#endregion
52
+ //#region src/hooks/useRouterTransition.d.ts
53
+ declare function useRouterTransition(): RouterTransitionSnapshot;
54
+ //#endregion
55
+ export { useNavigator as a, useRouteUtils as i, useRouteNode as n, useRouter as o, useRoute as r, useRouterTransition as t };
56
+ //# sourceMappingURL=useRouterTransition-CI1P95ZQ.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRouterTransition-CI1P95ZQ.d.mts","names":[],"sources":["../../src/hooks/useRouter.tsx","../../src/hooks/useNavigator.tsx","../../src/hooks/useRouteUtils.tsx","../../src/hooks/useRoute.tsx","../../src/hooks/useRouteNode.tsx","../../src/hooks/useRouterTransition.tsx"],"mappings":";;;;;;cAMa,SAAA,QAAgB,MAAA;;;cCAhB,YAAA,QAAmB,SAAA;;;;;;;;ADAhC;;;;;;;;ACAA;;;;;;;;ACwBA;;cAAa,aAAA,QAAoB,UAAA;;;;;;;AFxBjC;KGMK,eAAA,WAA0B,MAAA,GAAS,MAAA,IAAU,IAAA,CAChD,YAAA,CAAiB,CAAA;EAEb,KAAA,EAAO,KAAA,CAAM,CAAA;AAAA;AAAA,cAEN,QAAA,aAAsB,MAAA,GAAS,MAAA,OAAW,eAAA,CAAgB,CAAA;;;iBCTvD,YAAA,CAAa,QAAA,WAAmB,YAAA;;;iBCDhC,mBAAA,CAAA,GAAuB,wBAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/react",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "type": "commonjs",
5
5
  "description": "React integration for Real-Router",
6
6
  "main": "./dist/cjs/index.js",
@@ -13,11 +13,26 @@
13
13
  ],
14
14
  "ink": [
15
15
  "./dist/cjs/ink.d.ts"
16
+ ],
17
+ "ssr": [
18
+ "./dist/cjs/ssr.d.ts"
19
+ ],
20
+ "legacy/ssr": [
21
+ "./dist/cjs/legacy.ssr.d.ts"
16
22
  ]
17
23
  }
18
24
  },
19
25
  "exports": {
20
26
  ".": {
27
+ "react-server": {
28
+ "@real-router/internal-source": "./src/index.react-server.ts",
29
+ "types": {
30
+ "import": "./dist/esm/index.react-server.d.mts",
31
+ "require": "./dist/cjs/index.react-server.d.ts"
32
+ },
33
+ "import": "./dist/esm/index.react-server.mjs",
34
+ "require": "./dist/cjs/index.react-server.js"
35
+ },
21
36
  "@real-router/internal-source": "./src/index.ts",
22
37
  "types": {
23
38
  "import": "./dist/esm/index.d.mts",
@@ -43,6 +58,33 @@
43
58
  },
44
59
  "import": "./dist/esm/ink.mjs",
45
60
  "require": "./dist/cjs/ink.js"
61
+ },
62
+ "./ssr": {
63
+ "react-server": {
64
+ "@real-router/internal-source": "./src/ssr.react-server.ts",
65
+ "types": {
66
+ "import": "./dist/esm/ssr.react-server.d.mts",
67
+ "require": "./dist/cjs/ssr.react-server.d.ts"
68
+ },
69
+ "import": "./dist/esm/ssr.react-server.mjs",
70
+ "require": "./dist/cjs/ssr.react-server.js"
71
+ },
72
+ "@real-router/internal-source": "./src/ssr.ts",
73
+ "types": {
74
+ "import": "./dist/esm/ssr.d.mts",
75
+ "require": "./dist/cjs/ssr.d.ts"
76
+ },
77
+ "import": "./dist/esm/ssr.mjs",
78
+ "require": "./dist/cjs/ssr.js"
79
+ },
80
+ "./legacy/ssr": {
81
+ "@real-router/internal-source": "./src/legacy.ssr.ts",
82
+ "types": {
83
+ "import": "./dist/esm/legacy.ssr.d.mts",
84
+ "require": "./dist/cjs/legacy.ssr.d.ts"
85
+ },
86
+ "import": "./dist/esm/legacy.ssr.mjs",
87
+ "require": "./dist/cjs/legacy.ssr.js"
46
88
  }
47
89
  },
48
90
  "files": [
@@ -76,9 +118,9 @@
76
118
  "license": "MIT",
77
119
  "sideEffects": false,
78
120
  "dependencies": {
79
- "@real-router/core": "^0.52.0",
121
+ "@real-router/core": "^0.53.0",
80
122
  "@real-router/route-utils": "^0.2.2",
81
- "@real-router/sources": "^0.8.1"
123
+ "@real-router/sources": "^0.8.2"
82
124
  },
83
125
  "devDependencies": {
84
126
  "@testing-library/dom": "10.4.1",
@@ -88,7 +130,7 @@
88
130
  "ink": "7.0.1",
89
131
  "ink-testing-library": "4.0.0",
90
132
  "vitest-react-profiler": "1.12.0",
91
- "@real-router/browser-plugin": "^0.17.1"
133
+ "@real-router/browser-plugin": "^0.17.2"
92
134
  },
93
135
  "peerDependencies": {
94
136
  "@types/react": ">=18.0.0",
@@ -0,0 +1,46 @@
1
+ import { use } from "react";
2
+
3
+ import { useDeferred } from "../hooks/useDeferred";
4
+
5
+ import type { ReactNode } from "react";
6
+
7
+ export interface AwaitProps<T> {
8
+ /** Deferred key declared in the loader's `defer({ deferred: { <name>: ... } })`. */
9
+ readonly name: string;
10
+ /** Render the resolved value. Suspends while pending; throws inside the
11
+ * nearest Error Boundary on rejection. */
12
+ readonly children: (value: T) => ReactNode;
13
+ }
14
+
15
+ /**
16
+ * Ergonomic wrapper around `useDeferred(name)` + React 19's `use(promise)`.
17
+ *
18
+ * ```tsx
19
+ * <Suspense fallback={<Spinner />}>
20
+ * <Await<Review[]> name="reviews">
21
+ * {(reviews) => <ReviewList items={reviews} />}
22
+ * </Await>
23
+ * </Suspense>
24
+ * ```
25
+ *
26
+ * Equivalent to:
27
+ *
28
+ * ```tsx
29
+ * function Inner() {
30
+ * const reviews = use(useDeferred<Review[]>("reviews"));
31
+ * return <ReviewList items={reviews} />;
32
+ * }
33
+ * ```
34
+ *
35
+ * Pick `<Await>` for cross-adapter consistency with the SvelteKit
36
+ * `{#await}` / Solid `<Await/>` shape; pick the inline `use(useDeferred(...))`
37
+ * form if you prefer one fewer abstraction.
38
+ */
39
+ export function Await<T = unknown>({
40
+ name,
41
+ children,
42
+ }: AwaitProps<T>): ReactNode {
43
+ const value = use(useDeferred<T>(name));
44
+
45
+ return children(value);
46
+ }
@@ -0,0 +1,25 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import type { ReactNode } from "react";
4
+
5
+ export interface ClientOnlyProps {
6
+ readonly children: ReactNode;
7
+ readonly fallback?: ReactNode;
8
+ }
9
+
10
+ export function ClientOnly({
11
+ children,
12
+ fallback = null,
13
+ }: ClientOnlyProps): ReactNode {
14
+ const [mounted, setMounted] = useState(false);
15
+
16
+ useEffect(() => {
17
+ // SSR/hydration boundary: server emits the fallback branch, client matches
18
+ // it on first paint, then this effect flips state to swap in the children.
19
+ // The intentional re-render is what makes the markup match across renders.
20
+ // eslint-disable-next-line @eslint-react/set-state-in-effect -- intentional post-hydration swap
21
+ setMounted(true);
22
+ }, []);
23
+
24
+ return mounted ? children : fallback;
25
+ }
@@ -0,0 +1,66 @@
1
+ import { useContext } from "react";
2
+
3
+ import { HttpStatusContext } from "./HttpStatusProvider";
4
+
5
+ import type { ReactNode } from "react";
6
+
7
+ export interface HttpStatusCodeProps {
8
+ /** HTTP status to apply to the response. Common values: 404, 410, 451, 503. */
9
+ readonly code: number;
10
+ }
11
+
12
+ /**
13
+ * Render-time HTTP status declaration. Mount inside a route component (typical
14
+ * use case: a glob `*` route's NotFound page) when the status is decided by
15
+ * the rendered tree rather than a loader.
16
+ *
17
+ * Writes `code` to the nearest `<HttpStatusProvider>`'s sink during render and
18
+ * returns `null`. With no provider mounted (the standard client-side case)
19
+ * the component is a silent no-op — same component tree hydrates without
20
+ * touching the DOM or warning about mismatches.
21
+ *
22
+ * Loader-driven errors (`LoaderNotFound` → 404, `LoaderRedirect` → 30x) keep
23
+ * working as before; this component covers render-time decisions only.
24
+ *
25
+ * Last write wins when several `<HttpStatusCode />` instances mount in the
26
+ * same render pass — sink reflects the last component that ran.
27
+ *
28
+ * ```tsx
29
+ * // entry-server.tsx
30
+ * import { renderToString } from "react-dom/server";
31
+ * import { createHttpStatusSink, HttpStatusProvider } from "@real-router/react/ssr";
32
+ *
33
+ * const sink = createHttpStatusSink();
34
+ * const html = renderToString(
35
+ * <HttpStatusProvider sink={sink}>
36
+ * <RouterProvider router={router}>
37
+ * <App />
38
+ * </RouterProvider>
39
+ * </HttpStatusProvider>,
40
+ * );
41
+ * response.status(sink.code ?? 200).send(html);
42
+ * ```
43
+ *
44
+ * **Streaming SSR (`renderToReadableStream`):** the response status MUST be
45
+ * sent before the first body byte flushes. If `<HttpStatusCode />` is mounted
46
+ * inside a late-resolving `<Suspense>` boundary, the sink write may happen
47
+ * AFTER the headers are already on the wire — the override is then lost.
48
+ * Either mount the component in the shell (above every `<Suspense>` that
49
+ * could delay it) or `await stream.allReady` before reading `sink.code`
50
+ * (which forfeits streaming benefits). For non-streaming SSR
51
+ * (`renderToString`) there is no such ordering concern.
52
+ *
53
+ * **Valid `code` range:** Node's `res.end()` throws `Invalid status code` on
54
+ * `NaN`, `0`, negative values, or values `> 999` — this surfaces as a 5xx /
55
+ * dropped connection, not silent corruption. Pass a real HTTP status integer
56
+ * (commonly 4xx/5xx; 100-999 is what Node accepts).
57
+ */
58
+ export function HttpStatusCode({ code }: HttpStatusCodeProps): ReactNode {
59
+ const sink = useContext(HttpStatusContext);
60
+
61
+ if (sink) {
62
+ sink.code = code;
63
+ }
64
+
65
+ return null;
66
+ }
@@ -0,0 +1,26 @@
1
+ import { createContext } from "react";
2
+
3
+ import type { HttpStatusSink } from "../utils/createHttpStatusSink";
4
+ import type { ReactNode } from "react";
5
+
6
+ export const HttpStatusContext = createContext<HttpStatusSink | null>(null);
7
+
8
+ export interface HttpStatusProviderProps {
9
+ readonly sink: HttpStatusSink;
10
+ readonly children: ReactNode;
11
+ }
12
+
13
+ export function HttpStatusProvider({
14
+ sink,
15
+ children,
16
+ }: HttpStatusProviderProps): ReactNode {
17
+ // `<HttpStatusContext.Provider value>` (not the React 19 `<HttpStatusContext value>`
18
+ // shorthand) — same component file is exported via `/legacy/ssr` for React 18
19
+ // consumers, where the shorthand throws "Element type is invalid: expected
20
+ // a string but got: object".
21
+ return (
22
+ <HttpStatusContext.Provider value={sink}>
23
+ {children}
24
+ </HttpStatusContext.Provider>
25
+ );
26
+ }