-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(react-router): Slight reorg of the RouteModule
types
#12560
base: dev
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 5bddcce The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
/** | ||
* ErrorBoundary to display for this route | ||
*/ | ||
ErrorBoundary?: React.ComponentType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got rid of the type aliases here in favor of just using React.Component
type directly.
/** | ||
* Defines the component that will render when the route matches. | ||
*/ | ||
default: React.ComponentType<{}>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined but I think this is invalid now with the typegen props - going to look into making this actually pull the typegen stuff (CreateComponentProps
) with unknown
values for route-specific info
* They are only called on the server when server rendering or during the | ||
* build with pre-rendering. | ||
*/ | ||
loader?: LoaderFunction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved into this file from the now deleted version from server-runtime
export type HydrateFallbackComponent = ComponentType; | ||
export interface HeadersFunction { | ||
(args: HeadersArgs): Headers | HeadersInit; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved in from the server-runtime file
MetaArgs, | ||
MetaDescriptor, | ||
MetaFunction, | ||
LinksFunction, | ||
ServerRouteModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be weird, and potentially even a sign that this doesn't belong in type docs?
This is not a user-facing type but the only way to get the typedoc generated is to make it public API so we have to export it even though we never want anyone to import it and use it.
unknown, | ||
ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent | ||
>; | ||
export type LayoutComponent = React.ComponentType<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I legit didn't know this type existed, FWIW I added it here and got a comment from Michael to maybe change it to a different React type, check it out here:
#12543 (comment)
RouteModule
types
export interface HeadersFunction { | ||
(args: HeadersArgs): Headers | HeadersInit; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to
export interface HeadersFunction { | |
(args: HeadersArgs): Headers | HeadersInit; | |
} | |
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit; |
export type LayoutComponent = React.ComponentType<{ | ||
children: React.ReactElement; | ||
}>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to
export type LayoutComponent = React.ComponentType<{ | |
children: React.ReactElement; | |
}>; | |
export type LayoutComponent = React.ComponentType<React.PropsWithChildren>; |
/** | ||
* The shape of a route module file for your application | ||
*/ | ||
export interface ServerRouteModule extends RouteModule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this to be an interface
export interface ServerRouteModule extends RouteModule { | |
export type ServerRouteModule = RouteModule & { |
@@ -18,19 +18,82 @@ export interface RouteModules { | |||
[routeId: string]: RouteModule | undefined; | |||
} | |||
|
|||
/** | |||
* The shape of a route module shipped to the client | |||
*/ | |||
export interface RouteModule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a type
as well
export interface RouteModule { | |
export type RouteModule = { |
The primary goal of this PR is to provide typedoc for the file-based route module interface as a place for long form docs to link to - sort of an auto-generated version of https://reactrouter.com/start/framework/route-module. Then I added cross-links to the markdown doc which only had them for a few sections.
I also consolidated/de-duped some of the types that use to have to be duplicated across the
@remix-run/server-runtime
and@remix-run/react
packages.