react-router 7.2.0-pre.3 → 7.2.0-pre.5
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/CHANGELOG.md +8 -0
- package/dist/development/{chunk-YJVE32LY.mjs → chunk-FCWNNWGU.mjs} +17 -6
- package/dist/development/dom-export.d.mts +2 -2
- package/dist/development/dom-export.d.ts +2 -2
- package/dist/development/dom-export.js +16 -5
- package/dist/development/dom-export.mjs +2 -2
- package/dist/development/{fog-of-war-NSBQ-FR3.d.mts → fog-of-war-BALYJxf_.d.mts} +1 -1
- package/dist/{production/fog-of-war-D_yo3J7q.d.ts → development/fog-of-war-Cm1iXIp7.d.ts} +1 -1
- package/dist/development/index.d.mts +4 -4
- package/dist/development/index.d.ts +4 -4
- package/dist/development/index.js +17 -6
- package/dist/development/index.mjs +2 -2
- package/dist/development/lib/types/route-module.d.mts +81 -2
- package/dist/development/lib/types/route-module.d.ts +81 -2
- package/dist/development/lib/types/route-module.js +1 -1
- package/dist/development/lib/types/route-module.mjs +1 -1
- package/dist/development/{route-data-B_Qv26O_.d.ts → route-data-BmvbmBej.d.mts} +63 -0
- package/dist/{production/route-data-B_Qv26O_.d.mts → development/route-data-BmvbmBej.d.ts} +63 -0
- package/dist/production/{chunk-LDDZALL2.mjs → chunk-7XNVUWNN.mjs} +17 -6
- package/dist/production/dom-export.d.mts +2 -2
- package/dist/production/dom-export.d.ts +2 -2
- package/dist/production/dom-export.js +16 -5
- package/dist/production/dom-export.mjs +2 -2
- package/dist/production/{fog-of-war-NSBQ-FR3.d.mts → fog-of-war-BALYJxf_.d.mts} +1 -1
- package/dist/{development/fog-of-war-D_yo3J7q.d.ts → production/fog-of-war-Cm1iXIp7.d.ts} +1 -1
- package/dist/production/index.d.mts +4 -4
- package/dist/production/index.d.ts +4 -4
- package/dist/production/index.js +17 -6
- package/dist/production/index.mjs +2 -2
- package/dist/production/lib/types/route-module.d.mts +81 -2
- package/dist/production/lib/types/route-module.d.ts +81 -2
- package/dist/production/lib/types/route-module.js +1 -1
- package/dist/production/lib/types/route-module.mjs +1 -1
- package/dist/production/{route-data-B_Qv26O_.d.ts → route-data-BmvbmBej.d.mts} +63 -0
- package/dist/{development/route-data-B_Qv26O_.d.mts → production/route-data-BmvbmBej.d.ts} +63 -0
- package/package.json +1 -1
|
@@ -266,8 +266,28 @@ type Submission = {
|
|
|
266
266
|
* this as a private implementation detail in case they diverge in the future.
|
|
267
267
|
*/
|
|
268
268
|
interface DataFunctionArgs<Context> {
|
|
269
|
+
/** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
|
|
269
270
|
request: Request;
|
|
271
|
+
/**
|
|
272
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
273
|
+
* @example
|
|
274
|
+
* // app/routes.ts
|
|
275
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
276
|
+
*
|
|
277
|
+
* // app/team.tsx
|
|
278
|
+
* export function loader({
|
|
279
|
+
* params,
|
|
280
|
+
* }: Route.LoaderArgs) {
|
|
281
|
+
* params.teamId;
|
|
282
|
+
* // ^ string
|
|
283
|
+
* }
|
|
284
|
+
**/
|
|
270
285
|
params: Params;
|
|
286
|
+
/**
|
|
287
|
+
* This is the context passed in to your server adapter's getLoadContext() function.
|
|
288
|
+
* It's a way to bridge the gap between the adapter's request/response API with your React Router app.
|
|
289
|
+
* It is only applicable if you are using a custom server adapter.
|
|
290
|
+
*/
|
|
271
291
|
context?: Context;
|
|
272
292
|
}
|
|
273
293
|
/**
|
|
@@ -305,18 +325,56 @@ interface ActionFunction<Context = any> {
|
|
|
305
325
|
* Arguments passed to shouldRevalidate function
|
|
306
326
|
*/
|
|
307
327
|
interface ShouldRevalidateFunctionArgs {
|
|
328
|
+
/** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
|
|
308
329
|
currentUrl: URL;
|
|
330
|
+
/** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
|
|
309
331
|
currentParams: AgnosticDataRouteMatch["params"];
|
|
332
|
+
/** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
|
|
310
333
|
nextUrl: URL;
|
|
334
|
+
/** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
|
|
311
335
|
nextParams: AgnosticDataRouteMatch["params"];
|
|
336
|
+
/** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
|
|
312
337
|
formMethod?: Submission["formMethod"];
|
|
338
|
+
/** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
|
|
313
339
|
formAction?: Submission["formAction"];
|
|
340
|
+
/** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
|
|
314
341
|
formEncType?: Submission["formEncType"];
|
|
342
|
+
/** The form submission data when the form's encType is `text/plain` */
|
|
315
343
|
text?: Submission["text"];
|
|
344
|
+
/** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
|
|
316
345
|
formData?: Submission["formData"];
|
|
346
|
+
/** The form submission data when the form's encType is `application/json` */
|
|
317
347
|
json?: Submission["json"];
|
|
348
|
+
/** The status code of the action response */
|
|
318
349
|
actionStatus?: number;
|
|
350
|
+
/**
|
|
351
|
+
* When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* export async function action() {
|
|
355
|
+
* await saveSomeStuff();
|
|
356
|
+
* return { ok: true };
|
|
357
|
+
* }
|
|
358
|
+
*
|
|
359
|
+
* export function shouldRevalidate({
|
|
360
|
+
* actionResult,
|
|
361
|
+
* }) {
|
|
362
|
+
* if (actionResult?.ok) {
|
|
363
|
+
* return false;
|
|
364
|
+
* }
|
|
365
|
+
* return true;
|
|
366
|
+
* }
|
|
367
|
+
*/
|
|
319
368
|
actionResult?: any;
|
|
369
|
+
/**
|
|
370
|
+
* By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
|
|
371
|
+
*
|
|
372
|
+
* /projects/123/tasks/abc
|
|
373
|
+
* /projects/123/tasks/def
|
|
374
|
+
* React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
|
|
375
|
+
*
|
|
376
|
+
* It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
|
|
377
|
+
*/
|
|
320
378
|
defaultShouldRevalidate: boolean;
|
|
321
379
|
}
|
|
322
380
|
/**
|
|
@@ -473,8 +531,13 @@ declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = Agnos
|
|
|
473
531
|
interface UIMatch<Data = unknown, Handle = unknown> {
|
|
474
532
|
id: string;
|
|
475
533
|
pathname: string;
|
|
534
|
+
/**
|
|
535
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
|
|
536
|
+
**/
|
|
476
537
|
params: AgnosticRouteMatch["params"];
|
|
538
|
+
/** The return value from the matched route's loader or clientLoader */
|
|
477
539
|
data: Data;
|
|
540
|
+
/** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
|
|
478
541
|
handle: Handle;
|
|
479
542
|
}
|
|
480
543
|
/**
|
|
@@ -266,8 +266,28 @@ type Submission = {
|
|
|
266
266
|
* this as a private implementation detail in case they diverge in the future.
|
|
267
267
|
*/
|
|
268
268
|
interface DataFunctionArgs<Context> {
|
|
269
|
+
/** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
|
|
269
270
|
request: Request;
|
|
271
|
+
/**
|
|
272
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
273
|
+
* @example
|
|
274
|
+
* // app/routes.ts
|
|
275
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
276
|
+
*
|
|
277
|
+
* // app/team.tsx
|
|
278
|
+
* export function loader({
|
|
279
|
+
* params,
|
|
280
|
+
* }: Route.LoaderArgs) {
|
|
281
|
+
* params.teamId;
|
|
282
|
+
* // ^ string
|
|
283
|
+
* }
|
|
284
|
+
**/
|
|
270
285
|
params: Params;
|
|
286
|
+
/**
|
|
287
|
+
* This is the context passed in to your server adapter's getLoadContext() function.
|
|
288
|
+
* It's a way to bridge the gap between the adapter's request/response API with your React Router app.
|
|
289
|
+
* It is only applicable if you are using a custom server adapter.
|
|
290
|
+
*/
|
|
271
291
|
context?: Context;
|
|
272
292
|
}
|
|
273
293
|
/**
|
|
@@ -305,18 +325,56 @@ interface ActionFunction<Context = any> {
|
|
|
305
325
|
* Arguments passed to shouldRevalidate function
|
|
306
326
|
*/
|
|
307
327
|
interface ShouldRevalidateFunctionArgs {
|
|
328
|
+
/** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
|
|
308
329
|
currentUrl: URL;
|
|
330
|
+
/** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
|
|
309
331
|
currentParams: AgnosticDataRouteMatch["params"];
|
|
332
|
+
/** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
|
|
310
333
|
nextUrl: URL;
|
|
334
|
+
/** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
|
|
311
335
|
nextParams: AgnosticDataRouteMatch["params"];
|
|
336
|
+
/** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
|
|
312
337
|
formMethod?: Submission["formMethod"];
|
|
338
|
+
/** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
|
|
313
339
|
formAction?: Submission["formAction"];
|
|
340
|
+
/** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
|
|
314
341
|
formEncType?: Submission["formEncType"];
|
|
342
|
+
/** The form submission data when the form's encType is `text/plain` */
|
|
315
343
|
text?: Submission["text"];
|
|
344
|
+
/** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
|
|
316
345
|
formData?: Submission["formData"];
|
|
346
|
+
/** The form submission data when the form's encType is `application/json` */
|
|
317
347
|
json?: Submission["json"];
|
|
348
|
+
/** The status code of the action response */
|
|
318
349
|
actionStatus?: number;
|
|
350
|
+
/**
|
|
351
|
+
* When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* export async function action() {
|
|
355
|
+
* await saveSomeStuff();
|
|
356
|
+
* return { ok: true };
|
|
357
|
+
* }
|
|
358
|
+
*
|
|
359
|
+
* export function shouldRevalidate({
|
|
360
|
+
* actionResult,
|
|
361
|
+
* }) {
|
|
362
|
+
* if (actionResult?.ok) {
|
|
363
|
+
* return false;
|
|
364
|
+
* }
|
|
365
|
+
* return true;
|
|
366
|
+
* }
|
|
367
|
+
*/
|
|
319
368
|
actionResult?: any;
|
|
369
|
+
/**
|
|
370
|
+
* By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
|
|
371
|
+
*
|
|
372
|
+
* /projects/123/tasks/abc
|
|
373
|
+
* /projects/123/tasks/def
|
|
374
|
+
* React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
|
|
375
|
+
*
|
|
376
|
+
* It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
|
|
377
|
+
*/
|
|
320
378
|
defaultShouldRevalidate: boolean;
|
|
321
379
|
}
|
|
322
380
|
/**
|
|
@@ -473,8 +531,13 @@ declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = Agnos
|
|
|
473
531
|
interface UIMatch<Data = unknown, Handle = unknown> {
|
|
474
532
|
id: string;
|
|
475
533
|
pathname: string;
|
|
534
|
+
/**
|
|
535
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
|
|
536
|
+
**/
|
|
476
537
|
params: AgnosticRouteMatch["params"];
|
|
538
|
+
/** The return value from the matched route's loader or clientLoader */
|
|
477
539
|
data: Data;
|
|
540
|
+
/** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
|
|
478
541
|
handle: Handle;
|
|
479
542
|
}
|
|
480
543
|
/**
|