From a443f0a2f1c6f1e19b487ec0597d710ca79428d2 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 17 Jan 2025 08:23:10 +0100 Subject: [PATCH] Revert "[Router][TS] Auto-complete route names for unauthenticated prop (#11756)" This reverts commit 6cfc992c35a06307bc703c402296b86ae58873f4. --- .changesets/11756.md | 8 -------- packages/router/src/Set.tsx | 35 +++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 22 deletions(-) delete mode 100644 .changesets/11756.md diff --git a/.changesets/11756.md b/.changesets/11756.md deleted file mode 100644 index 08431fd9bb11..000000000000 --- a/.changesets/11756.md +++ /dev/null @@ -1,8 +0,0 @@ -- [Router][TS] Auto-complete route names for unauthenticated prop (#11756) by @Philzen - -- auto-suggests available route names -- will highlight invalid values - -This depends on type generation, so either you'll have to run `yarn rw g types` manually, or you'll have to have the dev server running (which regenerates types when required). - -This PR is a little breaking, b/c the ``s generic typing has changed and also the `WrapperType

` type has been removed. diff --git a/packages/router/src/Set.tsx b/packages/router/src/Set.tsx index 141024f60b97..2283a90ad7e0 100644 --- a/packages/router/src/Set.tsx +++ b/packages/router/src/Set.tsx @@ -1,14 +1,20 @@ import type { ReactElement, ReactNode } from 'react' import React from 'react' -import type { routes } from '@redwoodjs/router' +export type WrapperType = ( + props: Omit & { + children: ReactNode + }, +) => ReactElement | null -type SetProps

= (P extends React.FC ? React.ComponentProps

: unknown) & { +type SetProps

= P & { /** - * A react component that the children of the Set will be wrapped - * in (typically a Layout component) + * P is the interface for the props that are forwarded to the wrapper + * components. TypeScript will most likely infer this for you, but if you + * need to you can specify it yourself in your JSX like so: + * wrap={ThemableLayout} theme="dark"> */ - wrap?: P | P[] + wrap?: WrapperType

| WrapperType

[] /** *`Routes` nested in a `` with `private` specified require * authentication. When a user is not authenticated and attempts to visit @@ -22,7 +28,7 @@ type SetProps

= (P extends React.FC ? React.ComponentProps

: unknown) & { * * @deprecated Please use `` instead and specify this prop there */ - unauthenticated?: keyof typeof routes + unauthenticated?: string /** * Route is permitted when authenticated and user has any of the provided * roles such as "admin" or ["admin", "editor"] @@ -37,7 +43,10 @@ type SetProps

= (P extends React.FC ? React.ComponentProps

: unknown) & { } /** - * A set containing public ``s + * TypeScript will often infer the type of the props you can forward to the + * wrappers for you, but if you need to you can specify it yourself in your + * JSX like so: + * wrap={ThemeableLayout} theme="dark"> */ export function Set(props: SetProps) { // @MARK: Virtual Component, this is actually never rendered @@ -45,10 +54,11 @@ export function Set(props: SetProps) { return <>{props.children} } -type PrivateSetProps

= Omit, 'private' | 'unauthenticated'> & { - /** The page name where a user will be redirected when not authenticated */ - unauthenticated: keyof typeof routes -} +type PrivateSetProps

= P & + Omit, 'private' | 'unauthenticated'> & { + /** The page name where a user will be redirected when not authenticated */ + unauthenticated: string + } /** @deprecated Please use `` instead */ export function Private(props: PrivateSetProps) { @@ -57,9 +67,6 @@ export function Private(props: PrivateSetProps) { return <>{props.children} } -/** - * A set containing private ``s that require authentication to access - */ export function PrivateSet(props: PrivateSetProps) { // @MARK Virtual Component, this is actually never rendered // See analyzeRoutes in utils.tsx, inside the isSetNode block