@remix-run/router 1.9.0-pre.0 → 1.9.0-pre.1

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/dist/utils.d.ts CHANGED
@@ -111,20 +111,20 @@ export type Submission = {
111
111
  * Arguments passed to route loader/action functions. Same for now but we keep
112
112
  * this as a private implementation detail in case they diverge in the future.
113
113
  */
114
- interface DataFunctionArgs {
114
+ interface DataFunctionArgs<Context> {
115
115
  request: Request;
116
116
  params: Params;
117
- context?: any;
117
+ context?: Context;
118
118
  }
119
119
  /**
120
120
  * Arguments passed to loader functions
121
121
  */
122
- export interface LoaderFunctionArgs extends DataFunctionArgs {
122
+ export interface LoaderFunctionArgs<C = any> extends DataFunctionArgs<C> {
123
123
  }
124
124
  /**
125
125
  * Arguments passed to action functions
126
126
  */
127
- export interface ActionFunctionArgs extends DataFunctionArgs {
127
+ export interface ActionFunctionArgs<C = any> extends DataFunctionArgs<C> {
128
128
  }
129
129
  /**
130
130
  * Loaders and actions can return anything except `undefined` (`null` is a
@@ -135,14 +135,14 @@ type DataFunctionValue = Response | NonNullable<unknown> | null;
135
135
  /**
136
136
  * Route loader function signature
137
137
  */
138
- export interface LoaderFunction {
139
- (args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
138
+ export interface LoaderFunction<C = any> {
139
+ (args: LoaderFunctionArgs<C>): Promise<DataFunctionValue> | DataFunctionValue;
140
140
  }
141
141
  /**
142
142
  * Route action function signature
143
143
  */
144
- export interface ActionFunction {
145
- (args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
144
+ export interface ActionFunction<C = any> {
145
+ (args: ActionFunctionArgs<C>): Promise<DataFunctionValue> | DataFunctionValue;
146
146
  }
147
147
  /**
148
148
  * Arguments passed to shouldRevalidate function
@@ -301,6 +301,14 @@ export declare function convertRoutesToDataRoutes(routes: AgnosticRouteObject[],
301
301
  * @see https://reactrouter.com/utils/match-routes
302
302
  */
303
303
  export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
304
+ export interface UIMatch<D = unknown, H = unknown> {
305
+ id: string;
306
+ pathname: string;
307
+ params: AgnosticRouteMatch["params"];
308
+ data: D;
309
+ handle: H;
310
+ }
311
+ export declare function convertRouteMatchToUiMatch(match: AgnosticDataRouteMatch, loaderData: RouteData): UIMatch;
304
312
  /**
305
313
  * Returns a path with params interpolated.
306
314
  *
package/history.ts CHANGED
@@ -49,15 +49,18 @@ export interface Path {
49
49
  hash: string;
50
50
  }
51
51
 
52
+ // TODO: (v7) Change the Location generic default from `any` to `unknown` and
53
+ // remove Remix `useLocation` wrapper.
54
+
52
55
  /**
53
56
  * An entry in a history stack. A location contains information about the
54
57
  * URL path, as well as possibly some arbitrary state and a key.
55
58
  */
56
- export interface Location extends Path {
59
+ export interface Location<S = any> extends Path {
57
60
  /**
58
61
  * A value of arbitrary data associated with this location.
59
62
  */
60
- state: any;
63
+ state: S;
61
64
 
62
65
  /**
63
66
  * A unique string associated with this location. May be used to safely store
package/index.ts CHANGED
@@ -25,6 +25,7 @@ export type {
25
25
  ShouldRevalidateFunction,
26
26
  ShouldRevalidateFunctionArgs,
27
27
  TrackedPromise,
28
+ UIMatch,
28
29
  V7_FormMethod,
29
30
  } from "./utils";
30
31
 
@@ -84,6 +85,7 @@ export {
84
85
  DeferredData as UNSAFE_DeferredData,
85
86
  ErrorResponseImpl as UNSAFE_ErrorResponseImpl,
86
87
  convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes,
88
+ convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch,
87
89
  getPathContributingMatches as UNSAFE_getPathContributingMatches,
88
90
  } from "./utils";
89
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.9.0-pre.0",
3
+ "version": "1.9.0-pre.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -11,7 +11,6 @@ import type {
11
11
  ActionFunction,
12
12
  AgnosticDataRouteMatch,
13
13
  AgnosticDataRouteObject,
14
- AgnosticRouteMatch,
15
14
  AgnosticRouteObject,
16
15
  DataResult,
17
16
  DeferredData,
@@ -31,12 +30,14 @@ import type {
31
30
  ShouldRevalidateFunctionArgs,
32
31
  Submission,
33
32
  SuccessResult,
33
+ UIMatch,
34
34
  V7_FormMethod,
35
35
  V7_MutationFormMethod,
36
36
  } from "./utils";
37
37
  import {
38
38
  ErrorResponseImpl,
39
39
  ResultType,
40
+ convertRouteMatchToUiMatch,
40
41
  convertRoutesToDataRoutes,
41
42
  getPathContributingMatches,
42
43
  immutableRouteKeys,
@@ -394,20 +395,12 @@ export interface RouterSubscriber {
394
395
  (state: RouterState): void;
395
396
  }
396
397
 
397
- interface UseMatchesMatch {
398
- id: string;
399
- pathname: string;
400
- params: AgnosticRouteMatch["params"];
401
- data: unknown;
402
- handle: unknown;
403
- }
404
-
405
398
  /**
406
399
  * Function signature for determining the key to be used in scroll restoration
407
400
  * for a given location
408
401
  */
409
402
  export interface GetScrollRestorationKeyFunction {
410
- (location: Location, matches: UseMatchesMatch[]): string | null;
403
+ (location: Location, matches: UIMatch[]): string | null;
411
404
  }
412
405
 
413
406
  /**
@@ -2461,7 +2454,7 @@ export function createRouter(init: RouterInit): Router {
2461
2454
  if (getScrollRestorationKey) {
2462
2455
  let key = getScrollRestorationKey(
2463
2456
  location,
2464
- matches.map((m) => createUseMatchesMatch(m, state.loaderData))
2457
+ matches.map((m) => convertRouteMatchToUiMatch(m, state.loaderData))
2465
2458
  );
2466
2459
  return key || location.key;
2467
2460
  }
@@ -4332,22 +4325,6 @@ function hasNakedIndexQuery(search: string): boolean {
4332
4325
  return new URLSearchParams(search).getAll("index").some((v) => v === "");
4333
4326
  }
4334
4327
 
4335
- // Note: This should match the format exported by useMatches, so if you change
4336
- // this please also change that :) Eventually we'll DRY this up
4337
- function createUseMatchesMatch(
4338
- match: AgnosticDataRouteMatch,
4339
- loaderData: RouteData
4340
- ): UseMatchesMatch {
4341
- let { route, pathname, params } = match;
4342
- return {
4343
- id: route.id,
4344
- pathname,
4345
- params,
4346
- data: loaderData[route.id] as unknown,
4347
- handle: route.handle as unknown,
4348
- };
4349
- }
4350
-
4351
4328
  function getTargetMatch(
4352
4329
  matches: AgnosticDataRouteMatch[],
4353
4330
  location: Location | string
package/utils.ts CHANGED
@@ -137,21 +137,24 @@ export type Submission =
137
137
  * Arguments passed to route loader/action functions. Same for now but we keep
138
138
  * this as a private implementation detail in case they diverge in the future.
139
139
  */
140
- interface DataFunctionArgs {
140
+ interface DataFunctionArgs<Context> {
141
141
  request: Request;
142
142
  params: Params;
143
- context?: any;
143
+ context?: Context;
144
144
  }
145
145
 
146
+ // TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
147
+ // ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
148
+
146
149
  /**
147
150
  * Arguments passed to loader functions
148
151
  */
149
- export interface LoaderFunctionArgs extends DataFunctionArgs {}
152
+ export interface LoaderFunctionArgs<C = any> extends DataFunctionArgs<C> {}
150
153
 
151
154
  /**
152
155
  * Arguments passed to action functions
153
156
  */
154
- export interface ActionFunctionArgs extends DataFunctionArgs {}
157
+ export interface ActionFunctionArgs<C = any> extends DataFunctionArgs<C> {}
155
158
 
156
159
  /**
157
160
  * Loaders and actions can return anything except `undefined` (`null` is a
@@ -163,15 +166,15 @@ type DataFunctionValue = Response | NonNullable<unknown> | null;
163
166
  /**
164
167
  * Route loader function signature
165
168
  */
166
- export interface LoaderFunction {
167
- (args: LoaderFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
169
+ export interface LoaderFunction<C = any> {
170
+ (args: LoaderFunctionArgs<C>): Promise<DataFunctionValue> | DataFunctionValue;
168
171
  }
169
172
 
170
173
  /**
171
174
  * Route action function signature
172
175
  */
173
- export interface ActionFunction {
174
- (args: ActionFunctionArgs): Promise<DataFunctionValue> | DataFunctionValue;
176
+ export interface ActionFunction<C = any> {
177
+ (args: ActionFunctionArgs<C>): Promise<DataFunctionValue> | DataFunctionValue;
175
178
  }
176
179
 
177
180
  /**
@@ -490,6 +493,28 @@ export function matchRoutes<
490
493
  return matches;
491
494
  }
492
495
 
496
+ export interface UIMatch<D = unknown, H = unknown> {
497
+ id: string;
498
+ pathname: string;
499
+ params: AgnosticRouteMatch["params"];
500
+ data: D;
501
+ handle: H;
502
+ }
503
+
504
+ export function convertRouteMatchToUiMatch(
505
+ match: AgnosticDataRouteMatch,
506
+ loaderData: RouteData
507
+ ): UIMatch {
508
+ let { route, pathname, params } = match;
509
+ return {
510
+ id: route.id,
511
+ pathname,
512
+ params,
513
+ data: loaderData[route.id],
514
+ handle: route.handle,
515
+ };
516
+ }
517
+
493
518
  interface RouteMeta<
494
519
  RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject
495
520
  > {