Skip to content

Commit 4a75aa1

Browse files
scttcperevanpurkhisergetsantry[bot]
authored
feat(rr6): Add deprecatedRouterProps to route objects (#96588)
This uses typescript to enforce that only some routes are injected with the legacy router props. This way we can slowly reduce the components that require this react router 3 style prop. Removes the "NoOp" route component and renders undefined instead which react router 6 should just render the child? --------- Co-authored-by: Evan Purkhiser <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent d26758e commit 4a75aa1

File tree

13 files changed

+336
-32
lines changed

13 files changed

+336
-32
lines changed

static/app/components/route.tsx

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
* routing object in that it doesn't take a rendered component, but instead a
44
* component type and handles the rendering itself.
55
*/
6-
export interface SentryRouteObject {
6+
interface BaseRouteObject {
77
/**
88
* child components to render under this route
99
*/
1010
children?: SentryRouteObject[];
11-
/**
12-
* A react component to render or a import promise that will be lazily loaded
13-
*/
14-
component?: React.ComponentType<any>;
1511
/**
1612
* Only enable this route when USING_CUSTOMER_DOMAIN is enabled
1713
*/
1814
customerDomainOnlyRoute?: true;
15+
/**
16+
* Injects react router 3 style router props to the component.
17+
* Including an `Outlet` component as a child element.
18+
*/
19+
deprecatedRouteProps?: never;
1920
/**
2021
* Is a index route
2122
*/
@@ -52,9 +53,45 @@ export interface SentryRouteObject {
5253
* withDomainRedirect respectively.
5354
*/
5455
withOrgPath?: boolean;
56+
}
5557

56-
// XXX(epurkhiser): In the future we can introduce a `requiresLegacyProps`
57-
// prop here that will pass in the react-router 3 style routing props. We can
58-
// use this as a way to slowly get rid of react router 3 style prosp in favor
59-
// of using the route hooks.
58+
/**
59+
* Enforces that these props are not expected by the component.
60+
*/
61+
type NoRouteProps = {
62+
[key: string | number | symbol]: any;
63+
children?: never;
64+
location?: never;
65+
params?: never;
66+
route?: never;
67+
routeParams?: never;
68+
router?: never;
69+
routes?: never;
70+
};
71+
72+
interface DeprecatedPropRoute extends Omit<BaseRouteObject, 'deprecatedRouteProps'> {
73+
/**
74+
* A react component that accepts legacy router props (location, params, router, etc.)
75+
*/
76+
component: React.ComponentType<any>;
77+
/**
78+
* Passes legacy route props to the component.
79+
*/
80+
deprecatedRouteProps: true;
6081
}
82+
83+
interface RouteObject extends BaseRouteObject {
84+
/**
85+
* A react component to render. Components that expect RouteComponentProps are
86+
* not allowed here. Use deprecatedRouteProps: true on legacy components. New
87+
* components should use the `use{Params,Location}` hooks.
88+
* Components that expect RouteComponentProps are not allowed here - use deprecatedRouteProps: true instead.
89+
*/
90+
component: React.ComponentType<NoRouteProps>;
91+
}
92+
93+
interface NoComponentRoute extends BaseRouteObject {
94+
component?: never;
95+
}
96+
97+
export type SentryRouteObject = RouteObject | DeprecatedPropRoute | NoComponentRoute;

0 commit comments

Comments
 (0)