From 52736b08023ea6a424f736a5c1d2185967bc3285 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 17 Jan 2025 06:34:47 +0100 Subject: [PATCH] Revert "feat(router): Better autocomplete for ``s (#11769)" This reverts commit 9e6b769fb770c1f2fb01910d72c65431c3197b62. --- .changesets/11769.md | 3 -- packages/router/src/Set.tsx | 75 +++++++++++++------------------------ 2 files changed, 25 insertions(+), 53 deletions(-) delete mode 100644 .changesets/11769.md diff --git a/.changesets/11769.md b/.changesets/11769.md deleted file mode 100644 index 13720912a477..000000000000 --- a/.changesets/11769.md +++ /dev/null @@ -1,3 +0,0 @@ -- feat(router): Better autocomplete for ``s (#11769) by @Tobbe - -There's a limit to 10 wrapper components. After that additional props will not be included. To work around this you can either make sure to put wrapper components that doesn't require any props last, or just split your wrappers between multiple ``s diff --git a/packages/router/src/Set.tsx b/packages/router/src/Set.tsx index 80b66c284d4e..98403546a7f7 100644 --- a/packages/router/src/Set.tsx +++ b/packages/router/src/Set.tsx @@ -3,7 +3,12 @@ import React from 'react' import type { AvailableRoutes } from '@redwoodjs/router' -type RegularSetProps = { +type SetProps

= (P extends React.FC ? React.ComponentProps

: unknown) & { + /** + * A react component that the children of the Set will be wrapped + * in (typically a Layout component) + */ + wrap?: P /** *`Routes` nested in a `` with `private` specified require * authentication. When a user is not authenticated and attempts to visit @@ -18,38 +23,6 @@ type RegularSetProps = { * @deprecated Please use `` instead and specify this prop there */ unauthenticated?: keyof AvailableRoutes -} - -/** - * A set containing public ``s - */ -export function Set( - props: CommonSetProps & RegularSetProps, -) { - // @MARK: Virtual Component, this is actually never rendered - // See analyzeRoutes in utils.tsx, inside the isSetNode block - return <>{props.children} -} - -type CommonSetProps

= (P extends React.FC - ? React.ComponentProps

- : P extends React.FC[] - ? React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps & - React.ComponentProps - : unknown) & { - /** - * A React component, or an array of React components, that the children of - * the Set will be wrapped in (typically a Layout component and/or a context) - */ - wrap?: P /** * Route is permitted when authenticated and user has any of the provided * roles such as "admin" or ["admin", "editor"] @@ -63,13 +36,22 @@ type CommonSetProps

= (P extends React.FC whileLoadingPage?: () => ReactElement | null } +/** + * A set containing public ``s + */ +export function Set(props: SetProps) { + // @MARK: Virtual Component, this is actually never rendered + // See analyzeRoutes in utils.tsx, inside the isSetNode block + return <>{props.children} +} + +type PrivateSetProps

= Omit, 'private' | 'unauthenticated'> & { + /** The page name where a user will be redirected when not authenticated */ + unauthenticated: keyof AvailableRoutes +} + /** @deprecated Please use `` instead */ -export function Private( - props: CommonSetProps & { - /** The page name where a user will be redirected when not authenticated */ - unauthenticated: keyof AvailableRoutes - }, -) { +export function Private(props: PrivateSetProps) { // @MARK Virtual Component, this is actually never rendered // See analyzeRoutes in utils.tsx, inside the isSetNode block return <>{props.children} @@ -78,12 +60,7 @@ export function Private( /** * A set containing private ``s that require authentication to access */ -export function PrivateSet( - props: CommonSetProps & { - /** The page name where a user will be redirected when not authenticated */ - unauthenticated: keyof AvailableRoutes - }, -) { +export function PrivateSet(props: PrivateSetProps) { // @MARK Virtual Component, this is actually never rendered // See analyzeRoutes in utils.tsx, inside the isSetNode block return <>{props.children} @@ -91,7 +68,7 @@ export function PrivateSet( export const isSetNode = ( node: ReactNode, -): node is ReactElement & RegularSetProps> => { +): node is ReactElement> => { return ( React.isValidElement(node) && (node.type === Set || node.type === PrivateSet || node.type === Private) && @@ -102,15 +79,13 @@ export const isSetNode = ( export const isPrivateSetNode = ( node: ReactNode, -): node is ReactElement< - CommonSetProps & { unauthenticated: keyof AvailableRoutes } -> => { +): node is ReactElement> => { return React.isValidElement(node) && node.type === PrivateSet } // Only identifies nodes, not nodes export const isPrivateNode = ( node: ReactNode, -): node is ReactElement & RegularSetProps> => { +): node is ReactElement> => { return React.isValidElement(node) && node.type === Private }