From e2822b9a1b4069b0b6b0e57f5b0e6b4f23038e0a Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 28 Jun 2024 16:04:42 -0400 Subject: [PATCH] Remove deprecated detectErrorBoundaries --- .changeset/two-countries-yell.md | 5 +++ packages/react-router/lib/dom/server.tsx | 2 +- packages/react-router/lib/router/router.ts | 47 +++------------------- packages/react-router/lib/router/utils.ts | 10 ----- 4 files changed, 12 insertions(+), 52 deletions(-) create mode 100644 .changeset/two-countries-yell.md diff --git a/.changeset/two-countries-yell.md b/.changeset/two-countries-yell.md new file mode 100644 index 0000000000..de7d6d5098 --- /dev/null +++ b/.changeset/two-countries-yell.md @@ -0,0 +1,5 @@ +--- +"react-router": major +--- + +Remove `@remix-run/router` deprecated `detectErrorBoundary` option in favor of `mapRouteProperties` diff --git a/packages/react-router/lib/dom/server.tsx b/packages/react-router/lib/dom/server.tsx index 000f951d91..e2f98bacb9 100644 --- a/packages/react-router/lib/dom/server.tsx +++ b/packages/react-router/lib/dom/server.tsx @@ -248,7 +248,7 @@ function getStatelessNavigator() { type CreateStaticHandlerOptions = Omit< RouterCreateStaticHandlerOptions, - "detectErrorBoundary" | "mapRouteProperties" + "mapRouteProperties" >; /** diff --git a/packages/react-router/lib/router/router.ts b/packages/react-router/lib/router/router.ts index 045ec11842..95e7d0b6c8 100644 --- a/packages/react-router/lib/router/router.ts +++ b/packages/react-router/lib/router/router.ts @@ -17,7 +17,6 @@ import type { DataStrategyFunctionArgs, DeferredData, DeferredResult, - DetectErrorBoundaryFunction, ErrorResult, FormEncType, FormMethod, @@ -375,10 +374,6 @@ export interface RouterInit { routes: AgnosticRouteObject[]; history: History; basename?: string; - /** - * @deprecated Use `mapRouteProperties` instead - */ - detectErrorBoundary?: DetectErrorBoundaryFunction; mapRouteProperties?: MapRoutePropertiesFunction; future?: Partial; hydrationData?: HydrationState; @@ -810,18 +805,7 @@ export function createRouter(init: RouterInit): Router { "You must provide a non-empty routes array to createRouter" ); - let mapRouteProperties: MapRoutePropertiesFunction; - if (init.mapRouteProperties) { - mapRouteProperties = init.mapRouteProperties; - } else if (init.detectErrorBoundary) { - // If they are still using the deprecated version, wrap it with the new API - let detectErrorBoundary = init.detectErrorBoundary; - mapRouteProperties = (route) => ({ - hasErrorBoundary: detectErrorBoundary(route), - }); - } else { - mapRouteProperties = defaultMapRouteProperties; - } + let mapRouteProperties = init.mapRouteProperties || defaultMapRouteProperties; // Routes keyed by ID let manifest: RouteManifest = {}; @@ -3399,10 +3383,6 @@ export const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred"); export interface CreateStaticHandlerOptions { basename?: string; - /** - * @deprecated Use `mapRouteProperties` instead - */ - detectErrorBoundary?: DetectErrorBoundaryFunction; mapRouteProperties?: MapRoutePropertiesFunction; future?: {}; } @@ -3418,22 +3398,8 @@ export function createStaticHandler( let manifest: RouteManifest = {}; let basename = (opts ? opts.basename : null) || "/"; - let mapRouteProperties: MapRoutePropertiesFunction; - if (opts?.mapRouteProperties) { - mapRouteProperties = opts.mapRouteProperties; - } else if (opts?.detectErrorBoundary) { - // If they are still using the deprecated version, wrap it with the new API - let detectErrorBoundary = opts.detectErrorBoundary; - mapRouteProperties = (route) => ({ - hasErrorBoundary: detectErrorBoundary(route), - }); - } else { - mapRouteProperties = defaultMapRouteProperties; - } - // Config driven behavior flags - let future = { - ...opts?.future, - }; + let mapRouteProperties = + opts?.mapRouteProperties || defaultMapRouteProperties; let dataRoutes = convertRoutesToDataRoutes( routes, @@ -4677,10 +4643,9 @@ async function loadLazyRouteModule( // updates and remove the `lazy` function so we don't resolve the lazy // route again. Object.assign(routeToUpdate, { - // To keep things framework agnostic, we use the provided - // `mapRouteProperties` (or wrapped `detectErrorBoundary`) function to - // set the framework-aware properties (`element`/`hasErrorBoundary`) since - // the logic will differ between frameworks. + // To keep things framework agnostic, we use the provided `mapRouteProperties` + // function to set the framework-aware properties (`element`/`hasErrorBoundary`) + // since the logic will differ between frameworks. ...mapRouteProperties(routeToUpdate), lazy: undefined, }); diff --git a/packages/react-router/lib/router/utils.ts b/packages/react-router/lib/router/utils.ts index 8547af9d81..99dd64b220 100644 --- a/packages/react-router/lib/router/utils.ts +++ b/packages/react-router/lib/router/utils.ts @@ -219,16 +219,6 @@ export interface ShouldRevalidateFunction { (args: ShouldRevalidateFunctionArgs): boolean; } -/** - * Function provided by the framework-aware layers to set `hasErrorBoundary` - * from the framework-aware `errorElement` prop - * - * @deprecated Use `mapRouteProperties` instead - */ -export interface DetectErrorBoundaryFunction { - (route: AgnosticRouteObject): boolean; -} - export interface DataStrategyMatch extends AgnosticRouteMatch { shouldLoad: boolean;