Skip to content

Commit

Permalink
Remove deprecated detectErrorBoundaries (#11751)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Jul 1, 2024
1 parent 0457dbe commit 64f0d0a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-countries-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": major
---

Remove `@remix-run/router` deprecated `detectErrorBoundary` option in favor of `mapRouteProperties`
2 changes: 1 addition & 1 deletion packages/react-router/lib/dom/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function getStatelessNavigator() {

type CreateStaticHandlerOptions = Omit<
RouterCreateStaticHandlerOptions,
"detectErrorBoundary" | "mapRouteProperties"
"mapRouteProperties"
>;

/**
Expand Down
47 changes: 6 additions & 41 deletions packages/react-router/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
DataResult,
DataStrategyFunction,
DataStrategyFunctionArgs,
DetectErrorBoundaryFunction,
ErrorResult,
FormEncType,
FormMethod,
Expand Down Expand Up @@ -365,10 +364,6 @@ export interface RouterInit {
routes: AgnosticRouteObject[];
history: History;
basename?: string;
/**
* @deprecated Use `mapRouteProperties` instead
*/
detectErrorBoundary?: DetectErrorBoundaryFunction;
mapRouteProperties?: MapRoutePropertiesFunction;
future?: Partial<FutureConfig>;
hydrationData?: HydrationState;
Expand Down Expand Up @@ -799,18 +794,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 = {};
Expand Down Expand Up @@ -3287,10 +3271,6 @@ export function createRouter(init: RouterInit): Router {

export interface CreateStaticHandlerOptions {
basename?: string;
/**
* @deprecated Use `mapRouteProperties` instead
*/
detectErrorBoundary?: DetectErrorBoundaryFunction;
mapRouteProperties?: MapRoutePropertiesFunction;
future?: {};
}
Expand All @@ -3306,22 +3286,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,
Expand Down Expand Up @@ -4536,10 +4502,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,
});
Expand Down
10 changes: 0 additions & 10 deletions packages/react-router/lib/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,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<string, AgnosticDataRouteObject> {
shouldLoad: boolean;
Expand Down

0 comments on commit 64f0d0a

Please sign in to comment.