Skip to content

Commit 01e9b65

Browse files
committed
Remove implementation from createRouter
1 parent 1ab7d52 commit 01e9b65

File tree

7 files changed

+18
-89
lines changed

7 files changed

+18
-89
lines changed

packages/react-router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export type {
1212
StaticHandler,
1313
GetScrollPositionFunction,
1414
GetScrollRestorationKeyFunction,
15-
unstable_HandleErrorFunction,
1615
StaticHandlerContext,
1716
Fetcher,
1817
Navigation,
@@ -98,6 +97,7 @@ export type {
9897
export type {
9998
AwaitProps,
10099
IndexRouteProps,
100+
unstable_HandleErrorFunction,
101101
LayoutRouteProps,
102102
MemoryRouterOpts,
103103
MemoryRouterProps,

packages/react-router/lib/components.tsx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type {
2121
RouterState,
2222
RouterSubscriber,
2323
RouterInit,
24-
unstable_HandleErrorFunction,
2524
} from "./router/router";
2625
import { createRouter } from "./router/router";
2726
import type {
@@ -178,29 +177,6 @@ export interface MemoryRouterOpts {
178177
* Lazily define portions of the route tree on navigations.
179178
*/
180179
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
181-
/**
182-
* An error handler function that will be called for any loader/action/render
183-
* errors that are encountered in your application. This is useful for
184-
* logging or reporting errors instead of the `ErrorBoundary` because it's not
185-
* subject to re-rendering and will only run one time per error.
186-
*
187-
* The `errorInfo` parameter is passed along from
188-
* [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
189-
* and is only present for render errors.
190-
*
191-
* ```tsx
192-
* let router = createMemoryRouter(routes, {
193-
* unstable_handleError(error, { location, errorInfo }) {
194-
* console.log(
195-
* `Error at location ${location.pathname}`,
196-
* error,
197-
* errorInfo
198-
* );
199-
* }
200-
* );
201-
* ```
202-
*/
203-
unstable_handleError?: unstable_HandleErrorFunction;
204180
}
205181

206182
/**
@@ -217,7 +193,6 @@ export interface MemoryRouterOpts {
217193
* @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
218194
* @param {MemoryRouterOpts.future} opts.future n/a
219195
* @param {MemoryRouterOpts.unstable_getContext} opts.unstable_getContext n/a
220-
* @param {MemoryRouterOpts.unstable_handleError} opts.unstable_handleError n/a
221196
* @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
222197
* @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
223198
* @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
@@ -236,7 +211,6 @@ export function createMemoryRouter(
236211
initialEntries: opts?.initialEntries,
237212
initialIndex: opts?.initialIndex,
238213
}),
239-
unstable_handleError: opts?.unstable_handleError,
240214
hydrationData: opts?.hydrationData,
241215
routes,
242216
hydrationRouteProperties,
@@ -271,6 +245,20 @@ class Deferred<T> {
271245
}
272246
}
273247

248+
/**
249+
* Function signature for client side error handling for loader/actions errors
250+
* and rendering errors via `componentDidCatch`
251+
*/
252+
export interface unstable_HandleErrorFunction {
253+
(
254+
error: unknown,
255+
info: {
256+
location: Location;
257+
errorInfo?: React.ErrorInfo;
258+
},
259+
): void;
260+
}
261+
274262
/**
275263
* @category Types
276264
*/

packages/react-router/lib/dom-export/hydrated-router.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
DataRouter,
77
HydrationState,
88
RouterInit,
9+
unstable_HandleErrorFunction,
910
} from "react-router";
1011
import {
1112
UNSAFE_getHydrationData as getHydrationData,
@@ -77,10 +78,8 @@ function initSsrInfo(): void {
7778

7879
function createHydratedRouter({
7980
unstable_getContext,
80-
unstable_handleError,
8181
}: {
8282
unstable_getContext?: RouterInit["unstable_getContext"];
83-
unstable_handleError?: RouterInit["unstable_handleError"];
8483
}): DataRouter {
8584
initSsrInfo();
8685

@@ -171,7 +170,6 @@ function createHydratedRouter({
171170
history: createBrowserHistory(),
172171
basename: ssrInfo.context.basename,
173172
unstable_getContext,
174-
unstable_handleError,
175173
hydrationData,
176174
hydrationRouteProperties,
177175
mapRouteProperties,
@@ -245,7 +243,7 @@ export interface HydratedRouterProps {
245243
* }} />
246244
* ```
247245
*/
248-
unstable_handleError?: RouterInit["unstable_handleError"];
246+
unstable_handleError?: unstable_HandleErrorFunction;
249247
}
250248

251249
/**
@@ -264,7 +262,6 @@ export function HydratedRouter(props: HydratedRouterProps) {
264262
if (!router) {
265263
router = createHydratedRouter({
266264
unstable_getContext: props.unstable_getContext,
267-
unstable_handleError: props.unstable_handleError,
268265
});
269266
}
270267

packages/react-router/lib/dom/lib.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type {
2424
RelativeRoutingType,
2525
Router as DataRouter,
2626
RouterInit,
27-
unstable_HandleErrorFunction,
2827
} from "../router/router";
2928
import { IDLE_FETCHER, createRouter } from "../router/router";
3029
import type {
@@ -720,29 +719,6 @@ export interface DOMRouterOpts {
720719
* </details>
721720
*/
722721
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
723-
/**
724-
* An error handler function that will be called for any loader/action/render
725-
* errors that are encountered in your application. This is useful for
726-
* logging or reporting errors instead of the `ErrorBoundary` because it's not
727-
* subject to re-rendering and will only run one time per error.
728-
*
729-
* The `errorInfo` parameter is passed along from
730-
* [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
731-
* and is only present for render errors.
732-
*
733-
* ```tsx
734-
* let router = createBrowserRouter(routes, {
735-
* unstable_handleError(error, { location, errorInfo }) {
736-
* console.log(
737-
* `Error at location ${location.pathname}`,
738-
* error,
739-
* errorInfo
740-
* );
741-
* }
742-
* );
743-
* ```
744-
*/
745-
unstable_handleError?: unstable_HandleErrorFunction;
746722
/**
747723
* [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
748724
* override. Defaults to the global `window` instance.
@@ -764,7 +740,6 @@ export interface DOMRouterOpts {
764740
* @param {DOMRouterOpts.dataStrategy} opts.dataStrategy n/a
765741
* @param {DOMRouterOpts.future} opts.future n/a
766742
* @param {DOMRouterOpts.unstable_getContext} opts.unstable_getContext n/a
767-
* @param {DOMRouterOpts.unstable_handleError} opts.unstable_handleError n/a
768743
* @param {DOMRouterOpts.hydrationData} opts.hydrationData n/a
769744
* @param {DOMRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
770745
* @param {DOMRouterOpts.window} opts.window n/a
@@ -779,7 +754,6 @@ export function createBrowserRouter(
779754
unstable_getContext: opts?.unstable_getContext,
780755
future: opts?.future,
781756
history: createBrowserHistory({ window: opts?.window }),
782-
unstable_handleError: opts?.unstable_handleError,
783757
hydrationData: opts?.hydrationData || parseHydrationData(),
784758
routes,
785759
mapRouteProperties,
@@ -802,7 +776,6 @@ export function createBrowserRouter(
802776
* @param {DOMRouterOpts.basename} opts.basename n/a
803777
* @param {DOMRouterOpts.future} opts.future n/a
804778
* @param {DOMRouterOpts.unstable_getContext} opts.unstable_getContext n/a
805-
* @param {DOMRouterOpts.unstable_handleError} opts.unstable_handleError n/a
806779
* @param {DOMRouterOpts.hydrationData} opts.hydrationData n/a
807780
* @param {DOMRouterOpts.dataStrategy} opts.dataStrategy n/a
808781
* @param {DOMRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
@@ -818,7 +791,6 @@ export function createHashRouter(
818791
unstable_getContext: opts?.unstable_getContext,
819792
future: opts?.future,
820793
history: createHashHistory({ window: opts?.window }),
821-
unstable_handleError: opts?.unstable_handleError,
822794
hydrationData: opts?.hydrationData || parseHydrationData(),
823795
routes,
824796
mapRouteProperties,

packages/react-router/lib/dom/server.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@ export function createStaticRouter(
484484
patchRoutes() {
485485
throw msg("patchRoutes");
486486
},
487-
_internalHandleError() {
488-
throw msg("_internalHandleError");
489-
},
490487
_internalFetchControllers: new Map(),
491488
_internalSetRoutes() {
492489
throw msg("_internalSetRoutes");

packages/react-router/lib/hooks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import type {
3030
Router as DataRouter,
3131
RevalidationState,
3232
Navigation,
33-
unstable_HandleErrorFunction,
3433
} from "./router/router";
3534
import { IDLE_BLOCKER } from "./router/router";
3635
import type {
@@ -52,6 +51,7 @@ import {
5251
stripBasename,
5352
} from "./router/utils";
5453
import type { SerializeFrom } from "./types/route-data";
54+
import { unstable_HandleErrorFunction } from "./components";
5555

5656
/**
5757
* Resolves a URL against the current {@link Location}.

packages/react-router/lib/router/router.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,6 @@ export interface Router {
271271
unstable_allowElementMutations?: boolean,
272272
): void;
273273

274-
/**
275-
* @private
276-
* PRIVATE - DO NOT USE
277-
*
278-
* Error handler exposed for wiring up to `ErrorBoundary` `componentDidCatch`
279-
*/
280-
_internalHandleError: unstable_HandleErrorFunction | undefined;
281-
282274
/**
283275
* @private
284276
* PRIVATE - DO NOT USE
@@ -413,7 +405,6 @@ export interface RouterInit {
413405
window?: Window;
414406
dataStrategy?: DataStrategyFunction;
415407
patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
416-
unstable_handleError?: unstable_HandleErrorFunction;
417408
}
418409

419410
/**
@@ -482,20 +473,6 @@ export interface RouterSubscriber {
482473
): void;
483474
}
484475

485-
/**
486-
* Function signature for client side error handling for loader/actions errors
487-
* and rendering errors via `componentDidCatch`
488-
*/
489-
export interface unstable_HandleErrorFunction {
490-
(
491-
error: unknown,
492-
info: {
493-
location: Location;
494-
errorInfo?: React.ErrorInfo;
495-
},
496-
): void;
497-
}
498-
499476
/**
500477
* Function signature for determining the key to be used in scroll restoration
501478
* for a given location
@@ -880,7 +857,6 @@ export function createRouter(init: RouterInit): Router {
880857

881858
let hydrationRouteProperties = init.hydrationRouteProperties || [];
882859
let mapRouteProperties = init.mapRouteProperties || defaultMapRouteProperties;
883-
let unstable_handleError = init.unstable_handleError;
884860

885861
// Routes keyed by ID
886862
let manifest: RouteManifest = {};
@@ -3475,7 +3451,6 @@ export function createRouter(init: RouterInit): Router {
34753451
getBlocker,
34763452
deleteBlocker,
34773453
patchRoutes,
3478-
_internalHandleError: unstable_handleError,
34793454
_internalFetchControllers: fetchControllers,
34803455
// TODO: Remove setRoutes, it's temporary to avoid dealing with
34813456
// updating the tree while validating the update algorithm.

0 commit comments

Comments
 (0)