Skip to content

Commit 869a7f1

Browse files
committed
fix: prerender homepage content
1 parent c1baf23 commit 869a7f1

2 files changed

Lines changed: 81 additions & 47 deletions

File tree

src/components/Layout/HomeContent.js

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Copyright (c) Facebook, Inc. and its affiliates.
1010
*/
1111

12+
'use client';
13+
1214
import {
1315
createContext,
1416
memo,
@@ -89,24 +91,30 @@ function FullBleed({children}) {
8991
}
9092

9193
function CurrentTime() {
92-
const [date, setDate] = useState(new Date());
93-
const currentTime = date.toLocaleTimeString([], {
94-
hour: 'numeric',
95-
minute: 'numeric',
96-
});
94+
const [date, setDate] = useState(null);
95+
9796
useEffect(() => {
9897
const msPerMinute = 60 * 1000;
99-
let nextMinute = Math.floor(+date / msPerMinute + 1) * msPerMinute;
10098

101-
const timeout = setTimeout(() => {
102-
if (Date.now() > nextMinute) {
103-
setDate(new Date());
104-
}
105-
}, nextMinute - Date.now());
106-
return () => clearTimeout(timeout);
107-
}, [date]);
99+
function updateDate() {
100+
setDate(new Date());
101+
}
102+
103+
updateDate();
104+
const interval = setInterval(updateDate, msPerMinute);
105+
return () => clearInterval(interval);
106+
}, []);
108107

109-
return <span suppressHydrationWarning>{currentTime}</span>;
108+
const currentTime = date?.toLocaleTimeString([], {
109+
hour: 'numeric',
110+
minute: 'numeric',
111+
});
112+
113+
return (
114+
<span className={date === null ? 'invisible' : undefined}>
115+
{currentTime ?? '00:00'}
116+
</span>
117+
);
110118
}
111119

112120
const blogSidebar = sidebarBlog.routes[1];
@@ -2367,23 +2375,38 @@ function fetchConf(slug) {
23672375
if (confCache.has(slug)) {
23682376
return confCache.get(slug);
23692377
}
2378+
const isInitialConference = slug === 'react-conf-2021';
2379+
let initialValue;
23702380
const promise = new Promise((resolve) => {
2371-
setTimeout(() => {
2381+
const complete = (value) => {
2382+
initialValue = value;
2383+
resolve(value);
2384+
};
2385+
const load = () => {
23722386
if (slug === 'react-conf-2021') {
2373-
resolve({
2387+
complete({
23742388
id: 0,
23752389
cover: reactConf2021Cover,
23762390
name: 'React Conf 2021',
23772391
});
23782392
} else if (slug === 'react-conf-2019') {
2379-
resolve({
2393+
complete({
23802394
id: 1,
23812395
cover: reactConf2019Cover,
23822396
name: 'React Conf 2019',
23832397
});
23842398
}
2385-
}, loadConfDelay);
2399+
};
2400+
if (isInitialConference) {
2401+
load();
2402+
} else {
2403+
setTimeout(load, loadConfDelay);
2404+
}
23862405
});
2406+
if (isInitialConference) {
2407+
promise.status = 'fulfilled';
2408+
promise.value = initialValue;
2409+
}
23872410
confCache.set(slug, promise);
23882411
return promise;
23892412
}
@@ -2392,10 +2415,16 @@ function fetchTalks(confId) {
23922415
if (talksCache.has(confId)) {
23932416
return talksCache.get(confId);
23942417
}
2418+
const isInitialConference = confId === 0;
2419+
let initialValue;
23952420
const promise = new Promise((resolve) => {
2396-
setTimeout(() => {
2421+
const complete = (value) => {
2422+
initialValue = value;
2423+
resolve(value);
2424+
};
2425+
const load = () => {
23972426
if (confId === 0) {
2398-
resolve([
2427+
complete([
23992428
{
24002429
id: 'conf-2021-0',
24012430
title: 'React 18 Keynote',
@@ -2577,7 +2606,7 @@ function fetchTalks(confId) {
25772606
},
25782607
]);
25792608
} else if (confId === 1) {
2580-
resolve([
2609+
complete([
25812610
{
25822611
id: 'conf-2019-0',
25832612
title: 'Keynote (Part 1)',
@@ -2774,8 +2803,17 @@ function fetchTalks(confId) {
27742803
},
27752804
]);
27762805
}
2777-
}, loadTalksDelay);
2806+
};
2807+
if (isInitialConference) {
2808+
load();
2809+
} else {
2810+
setTimeout(load, loadTalksDelay);
2811+
}
27782812
});
2813+
if (isInitialConference) {
2814+
promise.status = 'fulfilled';
2815+
promise.value = initialValue;
2816+
}
27792817
talksCache.set(confId, promise);
27802818
return promise;
27812819
}

src/components/Layout/Page.tsx

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
'use client';
1313

14-
import {Suspense} from 'react';
1514
import * as React from 'react';
1615
import dynamic from 'next/dynamic';
1716
import {SidebarNav} from './SidebarNav';
@@ -154,34 +153,31 @@ export function Page({
154153
</div>
155154
</div>
156155
)}
157-
{/* No fallback UI so need to be careful not to suspend directly inside. */}
158-
<Suspense fallback={null}>
159-
<main className="min-w-0 isolate">
160-
<article
161-
className="font-normal break-words text-primary dark:text-primary-dark"
162-
key={pathname}>
163-
{content}
164-
</article>
156+
<main className="min-w-0 isolate">
157+
<article
158+
className="font-normal break-words text-primary dark:text-primary-dark"
159+
key={pathname}>
160+
{content}
161+
</article>
162+
<div
163+
className={cn(
164+
'self-stretch w-full',
165+
isHomePage && 'bg-wash dark:bg-gray-95 mt-[-1px]'
166+
)}>
167+
{!isHomePage && (
168+
<div className="w-full px-5 pt-10 mx-auto sm:px-12 md:px-12 md:pt-12 lg:pt-10">
169+
<hr className="mx-auto max-w-7xl border-border dark:border-border-dark" />
170+
</div>
171+
)}
165172
<div
166173
className={cn(
167-
'self-stretch w-full',
168-
isHomePage && 'bg-wash dark:bg-gray-95 mt-[-1px]'
174+
'py-12 px-5 sm:px-12 md:px-12 sm:py-12 md:py-16 lg:py-14',
175+
isHomePage && 'lg:pt-0'
169176
)}>
170-
{!isHomePage && (
171-
<div className="w-full px-5 pt-10 mx-auto sm:px-12 md:px-12 md:pt-12 lg:pt-10">
172-
<hr className="mx-auto max-w-7xl border-border dark:border-border-dark" />
173-
</div>
174-
)}
175-
<div
176-
className={cn(
177-
'py-12 px-5 sm:px-12 md:px-12 sm:py-12 md:py-16 lg:py-14',
178-
isHomePage && 'lg:pt-0'
179-
)}>
180-
<Footer />
181-
</div>
177+
<Footer />
182178
</div>
183-
</main>
184-
</Suspense>
179+
</div>
180+
</main>
185181
<div className="hidden -mt-16 lg:max-w-custom-xs 2xl:block">
186182
{showToc && toc.length > 0 && <Toc headings={toc} key={pathname} />}
187183
</div>

0 commit comments

Comments
 (0)