Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor(motion): import `m` from `motion/react-m` instead of the barrel (#19491)

Inneicb93a85a5cc1
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 2c09887f7a7..5e91e08de80 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -39,9 +39,9 @@ const performanceRestrictedImportPaths = [
},
{
allowTypeImports: true,
- importNames: ['motion'],
+ importNames: ['motion', 'm'],
message:
- 'The app runs under <LazyMotion features={domMax}>; `motion` bundles every feature again. Use `m` from "motion/react" (or "motion/react-m").',
+ 'The app runs under <LazyMotion features={domMax}>; `motion` bundles every feature again and `m` from the barrel drags it along. Use `import * as m from "motion/react-m"`.',
name: 'motion/react',
},
{
diff --git a/src/features/AgentSidebar/Topic/List/Item/index.test.tsx b/src/features/AgentSidebar/Topic/List/Item/index.test.tsx
index a277c53ce61..0162a86f4ee 100644
--- a/src/features/AgentSidebar/Topic/List/Item/index.test.tsx
+++ b/src/features/AgentSidebar/Topic/List/Item/index.test.tsx
@@ -30,14 +30,15 @@ vi.mock('@lobehub/ui', async (importOriginal) => ({
vi.mock('motion/react', () => ({
AnimatePresence: ({ children }: { children?: ReactNode }) => <>{children}</>,
- m: {
- div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
- <div {...props}>{children}</div>
- ),
- span: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
- <span {...props}>{children}</span>
- ),
- },
+}));
+
+vi.mock('motion/react-m', () => ({
+ div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
+ <div {...props}>{children}</div>
+ ),
+ span: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
+ <span {...props}>{children}</span>
+ ),
}));
vi.mock('@/const/version', () => ({ isDesktop: false }));
diff --git a/src/features/Billboard/Carousel.tsx b/src/features/Billboard/Carousel.tsx
index f86db172cc2..c83dfe1af46 100644
--- a/src/features/Billboard/Carousel.tsx
+++ b/src/features/Billboard/Carousel.tsx
@@ -5,7 +5,7 @@ import { ActionIcon, Button } from '@lobehub/ui/base-ui';
import { Carousel as AntCarousel } from 'antd';
import { createStaticStyles, cssVar } from 'antd-style';
import { X } from 'lucide-react';
-import { m } from 'motion/react';
+import * as m from 'motion/react-m';
import {
type ComponentRef,
memo,
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx
index bb20f2adcb9..9809eb3e204 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx
@@ -85,14 +85,15 @@ vi.mock('@lobehub/ui/base-ui', async (importOriginal) => ({
vi.mock('motion/react', () => ({
AnimatePresence: ({ children }: { children?: ReactNode }) => <>{children}</>,
- m: {
- div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
- <div {...props}>{children}</div>
- ),
- span: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
- <span {...props}>{children}</span>
- ),
- },
+}));
+
+vi.mock('motion/react-m', () => ({
+ div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
+ <div {...props}>{children}</div>
+ ),
+ span: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
+ <span {...props}>{children}</span>
+ ),
}));
vi.mock('react-i18next', () => ({
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx
index 7ed3182a1d0..3c5a5ee7882 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx
@@ -3,7 +3,8 @@ import { Accordion, AccordionItem, Block, Flexbox, Icon } from '@lobehub/ui';
import { ActionIcon, Text } from '@lobehub/ui/base-ui';
import { cssVar } from 'antd-style';
import { Check, HandIcon, Maximize2, Minimize2, X } from 'lucide-react';
-import { AnimatePresence, m as motion } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as motion from 'motion/react-m';
import { type Key, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/src/features/Conversation/Messages/components/SearchGrounding.tsx b/src/features/Conversation/Messages/components/SearchGrounding.tsx
index fcc2fc55b06..7573b965736 100644
--- a/src/features/Conversation/Messages/components/SearchGrounding.tsx
+++ b/src/features/Conversation/Messages/components/SearchGrounding.tsx
@@ -2,7 +2,8 @@ import { Flexbox, Icon, SearchResultCards } from '@lobehub/ui';
import { Tag } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar, cx } from 'antd-style';
import { ChevronDown, ChevronRight, Globe, Images } from 'lucide-react';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/src/features/Conversation/WorkingSidebar/Review/FileRow.tsx b/src/features/Conversation/WorkingSidebar/Review/FileRow.tsx
index fae0cebc3da..9c2720a307b 100644
--- a/src/features/Conversation/WorkingSidebar/Review/FileRow.tsx
+++ b/src/features/Conversation/WorkingSidebar/Review/FileRow.tsx
@@ -3,7 +3,8 @@
import type { GitWorkingTreePatch } from '@lobechat/electron-client-ipc';
import { createStaticStyles } from 'antd-style';
import { ChevronRightIcon } from 'lucide-react';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { type KeyboardEvent, memo, useCallback } from 'react';
import type { ComposerTarget } from '../../types';
diff --git a/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx b/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx
index bd1c790280e..8c70691f746 100644
--- a/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx
+++ b/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx
@@ -117,11 +117,12 @@ const globalStore = vi.hoisted(() => ({
vi.mock('motion/react', () => ({
AnimatePresence: ({ children }: { children?: ReactNode }) => <>{children}</>,
- m: {
- div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
- <div {...props}>{children}</div>
- ),
- },
+}));
+
+vi.mock('motion/react-m', () => ({
+ div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
+ <div {...props}>{children}</div>
+ ),
}));
vi.mock('@/features/RightPanel', () => ({
diff --git a/src/features/Conversation/WorkingSidebar/index.tsx b/src/features/Conversation/WorkingSidebar/index.tsx
index 18939b76e98..2812baa560f 100644
--- a/src/features/Conversation/WorkingSidebar/index.tsx
+++ b/src/features/Conversation/WorkingSidebar/index.tsx
@@ -23,7 +23,8 @@ import {
SquareTerminalIcon,
XIcon,
} from 'lucide-react';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import {
Activity,
lazy,
diff --git a/src/features/Electron/system/ZoomHUD/index.test.tsx b/src/features/Electron/system/ZoomHUD/index.test.tsx
index ab5476b267f..95a6c09c986 100644
--- a/src/features/Electron/system/ZoomHUD/index.test.tsx
+++ b/src/features/Electron/system/ZoomHUD/index.test.tsx
@@ -1,4 +1,5 @@
import { act, render, screen } from '@testing-library/react';
+import type { ReactNode } from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import ZoomHUD from './index';
@@ -13,21 +14,15 @@ vi.mock('@lobechat/electron-client-ipc', () => ({
},
}));
-vi.mock('motion/react', async () => {
- const React = await import('react');
- return {
- AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}</>,
- m: new Proxy(
- {},
- {
- get:
- () =>
- ({ children, ...rest }: any) =>
- React.createElement('div', rest, children),
- },
- ),
- };
-});
+vi.mock('motion/react', () => ({
+ AnimatePresence: ({ children }: { children: ReactNode }) => <>{children}</>,
+}));
+
+vi.mock('motion/react-m', () => ({
+ div: ({ children, ...rest }: { children?: ReactNode; [key: string]: unknown }) => (
+ <div {...rest}>{children}</div>
+ ),
+}));
const emit = (factor: number, level: number) => {
act(() => {
diff --git a/src/features/Electron/system/ZoomHUD/index.tsx b/src/features/Electron/system/ZoomHUD/index.tsx
index 08b2f1038db..dbcc13406c1 100644
--- a/src/features/Electron/system/ZoomHUD/index.tsx
+++ b/src/features/Electron/system/ZoomHUD/index.tsx
@@ -2,7 +2,8 @@
import { useWatchBroadcast } from '@lobechat/electron-client-ipc';
import { createStaticStyles, cssVar } from 'antd-style';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { memo, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/src/features/GlobalApprovalNotification/index.tsx b/src/features/GlobalApprovalNotification/index.tsx
index 3b5f7d59bdb..908a66226e6 100644
--- a/src/features/GlobalApprovalNotification/index.tsx
+++ b/src/features/GlobalApprovalNotification/index.tsx
@@ -3,7 +3,8 @@
import { TITLE_BAR_HEIGHT } from '@lobechat/desktop-bridge';
import { ActionIcon } from '@lobehub/ui/base-ui';
import { ChevronUp } from 'lucide-react';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { memo, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/src/features/PageEditor/RightPanel/index.tsx b/src/features/PageEditor/RightPanel/index.tsx
index cf29c7cb2ca..81e676addda 100644
--- a/src/features/PageEditor/RightPanel/index.tsx
+++ b/src/features/PageEditor/RightPanel/index.tsx
@@ -2,7 +2,8 @@
import { Freeze } from '@lobehub/ui';
import { createStaticStyles } from 'antd-style';
-import { AnimatePresence, m, useIsPresent } from 'motion/react';
+import { AnimatePresence, useIsPresent } from 'motion/react';
+import * as m from 'motion/react-m';
import { type ReactNode } from 'react';
import { memo, useMemo, useRef } from 'react';
diff --git a/src/features/Settings/proxy/features/SaveBar.tsx b/src/features/Settings/proxy/features/SaveBar.tsx
index 4f2cdb3c7e6..c14ea591f5a 100644
--- a/src/features/Settings/proxy/features/SaveBar.tsx
+++ b/src/features/Settings/proxy/features/SaveBar.tsx
@@ -2,7 +2,8 @@
import { Button } from '@lobehub/ui/base-ui';
import { createStaticStyles } from 'antd-style';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/src/features/TaskDock/index.tsx b/src/features/TaskDock/index.tsx
index f5fc9861c50..19818b17b41 100644
--- a/src/features/TaskDock/index.tsx
+++ b/src/features/TaskDock/index.tsx
@@ -9,7 +9,8 @@ import {
TriangleAlertIcon,
XIcon,
} from 'lucide-react';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
diff --git a/src/routes/(main)/(create)/features/CreateGenerationPage.tsx b/src/routes/(main)/(create)/features/CreateGenerationPage.tsx
index ebb346643af..c8ecf1609ac 100644
--- a/src/routes/(main)/(create)/features/CreateGenerationPage.tsx
+++ b/src/routes/(main)/(create)/features/CreateGenerationPage.tsx
@@ -1,7 +1,8 @@
'use client';
import { Flexbox } from '@lobehub/ui';
-import { AnimatePresence, m as motion } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as motion from 'motion/react-m';
import type { ComponentType, CSSProperties } from 'react';
import { memo } from 'react';
import { useMatch } from 'react-router';
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx
index 9720be9d78f..291ad07d03c 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx
@@ -4,7 +4,8 @@ import { Flexbox, Icon, Tooltip } from '@lobehub/ui';
import { Skeleton, Tag, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar, useTheme } from 'antd-style';
import { HashIcon, MessageSquareDashed } from 'lucide-react';
-import { AnimatePresence, m } from 'motion/react';
+import { AnimatePresence } from 'motion/react';
+import * as m from 'motion/react-m';
import { memo, Suspense, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';