Skip to content

Commit a7381a0

Browse files
committed
feat: 使用lazyMotion优化性能
1 parent 9c25798 commit a7381a0

File tree

13 files changed

+76
-50
lines changed

13 files changed

+76
-50
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"tailwind-scrollbar": "^3.1.0",
4242
"tailwind-variants": "^0.2.1",
4343
"tailwindcss-animate": "^1.0.7",
44-
"tailwindcss-animated": "^1.1.2"
44+
"tailwindcss-animated": "^1.1.2",
45+
"zustand": "^5.0.0"
4546
},
4647
"devDependencies": {
4748
"@commitlint/cli": "^19.4.1",

pnpm-lock.yaml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(app)/(home)/page.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { motion } from 'framer-motion';
3+
import { m } from 'framer-motion';
44
import { createElement, useEffect, useState } from 'react';
55
import Image from 'next/image';
66

@@ -155,7 +155,7 @@ const Hero = () => {
155155
<div className="mt-[-2.5rem] min-w-0 md:px-44 max-w-screen overflow-hidden lg:mt-[-6.5rem] lg:h-dvh lg:min-h-[800px]">
156156
<TwoColumnLayout leftContainerClassName="mt-[110px] lg:mt-0 lg:h-[15rem] lg:h-1/2">
157157
<>
158-
<motion.div
158+
<m.div
159159
className=" relative text-center leading-[4] lg:text-left lg:ml-24 lg:mt-10"
160160
initial={{ y: 50, opacity: 1 }}
161161
animate={{ y: 0, opacity: 1 }}
@@ -178,9 +178,9 @@ const Hero = () => {
178178
)
179179
: null;
180180
})}
181-
</motion.div>
181+
</m.div>
182182

