-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add RSC streaming pre-render with promise fallback example (#…
…2905) examples: add RSC streaming prerender with promise fallback example
- Loading branch information
Showing
13 changed files
with
145 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
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,9 @@ | ||
export default function RootLayout({ | ||
children | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body style={{ textAlign: 'center' }}>{children}</body> | ||
</html> | ||
) | ||
} |
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,4 @@ | ||
'use client' | ||
export default function ErrorPage() { | ||
return <div>Error happen</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,3 @@ | ||
export default function Loading() { | ||
return <div>Loading...</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,23 @@ | ||
import Repo from './repo' | ||
import fetcher from '../../../../libs/fetch' | ||
import Link from 'next/link' | ||
import { Suspense } from 'react' | ||
const Page = ({ params }) => { | ||
const { user, repo } = params | ||
const id = `${user}/${repo}` | ||
const serverData = fetcher('http://localhost:3000/api/data?id=' + id) | ||
return ( | ||
<div> | ||
<div>Repo: {id}</div> | ||
<Suspense fallback={<div>Loading stats</div>}> | ||
<Repo serverData={serverData} id={id} /> | ||
</Suspense> | ||
<br /> | ||
<br /> | ||
<Link href="/rsc">Back</Link> | ||
</div> | ||
) | ||
} | ||
|
||
|
||
export default Page |
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,21 @@ | ||
'use client' | ||
import fetcher from '../../../../libs/fetch' | ||
import useSWR from 'swr' | ||
|
||
const Repo = ({ id, serverData }) => { | ||
const { data } = useSWR('/api/data?id=' + id, fetcher, { suspense: true, fallbackData: serverData }) | ||
return ( | ||
<> | ||
{data ? ( | ||
<div> | ||
<p>forks: {data.forks_count}</p> | ||
<p>stars: {data.stargazers_count}</p> | ||
<p>watchers: {data.watchers}</p> | ||
</div> | ||
) : null} | ||
|
||
</> | ||
) | ||
} | ||
|
||
export default Repo |
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,3 @@ | ||
export default function Loading() { | ||
return <div>Loading...</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,8 @@ | ||
import fetcher from '../../libs/fetch' | ||
import Repos from './repos' | ||
const Page = () => { | ||
const serverData = fetcher('http://localhost:3000/api/data') | ||
return <Repos serverData={serverData} /> | ||
} | ||
|
||
export default Page |
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,24 @@ | ||
'use client' | ||
import useSWR from 'swr' | ||
import fetcher from '../../libs/fetch' | ||
import Link from 'next/link' | ||
|
||
const Repos = ({ serverData }) => { | ||
const { data } = useSWR('/api/data', fetcher, { | ||
suspense: true, | ||
fallbackData: serverData | ||
}) | ||
return ( | ||
<> | ||
{data.map(project => ( | ||
<p key={project}> | ||
<Link href={`/rsc/${project}`}> | ||
{project} | ||
</Link> | ||
</p> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
export default Repos |
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,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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