Skip to content
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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Dec 16, 2024

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.

Copy link

changeset-bot bot commented Dec 16, 2024

🦋 Changeset detected

Latest commit: 5bddcce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
react-router Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch

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;
Copy link
Contributor Author

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<{}>;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
}
Copy link
Contributor Author

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,
Copy link
Contributor Author

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<{
Copy link
Contributor

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)

@MichaelDeBoey MichaelDeBoey changed the title Slight reorg of the RouteModule types refactor(react-router): Slight reorg of the RouteModule types Dec 17, 2024
Comment on lines +141 to +143
export interface HeadersFunction {
(args: HeadersArgs): Headers | HeadersInit;
}
Copy link
Member

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

Suggested change
export interface HeadersFunction {
(args: HeadersArgs): Headers | HeadersInit;
}
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit;

Comment on lines +150 to 152
export type LayoutComponent = React.ComponentType<{
children: React.ReactElement;
}>;
Copy link
Member

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

Suggested change
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 {
Copy link
Member

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

Suggested change
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 {
Copy link
Member

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

Suggested change
export interface RouteModule {
export type RouteModule = {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants