Skip to content

Commit 0be8708

Browse files
authored
Revert "feat(router): Better autocomplete for <Set>s (#11769)" (#11902)
1 parent 5f485c8 commit 0be8708

File tree

2 files changed

+25
-53
lines changed

2 files changed

+25
-53
lines changed

.changesets/11769.md

-3
This file was deleted.

packages/router/src/Set.tsx

+25-50
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import React from 'react'
33

44
import type { AvailableRoutes } from '@redwoodjs/router'
55

6-
type RegularSetProps = {
6+
type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
7+
/**
8+
* A react component that the children of the Set will be wrapped
9+
* in (typically a Layout component)
10+
*/
11+
wrap?: P
712
/**
813
*`Routes` nested in a `<Set>` with `private` specified require
914
* authentication. When a user is not authenticated and attempts to visit
@@ -18,38 +23,6 @@ type RegularSetProps = {
1823
* @deprecated Please use `<PrivateSet>` instead and specify this prop there
1924
*/
2025
unauthenticated?: keyof AvailableRoutes
21-
}
22-
23-
/**
24-
* A set containing public `<Route />`s
25-
*/
26-
export function Set<WrapperProps>(
27-
props: CommonSetProps<WrapperProps> & RegularSetProps,
28-
) {
29-
// @MARK: Virtual Component, this is actually never rendered
30-
// See analyzeRoutes in utils.tsx, inside the isSetNode block
31-
return <>{props.children}</>
32-
}
33-
34-
type CommonSetProps<P> = (P extends React.FC<any>
35-
? React.ComponentProps<P>
36-
: P extends React.FC<any>[]
37-
? React.ComponentProps<P[0]> &
38-
React.ComponentProps<P[1]> &
39-
React.ComponentProps<P[2]> &
40-
React.ComponentProps<P[3]> &
41-
React.ComponentProps<P[4]> &
42-
React.ComponentProps<P[5]> &
43-
React.ComponentProps<P[6]> &
44-
React.ComponentProps<P[7]> &
45-
React.ComponentProps<P[8]> &
46-
React.ComponentProps<P[9]>
47-
: unknown) & {
48-
/**
49-
* A React component, or an array of React components, that the children of
50-
* the Set will be wrapped in (typically a Layout component and/or a context)
51-
*/
52-
wrap?: P
5326
/**
5427
* Route is permitted when authenticated and user has any of the provided
5528
* roles such as "admin" or ["admin", "editor"]
@@ -63,13 +36,22 @@ type CommonSetProps<P> = (P extends React.FC<any>
6336
whileLoadingPage?: () => ReactElement | null
6437
}
6538

39+
/**
40+
* A set containing public `<Route />`s
41+
*/
42+
export function Set<WrapperProps>(props: SetProps<WrapperProps>) {
43+
// @MARK: Virtual Component, this is actually never rendered
44+
// See analyzeRoutes in utils.tsx, inside the isSetNode block
45+
return <>{props.children}</>
46+
}
47+
48+
type PrivateSetProps<P> = Omit<SetProps<P>, 'private' | 'unauthenticated'> & {
49+
/** The page name where a user will be redirected when not authenticated */
50+
unauthenticated: keyof AvailableRoutes
51+
}
52+
6653
/** @deprecated Please use `<PrivateSet>` instead */
67-
export function Private<WrapperProps>(
68-
props: CommonSetProps<WrapperProps> & {
69-
/** The page name where a user will be redirected when not authenticated */
70-
unauthenticated: keyof AvailableRoutes
71-
},
72-
) {
54+
export function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
7355
// @MARK Virtual Component, this is actually never rendered
7456
// See analyzeRoutes in utils.tsx, inside the isSetNode block
7557
return <>{props.children}</>
@@ -78,20 +60,15 @@ export function Private<WrapperProps>(
7860
/**
7961
* A set containing private `<Route />`s that require authentication to access
8062
*/
81-
export function PrivateSet<WrapperProps>(
82-
props: CommonSetProps<WrapperProps> & {
83-
/** The page name where a user will be redirected when not authenticated */
84-
unauthenticated: keyof AvailableRoutes
85-
},
86-
) {
63+
export function PrivateSet<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
8764
// @MARK Virtual Component, this is actually never rendered
8865
// See analyzeRoutes in utils.tsx, inside the isSetNode block
8966
return <>{props.children}</>
9067
}
9168

9269
export const isSetNode = (
9370
node: ReactNode,
94-
): node is ReactElement<CommonSetProps<any> & RegularSetProps> => {
71+
): node is ReactElement<SetProps<any>> => {
9572
return (
9673
React.isValidElement(node) &&
9774
(node.type === Set || node.type === PrivateSet || node.type === Private) &&
@@ -102,15 +79,13 @@ export const isSetNode = (
10279

10380
export const isPrivateSetNode = (
10481
node: ReactNode,
105-
): node is ReactElement<
106-
CommonSetProps<unknown> & { unauthenticated: keyof AvailableRoutes }
107-
> => {
82+
): node is ReactElement<PrivateSetProps<unknown>> => {
10883
return React.isValidElement(node) && node.type === PrivateSet
10984
}
11085

11186
// Only identifies <Private> nodes, not <Set private> nodes
11287
export const isPrivateNode = (
11388
node: ReactNode,
114-
): node is ReactElement<CommonSetProps<any> & RegularSetProps> => {
89+
): node is ReactElement<SetProps<any>> => {
11590
return React.isValidElement(node) && node.type === Private
11691
}

0 commit comments

Comments
 (0)