UNPKG

7.1 kBTypeScriptView Raw
1import * as React from 'react';
2import { RouterProviderProps as RouterProviderProps$1, RouterInit, ClientOnErrorFunction } from 'react-router';
3import { u as unstable_ClientInstrumentation } from './instrumentation-CMVbvxj9.js';
4export { D as unstable_DecodeActionFunction, a as unstable_DecodeFormStateFunction, b as unstable_DecodeReplyFunction, R as unstable_RSCHydratedRouter, d as unstable_RSCManifestPayload, e as unstable_RSCPayload, f as unstable_RSCRenderPayload, c as unstable_createCallServer } from './browser-CtktEGQs.js';
5import './routeModules-CM_clkdE.js';
6
7type RouterProviderProps = Omit<RouterProviderProps$1, "flushSync">;
8declare function RouterProvider(props: Omit<RouterProviderProps, "flushSync">): React.JSX.Element;
9
10/**
11 * Props for the {@link dom.HydratedRouter} component.
12 *
13 * @category Types
14 */
15interface HydratedRouterProps {
16 /**
17 * Context factory function to be passed through to {@link createBrowserRouter}.
18 * This function will be called to create a fresh `context` instance on each
19 * navigation/fetch and made available to
20 * [`clientAction`](../../start/framework/route-module#clientAction)/[`clientLoader`](../../start/framework/route-module#clientLoader)
21 * functions.
22 */
23 getContext?: RouterInit["getContext"];
24 /**
25 * Array of instrumentation objects allowing you to instrument the router and
26 * individual routes prior to router initialization (and on any subsequently
27 * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
28 * mostly useful for observability such as wrapping navigations, fetches,
29 * as well as route loaders/actions/middlewares with logging and/or performance
30 * tracing. See the [docs](../../how-to/instrumentation) for more information.
31 *
32 * ```tsx
33 * const logging = {
34 * router({ instrument }) {
35 * instrument({
36 * navigate: (impl, { to }) => logExecution(`navigate ${to}`, impl),
37 * fetch: (impl, { to }) => logExecution(`fetch ${to}`, impl)
38 * });
39 * },
40 * route({ instrument, id }) {
41 * instrument({
42 * middleware: (impl, { request }) => logExecution(
43 * `middleware ${request.url} (route ${id})`,
44 * impl
45 * ),
46 * loader: (impl, { request }) => logExecution(
47 * `loader ${request.url} (route ${id})`,
48 * impl
49 * ),
50 * action: (impl, { request }) => logExecution(
51 * `action ${request.url} (route ${id})`,
52 * impl
53 * ),
54 * })
55 * }
56 * };
57 *
58 * async function logExecution(label: string, impl: () => Promise<void>) {
59 * let start = performance.now();
60 * console.log(`start ${label}`);
61 * await impl();
62 * let duration = Math.round(performance.now() - start);
63 * console.log(`end ${label} (${duration}ms)`);
64 * }
65 *
66 * startTransition(() => {
67 * hydrateRoot(
68 * document,
69 * <HydratedRouter unstable_instrumentations={[logging]} />
70 * );
71 * });
72 * ```
73 */
74 unstable_instrumentations?: unstable_ClientInstrumentation[];
75 /**
76 * An error handler function that will be called for any middleware, loader, action,
77 * or render errors that are encountered in your application. This is useful for
78 * logging or reporting errors instead of in the {@link ErrorBoundary} because it's not
79 * subject to re-rendering and will only run one time per error.
80 *
81 * The `errorInfo` parameter is passed along from
82 * [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
83 * and is only present for render errors.
84 *
85 * ```tsx
86 * <HydratedRouter onError=(error, info) => {
87 * let { location, params, unstable_pattern, errorInfo } = info;
88 * console.error(error, location, errorInfo);
89 * reportToErrorService(error, location, errorInfo);
90 * }} />
91 * ```
92 */
93 onError?: ClientOnErrorFunction;
94 /**
95 * Control whether router state updates are internally wrapped in
96 * [`React.startTransition`](https://react.dev/reference/react/startTransition).
97 *
98 * - When left `undefined`, all state updates are wrapped in
99 * `React.startTransition`
100 * - This can lead to buggy behaviors if you are wrapping your own
101 * navigations/fetchers in `startTransition`.
102 * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
103 * in `React.startTransition` and router state changes will be wrapped in
104 * `React.startTransition` and also sent through
105 * [`useOptimistic`](https://react.dev/reference/react/useOptimistic) to
106 * surface mid-navigation router state changes to the UI.
107 * - When set to `false`, the router will not leverage `React.startTransition` or
108 * `React.useOptimistic` on any navigations or state changes.
109 *
110 * For more information, please see the [docs](https://reactrouter.com/explanation/react-transitions).
111 */
112 unstable_useTransitions?: boolean;
113}
114/**
115 * Framework-mode router component to be used to hydrate a router from a
116 * {@link ServerRouter}. See [`entry.client.tsx`](../framework-conventions/entry.client.tsx).
117 *
118 * @public
119 * @category Framework Routers
120 * @mode framework
121 * @param props Props
122 * @param {dom.HydratedRouterProps.getContext} props.getContext n/a
123 * @param {dom.HydratedRouterProps.onError} props.onError n/a
124 * @returns A React element that represents the hydrated application.
125 */
126declare function HydratedRouter(props: HydratedRouterProps): React.JSX.Element;
127
128declare global {
129 interface Window {
130 __FLIGHT_DATA: any[];
131 }
132}
133/**
134 * Get the prerendered [RSC](https://react.dev/reference/rsc/server-components)
135 * stream for hydration. Usually passed directly to your
136 * `react-server-dom-xyz/client`'s `createFromReadableStream`.
137 *
138 * @example
139 * import { startTransition, StrictMode } from "react";
140 * import { hydrateRoot } from "react-dom/client";
141 * import {
142 * unstable_getRSCStream as getRSCStream,
143 * unstable_RSCHydratedRouter as RSCHydratedRouter,
144 * } from "react-router";
145 * import type { unstable_RSCPayload as RSCPayload } from "react-router";
146 *
147 * createFromReadableStream(getRSCStream()).then(
148 * (payload: RSCServerPayload) => {
149 * startTransition(async () => {
150 * hydrateRoot(
151 * document,
152 * <StrictMode>
153 * <RSCHydratedRouter {...props} />
154 * </StrictMode>,
155 * {
156 * // Options
157 * }
158 * );
159 * });
160 * }
161 * );
162 *
163 * @name unstable_getRSCStream
164 * @public
165 * @category RSC
166 * @mode data
167 * @returns A [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)
168 * that contains the [RSC](https://react.dev/reference/rsc/server-components)
169 * data for hydration.
170 */
171declare function getRSCStream(): ReadableStream;
172
173export { HydratedRouter, type HydratedRouterProps, RouterProvider, type RouterProviderProps, getRSCStream as unstable_getRSCStream };