Skip to content

Commit

Permalink
Fix types for PatchRoutesOnNavigationFunction (#11976)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Sep 10, 2024
1 parent 19ba686 commit 0fc83f8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/react-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export type {
NavigateOptions,
Navigator,
NonIndexRouteObject,
PatchRoutesOnNavigationFunction,
PatchRoutesOnNavigationFunctionArgs,
RouteMatch,
RouteObject,
} from "./lib/context";
Expand All @@ -93,7 +95,6 @@ export type {
RouterProps,
RouterProviderProps,
RoutesProps,
PatchRoutesOnNavigationFunction as PatchRoutesOnNavigationFunction,
} from "./lib/components";
export type { NavigateFunction } from "./lib/hooks";
export {
Expand Down
5 changes: 1 addition & 4 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
} from "./router/router";
import { createRouter } from "./router/router";
import type {
AgnosticPatchRoutesOnNavigationFunction,
DataStrategyFunction,
LazyRouteFunction,
TrackedPromise,
Expand All @@ -35,6 +34,7 @@ import type {
IndexRouteObject,
Navigator,
NonIndexRouteObject,
PatchRoutesOnNavigationFunction,
RouteMatch,
RouteObject,
ViewTransitionContextObject,
Expand Down Expand Up @@ -130,9 +130,6 @@ export function mapRouteProperties(route: RouteObject) {
return updates;
}

export interface PatchRoutesOnNavigationFunction
extends AgnosticPatchRoutesOnNavigationFunction<RouteMatch> {}

/**
* @category Routers
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/react-router/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type {
import type {
AgnosticIndexRouteObject,
AgnosticNonIndexRouteObject,
AgnosticPatchRoutesOnNavigationFunction,
AgnosticPatchRoutesOnNavigationFunctionArgs,
AgnosticRouteMatch,
LazyRouteFunction,
TrackedPromise,
Expand Down Expand Up @@ -74,6 +76,12 @@ export interface RouteMatch<

export interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {}

export type PatchRoutesOnNavigationFunctionArgs =
AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;

export type PatchRoutesOnNavigationFunction =
AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;

export interface DataRouterContextObject
// Omit `future` since those can be pulled from the `router`
// `NavigationContext` needs future since it doesn't have a `router` in all cases
Expand Down
7 changes: 5 additions & 2 deletions packages/react-router/lib/dom/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ import {
mergeRefs,
usePrefetchBehavior,
} from "./ssr/components";
import type { PatchRoutesOnNavigationFunction } from "../components";
import { Router, mapRouteProperties } from "../components";
import type { RouteObject, NavigateOptions } from "../context";
import type {
RouteObject,
NavigateOptions,
PatchRoutesOnNavigationFunction,
} from "../context";
import {
DataRouterContext,
DataRouterStateContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/lib/dom/ssr/fog-of-war.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import type { PatchRoutesOnNavigationFunction } from "../../components";
import type { PatchRoutesOnNavigationFunction } from "../../context";
import type { Router as RemixRouter } from "../../router/router";
import { matchRoutes } from "../../router/utils";
import type { AssetsManifest } from "./entry";
Expand Down
22 changes: 14 additions & 8 deletions packages/react-router/lib/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,21 @@ export interface DataStrategyFunction {
(args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
}

export interface AgnosticPatchRoutesOnNavigationFunction<
export type AgnosticPatchRoutesOnNavigationFunctionArgs<
O extends AgnosticRouteObject = AgnosticRouteObject,
M extends AgnosticRouteMatch = AgnosticRouteMatch
> {
(opts: {
path: string;
matches: M[];
patch: (routeId: string | null, children: AgnosticRouteObject[]) => void;
}): void | Promise<void>;
}
> = {
path: string;
matches: M[];
patch: (routeId: string | null, children: O[]) => void;
};

export type AgnosticPatchRoutesOnNavigationFunction<
O extends AgnosticRouteObject = AgnosticRouteObject,
M extends AgnosticRouteMatch = AgnosticRouteMatch
> = (
opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>
) => void | Promise<void>;

/**
* Function provided by the framework-aware layers to set any framework-specific
Expand Down

0 comments on commit 0fc83f8

Please sign in to comment.