Skip to content

Commit bd7cdcb

Browse files
committed
feat: 尝试react scan
1 parent 8af2b78 commit bd7cdcb

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

.million/store.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"encodings":[],"reactData":{},"unusedFiles":[],"mtime":null}

src/app/layout.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export default async function RootLayout({ children }: PropsWithChildren) {
7171
return (
7272
<html lang="zh-CN" className=" noise" suppressHydrationWarning>
7373
<head>
74+
{/* react scan */}
75+
{/* <script src="https://unpkg.com/react-scan/dist/auto.global.js" async></script> */}
7476
<SayHi />
7577
<AccentColorStyleInjector />
7678
</head>

src/components/modules/shared/ReadIndicator.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useEffect, useState } from 'react';
3+
import { memo, useDeferredValue, useEffect, useState } from 'react';
44

55
import { MaterialSymbolsProgressActivity } from '@/components/icons/Progress';
66
import { MotionButtonBase } from '@/components/ui/button';
@@ -35,21 +35,27 @@ export const ReadIndicator = () => {
3535
}, [Element]);
3636

3737
return (
38-
<div className="text-gray-800 dark:text-neutral-300">
38+
<div className="text-gray-800 dark:text-neutral-300 gap-4">
3939
<div className="flex items-center gap-2">
4040
<MaterialSymbolsProgressActivity progress={readPercent} />
4141
{readPercent}%<br />
4242
</div>
43-
<MotionButtonBase
44-
onClick={springScrollToTop}
45-
className={cn(
46-
'mt-1 flex flex-nowrap items-center gap-2 opacity-50 transition-all duration-500 hover:opacity-100',
47-
readPercent > 10 ? '' : 'pointer-events-none opacity-0',
48-
)}
49-
>
50-
<i className="i-mingcute-arrow-up-circle-line" />
51-
<span className="whitespace-nowrap">回到顶部</span>
52-
</MotionButtonBase>
43+
<BackToTop readPercent={useDeferredValue(readPercent)} />
5344
</div>
5445
);
5546
};
47+
48+
const BackToTop = memo(({ readPercent }: { readPercent: number }) => {
49+
return (
50+
<MotionButtonBase
51+
onClick={springScrollToTop}
52+
className={cn(
53+
'mt-1 flex flex-nowrap items-center gap-2 opacity-50 transition-all duration-500 hover:opacity-100',
54+
readPercent > 10 ? '' : 'pointer-events-none opacity-0',
55+
)}
56+
>
57+
<i className="i-mingcute-arrow-up-circle-line" />
58+
<span className="whitespace-nowrap">回到顶部</span>
59+
</MotionButtonBase>
60+
);
61+
});

0 commit comments

Comments
 (0)