183-
<motion.div
183+
<m.div
184184
initial={{ y: 50, opacity: 0 }}
185185
animate={{ y: 0, opacity: 1 }}
186186
transition={{
@@ -192,11 +192,11 @@ const Hero = () => {
192192
className="my-3 text-center lg:text-left lg:ml-24"
193193
>
194194
<span className=" opacity-70"> {description}</span>
195-
</motion.div>
195+
</m.div>
196196

197197
<ul className="center mx-[60px] mt-8 flex flex-wrap gap-6 lg:mx-auto lg:mt-24 lg:justify-start lg:gap-4 lg:ml-24">
198198
{Object.entries(socialIds).map(([type, id], index) => (
199-
<motion.li
199+
<m.li
200200
key={type}
201201
initial={{ y: 50, opacity: 0 }}
202202
animate={{ y: 0, opacity: 1 }}
@@ -209,7 +209,7 @@ const Hero = () => {
209209
className="inline-block"
210210
>
211211
<SocialIcon id={id} type={type} />
212-
</motion.li>
212+
</m.li>
213213
))}
214214
</ul>
215215
</>
@@ -243,7 +243,7 @@ const Quote = () => {
243243
}, []);
244244

245245
return (
246-
<motion.div
246+
<m.div
247247
initial={{ opacity: 0.0001, y: 50 }}
248248
animate={{ opacity: 1, y: 0 }}
249249
transition={{ type: 'spring', damping: 10, stiffness: 100 }}
@@ -255,14 +255,14 @@ const Quote = () => {
255255
<small className=" flex text-center items-center ">
256256
{quote.hitokoto}
257257
<span className=" text-center ml-4">{quote.from}</span>
258-
<motion.span onClick={() => getQuote()} className=" flex items-center ml-3 cursor-pointer">
258+
<m.span onClick={() => getQuote()} className=" flex items-center ml-3 cursor-pointer">
259259
<i className="i-mingcute-refresh-2-line invisible group-hover:visible"></i>
260-
</motion.span>
260+
</m.span>
261261
</small>
262262
<span className="mt-6 animate-bounce">
263263
<i className="i-mingcute-right-line rotate-90 text-2xl" />
264264
</span>
265-
</motion.div>
265+
</m.div>
266266
);
267267
};
268268

@@ -316,7 +316,7 @@ const WindVane = () => {
316316
<ul className=" flex flex-col flex-wrap gap-2 gap-y-10 opacity-80 lg:flex-row">
317317
{windsock.map((item, index) => {
318318
return (
319-
<motion.li
319+
<m.li
320320
initial={{ opacity: 0.0001, y: 15 }}
321321
viewport={{ once: true }}
322322
whileInView={{
@@ -358,7 +358,7 @@ const WindVane = () => {
358358
{index != windsock.length - 1 && (
359359
<span className="mx-4 hidden select-none lg:inline"> · </span>
360360
)}
361-
</motion.li>
361+
</m.li>
362362
);
363363
})}
364364
</ul>

src/app/(app)/friends/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { motion } from 'framer-motion';
3+
import { m } from 'framer-motion';
44
import { memo, useState } from 'react';
55
import Image from 'next/image';
66

@@ -32,7 +32,7 @@ const FriendCard = ({ friendModel }: { friendModel: FriendModel }) => {
3232
const [enter, setEnter] = useState(false);
3333

3434
return (
35-
<motion.div
35+
<m.div
3636
key={friendModel.name}
3737
role="link"
3838
aria-label={`Go to ${friendModel.name}'s website`}
@@ -56,12 +56,12 @@ const FriendCard = ({ friendModel }: { friendModel: FriendModel }) => {
5656
{friendModel.desc}
5757
</span>
5858
</span>
59-
</motion.div>
59+
</m.div>
6060
);
6161
};
6262
const LayoutBg = memo(() => {
6363
return (
64-
<motion.span
64+
<m.span
6565
layoutId="bg"
6666
className="absolute -inset-2 z-[-1] rounded-md bg-slate-200/80 dark:bg-neutral-600/80 pointer-events-none"
6767
initial={{ opacity: 0.8, scale: 0.8 }}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const Header = () => {
2+
return <div>哈哈哈哈111111111</div>;
3+
};

src/components/layout/Header/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { Header } from './Header';
2+
export default Header;

src/components/layout/Root/Root.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import type { PropsWithChildren } from 'react';
44

55
import Content from '../Content';
66
import Footer from '../Footer';
7-
// import { Header } from '../Header';
7+
import Header from '../Header';
88

99
const Root = ({ children }: PropsWithChildren) => {
1010
return (
1111
<>
12-
{/* <Header /> */}
12+
<Header />
1313
<Content>{children}</Content>
14-
1514
<Footer />
1615
{/* <ClientOnly>
1716
<FABContainer />

src/components/modules/shared/AccentColorStyleInjector/AccentColorStyleInjector.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,9 @@ const convertHexToRgbString = (hex: string): string => {
2020
return `${r} ${g} ${b}`;
2121
};
2222

23-
const accentColorLight = [
24-
// 浅葱
25-
'#33A6B8',
26-
'#FF6666',
27-
'#26A69A',
28-
'#fb7287',
29-
'#69a6cc',
30-
];
31-
32-
const accentColorDark = [
33-
// 桃
34-
'#F596AA',
35-
'#A0A7D4',
36-
'#ff7b7b',
37-
'#99D8CF',
38-
'#838BC6',
39-
];
23+
const accentColorLight = ['#33A6B8', '#FF6666', '#26A69A', '#fb7287', '#69a6cc'];
24+
25+
const accentColorDark = ['#F596AA', '#A0A7D4', '#ff7b7b', '#99D8CF', '#838BC6'];
4026

4127
const defaultAccentColor = { light: accentColorLight, dark: accentColorDark };
4228

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { domMax as default } from 'framer-motion';

src/components/providers/root/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
'use client';
2+
13
import { PropsWithChildren } from 'react';
24
import { ThemeProvider } from 'next-themes';
5+
import { LazyMotion } from 'framer-motion';
36

47
import ProviderComposer from '@/components/modules/shared/ProviderComposer';
58

6-
const webAppContexts: JSX.Element[] = [<ThemeProvider children key="themeProvider" />];
9+
const loadFeatures = () => import('./framer-lazy-feature').then((res) => res.default);
10+
11+
const webAppContexts: JSX.Element[] = [
12+
<ThemeProvider children key="themeProvider" />,
13+
<LazyMotion features={loadFeatures} strict key="framer" />,
14+
];
715

816
export default function WebAppProviders({ children }: PropsWithChildren) {
917
return <ProviderComposer contexts={webAppContexts}>{children}</ProviderComposer>;

0 commit comments

Comments
 (0)