-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(vercel-app-playground): port ssg demo (#12)
- Loading branch information
Showing
14 changed files
with
149 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { RenderingInfo } from '#/ui/rendering-info'; | ||
|
||
export default async function Page({ params }: { params: { id: string } }) { | ||
const res = await fetch( | ||
`https://jsonplaceholder.typicode.com/posts/${params.id}`, | ||
); | ||
const data = (await res.json()) as { title: string; body: string }; | ||
|
||
return ( | ||
<div className="grid grid-cols-6 gap-x-6 gap-y-3"> | ||
<div className="col-span-full space-y-3 lg:col-span-4"> | ||
<h1 className="truncate text-2xl font-medium capitalize text-gray-200"> | ||
{data.title} | ||
</h1> | ||
<p className="line-clamp-3 font-medium text-gray-500">{data.body}</p> | ||
</div> | ||
<div className="-order-1 col-span-full lg:order-none lg:col-span-2"> | ||
<RenderingInfo | ||
type={ | ||
globalThis.process?.env?.['REACT_SERVER_PRERENDER'] ? 'ssg' : 'ssr' | ||
} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Tab } from '#/ui/tab'; | ||
import React from 'react'; | ||
import { Boundary } from '#/ui/boundary'; | ||
|
||
const title = 'Static Data'; | ||
|
||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<div className="space-y-9"> | ||
<title>{title}</title> | ||
<div className="flex flex-wrap items-center gap-2"> | ||
<Tab path="/ssg" item={{ text: 'Home' }} /> | ||
<Tab path="/ssg" item={{ text: 'Post 1 (prerender)', slug: '1' }} /> | ||
<Tab path="/ssg" item={{ text: 'Post 2 (prerender)', slug: '2' }} /> | ||
<Tab path="/ssg" item={{ text: 'Post 3 (dynamic)', slug: '3' }} /> | ||
</div> | ||
<div> | ||
<Boundary>{children}</Boundary> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ExternalLink } from '#/ui/external-link'; | ||
|
||
export default function Page() { | ||
return ( | ||
<div className="prose prose-sm prose-invert max-w-none"> | ||
<h1 className="text-xl font-bold">Static Data</h1> | ||
|
||
<ul> | ||
<li className="line-through"> | ||
By default, data fetching in Next.js is cached static. | ||
</li> | ||
<li>This example statically caches data fetches for Post 1 and 2.</li> | ||
<li className="line-through"> | ||
A random third post is fetched on-demand the first time it is | ||
requested. | ||
</li> | ||
<li> | ||
Try navigating to each post and noting the timestamp of when the page | ||
was rendered. | ||
</li> | ||
</ul> | ||
|
||
<div className="flex gap-2"> | ||
<ExternalLink href="https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#static-data-fetching"> | ||
Docs | ||
</ExternalLink> | ||
<ExternalLink href="https://github.com/vercel/app-playground/tree/main/app/ssg"> | ||
Code | ||
</ExternalLink> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters