Skip to content

Commit 177b0a1

Browse files
committed
Add PersistentLayout to fix duplicated flash messages
1 parent 81ef281 commit 177b0a1

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

app/frontend/entrypoints/inertia.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type ReactNode, createElement } from "react"
33
import { createRoot } from "react-dom/client"
44

55
import { initializeTheme } from "@/hooks/use-appearance"
6+
import PersistentLayout from "@/layouts/persistent-layout"
67

78
// Temporary type definition, until @inertiajs/react provides one
89
interface ResolvedComponent {
@@ -30,7 +31,8 @@ void createInertiaApp({
3031
// and use the following line.
3132
// see https://inertia-rails.dev/guide/pages#default-layouts
3233
//
33-
// page.default.layout ??= (page) => createElement(Layout, null, page)
34+
page.default.layout ??= (page) =>
35+
createElement(PersistentLayout, null, page)
3436

3537
return page
3638
},

app/frontend/layouts/app-layout.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { ReactNode } from "react"
22

3-
import { Toaster } from "@/components/ui/sonner"
4-
import { useFlash } from "@/hooks/use-flash"
53
import AppLayoutTemplate from "@/layouts/app/app-sidebar-layout"
64
import type { BreadcrumbItem } from "@/types"
75

@@ -15,11 +13,9 @@ export default function AppLayout({
1513
breadcrumbs,
1614
...props
1715
}: AppLayoutProps) {
18-
useFlash()
1916
return (
2017
<AppLayoutTemplate breadcrumbs={breadcrumbs} {...props}>
2118
{children}
22-
<Toaster richColors />
2319
</AppLayoutTemplate>
2420
)
2521
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Toaster } from "@/components/ui/sonner"
2-
import { useFlash } from "@/hooks/use-flash"
1+
import type { ReactNode } from "react"
2+
33
import AuthLayoutTemplate from "@/layouts/auth/auth-simple-layout"
44

55
export default function AuthLayout({
@@ -8,15 +8,13 @@ export default function AuthLayout({
88
description,
99
...props
1010
}: {
11-
children: React.ReactNode
11+
children: ReactNode
1212
title: string
1313
description: string
1414
}) {
15-
useFlash()
1615
return (
1716
<AuthLayoutTemplate title={title} description={description} {...props}>
1817
{children}
19-
<Toaster richColors />
2018
</AuthLayoutTemplate>
2119
)
2220
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ReactNode } from "react"
2+
3+
import { Toaster } from "@/components/ui/sonner"
4+
import { useFlash } from "@/hooks/use-flash"
5+
6+
interface PersistentLayoutProps {
7+
children: ReactNode
8+
}
9+
10+
export default function PersistentLayout({ children }: PersistentLayoutProps) {
11+
useFlash()
12+
return (
13+
<>
14+
{children}
15+
<Toaster richColors />
16+
</>
17+
)
18+
}

app/frontend/ssr/ssr.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import createServer from "@inertiajs/react/server"
33
import { type ReactNode, createElement } from "react"
44
import ReactDOMServer from "react-dom/server"
55

6+
import PersistentLayout from "@/layouts/persistent-layout"
7+
68
// Temporary type definition, until @inertiajs/react provides one
79
interface ResolvedComponent {
810
default: ReactNode & { layout?: (page: ReactNode) => ReactNode }
@@ -28,7 +30,8 @@ createServer((page) =>
2830
// and use the following line.
2931
// see https://inertia-rails.dev/guide/pages#default-layouts
3032
//
31-
// page.default.layout ??= (page) => createElement(Layout, null, page)
33+
page.default.layout ??= (page) =>
34+
createElement(PersistentLayout, null, page)
3235

3336
return page
3437
},

0 commit comments

Comments
 (0)