Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: static shell #37

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions apps/dashboard/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { Toaster } from 'sonner'
import { Suspense } from 'react'
import { Splash } from '../components/Splash'
import './globals.css'

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
Expand All @@ -20,15 +13,11 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
{/* OgSplash uses `useSearchParams()` so we need to wrap it in a Suspense to allow to statically render the page
https://nextjs.org/docs/app/building-your-application/rendering/server-components#dynamic-functions */}
<Suspense>
<Splash>
{children}
</Splash>
</Suspense>
<Splash>
{children}
</Splash>
<Toaster closeButton richColors />
</body>
</html>
</html >
)
}
2 changes: 2 additions & 0 deletions apps/dashboard/src/app/my-images/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const metadata = {
description: 'My Open Graph images.',
}

export const dynamic = 'force-static'

export default function MyImages() {
return <MyImagesSplash />
}
2 changes: 2 additions & 0 deletions apps/dashboard/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const metadata = {
description: 'Figma-like OG (Open Graph) Image builder.',
}

export const dynamic = 'force-static'

export default function Home() {
return <HomeSplash />
}
2 changes: 2 additions & 0 deletions apps/dashboard/src/app/templates/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const metadata = {
description: 'Pre-made Open Graph image templates.',
}

export const dynamic = 'force-static'

export default function Templates() {
return <TemplatesSplash />
}
22 changes: 20 additions & 2 deletions apps/dashboard/src/components/Splash/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
'use client'
import type { ReactNode } from "react";
import { Suspense, type ReactNode, useEffect } from "react";
import { useSearchParams } from "next/navigation";
import { OgEditor } from "../OgEditor";
import { CustomLink } from "../CustomLink";
import { GitHubIcon } from "../icons/GitHubIcon";
import { useImagesStore } from "../../stores/imagesStore";
import { useZoomStore } from "../../stores/zoomStore";

interface OgSplashProps {
children: ReactNode
}

export function Splash({ children }: OgSplashProps) {
function SplashInner({ children }: OgSplashProps) {
const searchParams = useSearchParams()
const image = searchParams.get('i')

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we don't want to wait for this
useImagesStore.persist.rehydrate()
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we don't want to wait for this
useZoomStore.persist.rehydrate()
}, [])

return (
<>
<OgEditor height={630} imageId={image ?? 'splash'} width={1200} />
Expand Down Expand Up @@ -43,3 +52,12 @@ export function Splash({ children }: OgSplashProps) {
)
}

export function Splash({ children }: OgSplashProps) {
return (
// SplashInner uses `useSearchParams()` so we need to wrap it in a Suspense to allow to statically render the page
// https://nextjs.org/docs/app/building-your-application/rendering/server-components#dynamic-functions
<Suspense>
<SplashInner>{children}</SplashInner>
</Suspense>
)
}
3 changes: 2 additions & 1 deletion apps/dashboard/src/stores/imagesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ export const useImagesStore = create(persist<ImagesState>(set => ({
}
}), {
name: 'images',
storage: createJSONStorage(() => localStorage)
storage: createJSONStorage(() => localStorage),
skipHydration: true,
}))
1 change: 1 addition & 0 deletions apps/dashboard/src/stores/zoomStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export const useZoomStore = create(persist<ZoomState>((set, get) => ({
}), {
name: 'zoom',
storage: createJSONStorage(() => localStorage),
skipHydration: true,
}))