Skip to content

Commit b22f5a0

Browse files
🚨 fix(playground): clear lint warnings in the landing page
1 parent 876d695 commit b22f5a0

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎playground/docs/home/BentoGallery.tsx‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Flexbox, Highlighter, Hotkey, Segmented, Snippet } from '@lobehub/ui';
22
import { BentoCard, BentoGrid } from '@lobehub/ui/awesome';
33
import { useTheme } from 'next-themes';
4-
import { useEffect, useState } from 'react';
4+
import { useEffect, useState, useSyncExternalStore } from 'react';
55

66
import DemoPreview from './DemoPreview.mdx';
77
import { renderLink } from './renderLink';
@@ -12,10 +12,16 @@ description: Button triggers an action.
1212
category: General
1313
---`;
1414

15+
const subscribeToNothing = () => () => {};
16+
1517
function ThemeSwitchTile() {
1618
const { setTheme, theme } = useTheme();
17-
const [mounted, setMounted] = useState(false);
18-
useEffect(() => setMounted(true), []);
19+
// false while prerendering and hydrating, true afterwards: the stored theme is only known in the browser
20+
const mounted = useSyncExternalStore(
21+
subscribeToNothing,
22+
() => true,
23+
() => false,
24+
);
1925
const preference = mounted && (theme === 'light' || theme === 'dark') ? theme : 'system';
2026

2127
return (
@@ -35,18 +41,16 @@ function LlmsTxtTile() {
3541
const [excerpt, setExcerpt] = useState('Loading /llms.txt…');
3642

3743
useEffect(() => {
38-
let cancelled = false;
39-
fetch('/llms.txt')
44+
const controller = new AbortController();
45+
fetch('/llms.txt', { signal: controller.signal })
4046
.then((response) => (response.ok ? response.text() : Promise.reject(response.status)))
41-
.then((text) => {
42-
if (!cancelled) setExcerpt(text.split('\n').slice(0, 7).join('\n').trim());
43-
})
47+
.then((text) => setExcerpt(text.split('\n').slice(0, 7).join('\n').trim()))
4448
.catch(() => {
45-
if (!cancelled) setExcerpt('Open /llms.txt to read the index of this site.');
49+
if (!controller.signal.aborted) {
50+
setExcerpt('Open /llms.txt to read the index of this site.');
51+
}
4652
});
47-
return () => {
48-
cancelled = true;
49-
};
53+
return () => controller.abort();
5054
}, []);
5155

5256
return (

‎playground/docs/home/home.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export default function Home({
9090
onNavigate={navigate}
9191
>
9292
<LogoMarquee
93+
items={STATIC_HOSTS}
9394
caption={
9495
<Link to="/guide/build-and-deploy">Static HTML in dist/, ready for any host</Link>
9596
}
96-
items={STATIC_HOSTS}
9797
/>
9898
</LandingHero>
9999

0 commit comments

Comments
 (0)