Skip to content

Commit

Permalink
Enhance the LayoutComponent type (#8910)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Feb 28, 2024
1 parent 8de0a5a commit 97cc8ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-games-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

Strengthen the internal `LayoutComponent` type to accept limited children
9 changes: 7 additions & 2 deletions packages/remix-react/routeModules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentType } from "react";
import type { ComponentType, ReactElement } from "react";
import type {
ActionFunction as RRActionFunction,
ActionFunctionArgs as RRActionFunctionArgs,
Expand Down Expand Up @@ -78,7 +78,12 @@ export type HydrateFallbackComponent = ComponentType;
* Useful for defining the <html>/<head>/<body> document shell shared by the
* Component, HydrateFallback, and ErrorBoundary
*/
export type LayoutComponent = ComponentType;
export type LayoutComponent = ComponentType<{
children: ReactElement<
unknown,
ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent
>;
}>;

/**
* A function that defines `<link>` tags to be inserted into the `<head>` of
Expand Down
24 changes: 12 additions & 12 deletions packages/remix-react/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,28 @@ function getRouteComponents(
return {
...(Component
? {
element: React.createElement(
routeModule.Layout,
null,
React.createElement(Component)
element: (
<routeModule.Layout>
<Component />
</routeModule.Layout>
),
}
: { Component }),
...(ErrorBoundary
? {
errorElement: React.createElement(
routeModule.Layout,
null,
React.createElement(ErrorBoundary)
errorElement: (
<routeModule.Layout>
<ErrorBoundary />
</routeModule.Layout>
),
}
: { ErrorBoundary }),
...(HydrateFallback
? {
hydrateFallbackElement: React.createElement(
routeModule.Layout,
null,
React.createElement(HydrateFallback)
hydrateFallbackElement: (
<routeModule.Layout>
<HydrateFallback />
</routeModule.Layout>
),
}
: { HydrateFallback }),
Expand Down

0 comments on commit 97cc8ec

Please sign in to comment.