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

Remove the Suspense boundary for individual items #15

Merged
merged 4 commits into from
Dec 8, 2021
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
37 changes: 33 additions & 4 deletions components/meta.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Head from "next/head";
import Head from 'next/head'
// import Router from 'next/router'

export default function Meta() {
return (
<div>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charSet="utf-8" />
<meta name='viewport' content='width=device-width, initial-scale=1' />
<meta charSet='utf-8' />
{/* <link rel="shortcut icon" href="/static/favicon.ico" /> */}
</Head>
<style
Expand Down Expand Up @@ -85,9 +85,38 @@ export default function Meta() {
.meta a:hover {
text-decoration: underline;
}
.item-skeleton {
margin: 5px 0;
overflow: hidden;
}
.item-skeleton:before, .item-skeleton:after {
content: '';
display: block;
width: 350px;
max-width: 100%;
height: 16px;
background: #eee;
margin: 6px 0 2px;
background-image: linear-gradient(270deg, #ccc, #eee, #eee, #ccc);
background-size: 400% 100%;
animation: highlight-rotating 8s ease infinite;
}
.item-skeleton:after {
width: 250px;
height: 10px;
margin: 5px 0;
}
@keyframes highlight-rotating {
from {
background-position: 200% 0;
}
to {
background-position: -200% 0;
}
}
`,
}}
/>
</div>
);
)
}
16 changes: 16 additions & 0 deletions components/skeletons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function Skeletons() {
// Generating 30 skeletons to match the size of the list.
return (
<div>
{Array(30)
.fill(0)
.map((_, index) => (
<Skeleton key={index} />
))}
</div>
)
}

function Skeleton() {
return <div className='item-skeleton' />
}
10 changes: 3 additions & 7 deletions pages/rsc.server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Suspense } from 'react'

// Shared Components
import Spinner from '../components/spinner'
import Skeletons from '../components/skeletons'

// Server Components
import SystemInfo from '../components/server-info.server'
Expand All @@ -26,11 +26,7 @@ function NewsWithData() {
return (
<>
{storyIds.slice(0, 30).map((id) => {
return (
<Suspense fallback={<Spinner />} key={id}>
<StoryWithData id={id} />
</Suspense>
)
return <StoryWithData id={id} key={id} />
})}
</>
)
Expand All @@ -39,7 +35,7 @@ function NewsWithData() {
export default function News() {
return (
<Page>
<Suspense fallback={<Spinner />}>
<Suspense fallback={<Skeletons />}>
<NewsWithData />
</Suspense>
<Footer />
Expand Down