From 4116e12237d8cc1a151bc9b278cbfffe2e86f196 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Fri, 8 Nov 2024 11:21:19 +0800 Subject: [PATCH] perf: use LazyMotion --- app/layout.tsx | 23 +++++++++++++---------- components/Switch.tsx | 4 ++-- components/TabSwitch.tsx | 4 ++-- components/motion/framer-lazy-feature.ts | 1 + components/motion/motion-provider.tsx | 14 ++++++++++++++ 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 components/motion/framer-lazy-feature.ts create mode 100644 components/motion/motion-provider.tsx diff --git a/app/layout.tsx b/app/layout.tsx index 912cdeb..61e8806 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,4 +1,5 @@ // @auto-i18n-check. Please do not delete the line. +import { MotionProvider } from "@/components/motion/motion-provider"; import getEnv from "@/lib/env-entry"; import { cn } from "@/lib/utils"; import "@/styles/globals.css"; @@ -64,16 +65,18 @@ export default async function LocaleLayout({ fontSans.variable, )} > - - - {children} - - + + + + {children} + + + ); diff --git a/components/Switch.tsx b/components/Switch.tsx index 4b0b0c4..acd68c6 100644 --- a/components/Switch.tsx +++ b/components/Switch.tsx @@ -1,7 +1,7 @@ "use client"; import { cn } from "@/lib/utils"; -import { motion } from "framer-motion"; +import { m } from "framer-motion"; import { useTranslations } from "next-intl"; import React, { createRef, useEffect, useRef } from "react"; @@ -74,7 +74,7 @@ export default function Switch({ )} > {nowTag === tag && ( - {currentTab === tab && ( - + import("./framer-lazy-feature").then((res) => res.default); + +export const MotionProvider = ({ children }: { children: React.ReactNode }) => { + return ( + + {children} + + ); +};