From 9b47058c945f39324903b9215f457bebec02f1c5 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 20 Nov 2026 12:48:51 +0530 Subject: [PATCH 1/4] fix(starter-kits): typed nav links, persistent Vue layouts, and Vue browser test plugins - NavLink takes the typed props of a route Link in the React and Vue kits, so params are checked against the route. - The app and settings layouts write their links inline, in place of NavItem arrays. - Vue pages attach their layout with defineOptions, so the layout and its flash toasts stay mounted across visits. - The Vue kit registers the browser, session and auth browser client plugins, as the React kit does. - The api providers cast the paginator metadata: the guard of @adonisjs/http-transformers does not list pageName, which Lucid 22.5 added. Claude-Session: https://claude.ai/code/session_01TEEvhcHLnHEEa4Qd5eGJs4 --- .../apps/backend/providers/api_provider.ts | 7 +- api/providers/api_provider.ts | 7 +- inertia-react/inertia/components/nav_link.tsx | 49 ++-- inertia-react/inertia/layouts/app.tsx | 22 +- inertia-react/inertia/layouts/settings.tsx | 22 +- inertia-react/providers/api_provider.ts | 7 +- inertia-vue/inertia/components/nav_link.vue | 52 ++-- inertia-vue/inertia/layouts/app.vue | 18 +- inertia-vue/inertia/layouts/settings.vue | 31 +-- inertia-vue/inertia/pages/auth/login.vue | 92 +++---- inertia-vue/inertia/pages/auth/signup.vue | 148 +++++----- inertia-vue/inertia/pages/dashboard.vue | 32 +-- .../inertia/pages/errors/not_found.vue | 36 +-- .../inertia/pages/errors/server_error.vue | 38 +-- inertia-vue/inertia/pages/home.vue | 259 +++++++++--------- inertia-vue/providers/api_provider.ts | 7 +- inertia-vue/tests/bootstrap.ts | 12 +- 17 files changed, 431 insertions(+), 408 deletions(-) diff --git a/api-monorepo/apps/backend/providers/api_provider.ts b/api-monorepo/apps/backend/providers/api_provider.ts index 8e4e00c..873eb95 100644 --- a/api-monorepo/apps/backend/providers/api_provider.ts +++ b/api-monorepo/apps/backend/providers/api_provider.ts @@ -29,7 +29,12 @@ class ApiSerializer extends BaseSerializer<{ 'Invalid pagination metadata. Expected metadata to contain Lucid pagination keys' ) } - return metaData + + /** + * The type guard of `@adonisjs/http-transformers` does not list + * `pageName`, which Lucid 22.5 added, so the value is cast. + */ + return metaData as SimplePaginatorMetaKeys } } diff --git a/api/providers/api_provider.ts b/api/providers/api_provider.ts index 8e4e00c..873eb95 100644 --- a/api/providers/api_provider.ts +++ b/api/providers/api_provider.ts @@ -29,7 +29,12 @@ class ApiSerializer extends BaseSerializer<{ 'Invalid pagination metadata. Expected metadata to contain Lucid pagination keys' ) } - return metaData + + /** + * The type guard of `@adonisjs/http-transformers` does not list + * `pageName`, which Lucid 22.5 added, so the value is cast. + */ + return metaData as SimplePaginatorMetaKeys } } diff --git a/inertia-react/inertia/components/nav_link.tsx b/inertia-react/inertia/components/nav_link.tsx index dafd765..e38758d 100644 --- a/inertia-react/inertia/components/nav_link.tsx +++ b/inertia-react/inertia/components/nav_link.tsx @@ -1,16 +1,18 @@ import { urlFor } from '~/client' import { usePage } from '@inertiajs/react' -import { type LucideIcon } from 'lucide-react' -import { type ReactNode } from 'react' import { Link } from '@adonisjs/inertia/react' +import { type ComponentProps, type ReactNode } from 'react' -export type NavRoute = Parameters[0] +type LinkRoute = NonNullable['route']> -export type NavItem = { - label: string - route: NavRoute - icon?: LucideIcon -} +/** + * The props of a route `Link`, so `routeParams` is checked against the + * route, plus `exact`. + */ +type NavLinkProps = Extract< + Parameters>[0], + { route: Route } +> & { exact?: boolean; className?: string; children: ReactNode } /** * A link that marks itself with `aria-current="page"` when the current URL @@ -18,25 +20,28 @@ export type NavItem = { * "Settings" link stays active on "/settings/security". Pass `exact` to * only match the route itself. */ -export default function NavLink({ - route, +export default function NavLink({ exact = false, - className, - children, -}: { - route: NavRoute - exact?: boolean - className?: string - children: ReactNode -}) { + ...props +}: NavLinkProps) { const { url } = usePage() - const href = urlFor(route) + + /** + * Inside this generic function TypeScript can't tie `routeParams` to + * `route`, so the two calls below are cast. Each caller's props are + * still checked against its route. + */ + const href = (urlFor as (route: string, params?: unknown) => string)( + props.route, + props.routeParams + ) const path = url.split('?')[0] const isActive = exact ? path === href : path === href || path.startsWith(`${href}/`) return ( - - {children} - + )} + aria-current={isActive ? 'page' : undefined} + /> ) } diff --git a/inertia-react/inertia/layouts/app.tsx b/inertia-react/inertia/layouts/app.tsx index cd883e9..30eb860 100644 --- a/inertia-react/inertia/layouts/app.tsx +++ b/inertia-react/inertia/layouts/app.tsx @@ -4,13 +4,7 @@ import { House, LogOut } from 'lucide-react' import { Form } from '@adonisjs/inertia/react' import FlashToasts from '~/components/flash_toasts' import ThemeToggle from '~/components/theme_toggle' -import NavLink, { type NavItem } from '~/components/nav_link' - -/** - * Top-level app navigation. Add an entry here for every new area of your - * app, and it shows up in the navigation bar with its active state handled. - */ -const nav: NavItem[] = [{ label: 'Dashboard', route: 'dashboard', icon: House }] +import NavLink from '~/components/nav_link' export default function AppLayout({ children }: { children: ReactNode }) { return ( @@ -31,12 +25,14 @@ export default function AppLayout({ children }: { children: ReactNode }) { diff --git a/inertia-react/inertia/layouts/settings.tsx b/inertia-react/inertia/layouts/settings.tsx index a64e246..1648dd0 100644 --- a/inertia-react/inertia/layouts/settings.tsx +++ b/inertia-react/inertia/layouts/settings.tsx @@ -1,14 +1,5 @@ import Page from '~/components/page' import { type ReactNode } from 'react' -import NavLink, { type NavItem } from '~/components/nav_link' - -/** - * The pages of the settings area, listed in the sidebar. Register a route - * for each page and add it here, for example: - * - * `{ label: 'Profile', route: 'settings.profile', icon: User }` - */ -const items: NavItem[] = [] /** * Renders the settings heading, a sidebar of links and a card holding the @@ -21,12 +12,15 @@ export default function SettingsLayout({ children }: { children: ReactNode }) {
{children}
diff --git a/inertia-react/providers/api_provider.ts b/inertia-react/providers/api_provider.ts index 8e4e00c..873eb95 100644 --- a/inertia-react/providers/api_provider.ts +++ b/inertia-react/providers/api_provider.ts @@ -29,7 +29,12 @@ class ApiSerializer extends BaseSerializer<{ 'Invalid pagination metadata. Expected metadata to contain Lucid pagination keys' ) } - return metaData + + /** + * The type guard of `@adonisjs/http-transformers` does not list + * `pageName`, which Lucid 22.5 added, so the value is cast. + */ + return metaData as SimplePaginatorMetaKeys } } diff --git a/inertia-vue/inertia/components/nav_link.vue b/inertia-vue/inertia/components/nav_link.vue index 037c6f4..4cf9e53 100644 --- a/inertia-vue/inertia/components/nav_link.vue +++ b/inertia-vue/inertia/components/nav_link.vue @@ -1,31 +1,43 @@ - - - diff --git a/inertia-vue/inertia/layouts/app.vue b/inertia-vue/inertia/layouts/app.vue index 569906d..8193511 100644 --- a/inertia-vue/inertia/layouts/app.vue +++ b/inertia-vue/inertia/layouts/app.vue @@ -4,13 +4,7 @@ import { Form } from '@adonisjs/inertia/vue' import Logo from '~/components/logo.vue' import FlashToasts from '~/components/flash_toasts.vue' import ThemeToggle from '~/components/theme_toggle.vue' -import NavLink, { type NavItem } from '~/components/nav_link.vue' - -/** - * Top-level app navigation. Add an entry here for every new area of your - * app, and it shows up in the navigation bar with its active state handled. - */ -const nav: NavItem[] = [{ label: 'Dashboard', route: 'dashboard', icon: House }] +import NavLink from '~/components/nav_link.vue'