Skip to content

Commit a39e340

Browse files
authored
Revert "[Router][TS] Auto-complete route names for unauthenticated prop (#11756)" (#11905)
1 parent 4ee5661 commit a39e340

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

.changesets/11756.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/router/src/Set.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import type { ReactElement, ReactNode } from 'react'
22
import React from 'react'
33

4-
import type { routes } from '@redwoodjs/router'
4+
export type WrapperType<WTProps> = (
5+
props: Omit<WTProps, 'wrap' | 'children'> & {
6+
children: ReactNode
7+
},
8+
) => ReactElement | null
59

6-
type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
10+
type SetProps<P> = P & {
711
/**
8-
* A react component that the children of the Set will be wrapped
9-
* in (typically a Layout component)
12+
* P is the interface for the props that are forwarded to the wrapper
13+
* components. TypeScript will most likely infer this for you, but if you
14+
* need to you can specify it yourself in your JSX like so:
15+
* <Set<{theme: string}> wrap={ThemableLayout} theme="dark">
1016
*/
11-
wrap?: P | P[]
17+
wrap?: WrapperType<P> | WrapperType<P>[]
1218
/**
1319
*`Routes` nested in a `<Set>` with `private` specified require
1420
* authentication. When a user is not authenticated and attempts to visit
@@ -22,7 +28,7 @@ type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
2228
*
2329
* @deprecated Please use `<PrivateSet>` instead and specify this prop there
2430
*/
25-
unauthenticated?: keyof typeof routes
31+
unauthenticated?: string
2632
/**
2733
* Route is permitted when authenticated and user has any of the provided
2834
* roles such as "admin" or ["admin", "editor"]
@@ -37,18 +43,22 @@ type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
3743
}
3844

3945
/**
40-
* A set containing public `<Route />`s
46+
* TypeScript will often infer the type of the props you can forward to the
47+
* wrappers for you, but if you need to you can specify it yourself in your
48+
* JSX like so:
49+
* <Set<{theme: string}> wrap={ThemeableLayout} theme="dark">
4150
*/
4251
export function Set<WrapperProps>(props: SetProps<WrapperProps>) {
4352
// @MARK: Virtual Component, this is actually never rendered
4453
// See analyzeRoutes in utils.tsx, inside the isSetNode block
4554
return <>{props.children}</>
4655
}
4756

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 typeof routes
51-
}
57+
type PrivateSetProps<P> = P &
58+
Omit<SetProps<P>, 'private' | 'unauthenticated'> & {
59+
/** The page name where a user will be redirected when not authenticated */
60+
unauthenticated: string
61+
}
5262

5363
/** @deprecated Please use `<PrivateSet>` instead */
5464
export function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
@@ -57,9 +67,6 @@ export function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
5767
return <>{props.children}</>
5868
}
5969

60-
/**
61-
* A set containing private `<Route />`s that require authentication to access
62-
*/
6370
export function PrivateSet<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
6471
// @MARK Virtual Component, this is actually never rendered
6572
// See analyzeRoutes in utils.tsx, inside the isSetNode block

0 commit comments

Comments
 (0)