@remix-run/router 1.5.0 → 1.6.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.
package/utils.ts CHANGED
@@ -123,18 +123,25 @@ export interface LoaderFunctionArgs extends DataFunctionArgs {}
123
123
  */
124
124
  export interface ActionFunctionArgs extends DataFunctionArgs {}
125
125
 
126
+ /**
127
+ * Loaders and actions can return anything except `undefined` (`null` is a
128
+ * valid return value if there is no data to return). Responses are preferred
129
+ * and will ease any future migration to Remix
130
+ */
131
+ type DataFunctionValue = Response | NonNullable<unknown> | null;
132
+
126
133
  /**
127
134
  * Route loader function signature
128
135
  */
129
136
  export interface LoaderFunction {
130
- (args: LoaderFunctionArgs): Promise<Response> | Response | Promise<any> | any;
137
+ (args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
131
138
  }
132
139
 
133
140
  /**
134
141
  * Route action function signature
135
142
  */
136
143
  export interface ActionFunction {
137
- (args: ActionFunctionArgs): Promise<Response> | Response | Promise<any> | any;
144
+ (args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
138
145
  }
139
146
 
140
147
  /**
@@ -162,11 +169,23 @@ export interface ShouldRevalidateFunction {
162
169
  /**
163
170
  * Function provided by the framework-aware layers to set `hasErrorBoundary`
164
171
  * from the framework-aware `errorElement` prop
172
+ *
173
+ * @deprecated Use `mapRouteProperties` instead
165
174
  */
166
175
  export interface DetectErrorBoundaryFunction {
167
176
  (route: AgnosticRouteObject): boolean;
168
177
  }
169
178
 
179
+ /**
180
+ * Function provided by the framework-aware layers to set any framework-specific
181
+ * properties from framework-agnostic properties
182
+ */
183
+ export interface MapRoutePropertiesFunction {
184
+ (route: AgnosticRouteObject): {
185
+ hasErrorBoundary: boolean;
186
+ } & Record<string, any>;
187
+ }
188
+
170
189
  /**
171
190
  * Keys we cannot change from within a lazy() function. We spread all other keys
172
191
  * onto the route. Either they're meaningful to the router, or they'll get
@@ -338,7 +357,7 @@ function isIndexRoute(
338
357
  // solely with AgnosticDataRouteObject's within the Router
339
358
  export function convertRoutesToDataRoutes(
340
359
  routes: AgnosticRouteObject[],
341
- detectErrorBoundary: DetectErrorBoundaryFunction,
360
+ mapRouteProperties: MapRoutePropertiesFunction,
342
361
  parentPath: number[] = [],
343
362
  manifest: RouteManifest = {}
344
363
  ): AgnosticDataRouteObject[] {
@@ -358,7 +377,7 @@ export function convertRoutesToDataRoutes(
358
377
  if (isIndexRoute(route)) {
359
378
  let indexRoute: AgnosticDataIndexRouteObject = {
360
379
  ...route,
361
- hasErrorBoundary: detectErrorBoundary(route),
380
+ ...mapRouteProperties(route),
362
381
  id,
363
382
  };
364
383
  manifest[id] = indexRoute;
@@ -366,8 +385,8 @@ export function convertRoutesToDataRoutes(
366
385
  } else {
367
386
  let pathOrLayoutRoute: AgnosticDataNonIndexRouteObject = {
368
387
  ...route,
388
+ ...mapRouteProperties(route),
369
389
  id,
370
- hasErrorBoundary: detectErrorBoundary(route),
371
390
  children: undefined,
372
391
  };
373
392
  manifest[id] = pathOrLayoutRoute;
@@ -375,7 +394,7 @@ export function convertRoutesToDataRoutes(
375
394
  if (route.children) {
376
395
  pathOrLayoutRoute.children = convertRoutesToDataRoutes(
377
396
  route.children,
378
- detectErrorBoundary,
397
+ mapRouteProperties,
379
398
  treePath,
380
399
  manifest
381
400
  );