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.

fix: add Suspense boundaries for i18n components (#11914)

Innei2a08e644f691
diff --git a/.eslintrc.js b/.eslintrc.js
index 4aa82d9c6ed..9c308b93f28 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -20,6 +20,7 @@ config.rules['unicorn/no-array-for-each'] = 0;
config.rules['unicorn/prefer-number-properties'] = 0;
config.rules['unicorn/prefer-query-selector'] = 0;
config.rules['unicorn/no-array-callback-reference'] = 0;
+config.rules['@typescript-eslint/no-use-before-define'] = 0;
// FIXME: Linting error in src/app/[variants]/(main)/chat/features/Migration/DBReader.ts, the fundamental solution should be upgrading typescript-eslint
config.rules['@typescript-eslint/no-useless-constructor'] = 0;
config.rules['@next/next/no-img-element'] = 0;
diff --git a/src/components/DebugNode.tsx b/src/components/DebugNode.tsx
new file mode 100644
index 00000000000..b7a284d8ac9
--- /dev/null
+++ b/src/components/DebugNode.tsx
@@ -0,0 +1,21 @@
+'use client';
+
+import { type ReactNode, useEffect } from 'react';
+
+interface DebugNodeProps {
+ children?: ReactNode;
+ trace: string;
+}
+
+const DebugNode = ({ children, trace }: DebugNodeProps) => {
+ if (process.env.NODE_ENV !== 'development') return null;
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ useEffect(() => {
+ // eslint-disable-next-line no-console
+ console.log(`[DebugNode] Suspense fallback active: ${trace}`);
+ }, [trace]);
+
+ return children ?? null;
+};
+
+export default DebugNode;
diff --git a/src/features/ChatInput/ActionBar/Tools/ToolItem.tsx b/src/features/ChatInput/ActionBar/Tools/ToolItem.tsx
index 0888b2dd182..44244ac0f04 100644
--- a/src/features/ChatInput/ActionBar/Tools/ToolItem.tsx
+++ b/src/features/ChatInput/ActionBar/Tools/ToolItem.tsx
@@ -1,6 +1,7 @@
import { Flexbox } from '@lobehub/ui';
-import { memo } from 'react';
+import { Suspense, memo } from 'react';
+import DebugNode from '@/components/DebugNode';
import PluginTag from '@/components/Plugins/PluginTag';
import { useToolStore } from '@/store/tool';
import { customPluginSelectors } from '@/store/tool/selectors';
@@ -11,18 +12,20 @@ const ToolItem = memo<CheckboxItemProps>(({ id, onUpdate, label, checked }) => {
const isCustom = useToolStore((s) => customPluginSelectors.isCustomPlugin(id)(s));
return (
- <CheckboxItem
- checked={checked}
- hasPadding={false}
- id={id}
- label={
- <Flexbox align={'center'} gap={8} horizontal>
- {label || id}
- {isCustom && <PluginTag showText={false} type={'customPlugin'} />}
- </Flexbox>
- }
- onUpdate={onUpdate}
- />
+ <Suspense fallback={<DebugNode trace="ActionBar/Tools/ToolItem" />}>
+ <CheckboxItem
+ checked={checked}
+ hasPadding={false}
+ id={id}
+ label={
+ <Flexbox align={'center'} gap={8} horizontal>
+ {label || id}
+ {isCustom && <PluginTag showText={false} type={'customPlugin'} />}
+ </Flexbox>
+ }
+ onUpdate={onUpdate}
+ />
+ </Suspense>
);
});
diff --git a/src/features/ChatInput/ActionBar/Tools/ToolsList.tsx b/src/features/ChatInput/ActionBar/Tools/ToolsList.tsx
index ec92fd3abaa..b5d99eba485 100644
--- a/src/features/ChatInput/ActionBar/Tools/ToolsList.tsx
+++ b/src/features/ChatInput/ActionBar/Tools/ToolsList.tsx
@@ -59,51 +59,62 @@ interface ToolsListProps {
items: ItemType[];
}
-const ToolsList = memo<ToolsListProps>(({ items }) => {
- const renderItem = (item: ToolItemData, index: number) => {
- if (item.type === 'divider') {
- return <Divider key={`divider-${index}`} style={{ margin: '4px 0' }} />;
- }
+const DividerItem = memo<{ index: number }>(({ index }) => (
+ <Divider key={`divider-${index}`} style={{ margin: '4px 0' }} />
+));
- if (item.type === 'group') {
- return (
- <Fragment key={item.key || `group-${index}`}>
- <Text className={toolsListStyles.groupLabel} fontSize={12} type="secondary">
- {item.label}
- </Text>
- {item.children?.map((child, childIndex) => renderItem(child, childIndex))}
- </Fragment>
- );
- }
+const RegularItem = memo<{ index: number; item: ToolItemData }>(({ item, index }) => {
+ const iconNode = item.icon ? (
+ isValidElement(item.icon) ? (
+ item.icon
+ ) : (
+ <Icon icon={item.icon as any} size={20} />
+ )
+ ) : null;
+
+ return (
+ <div
+ className={toolsListStyles.item}
+ key={item.key || `item-${index}`}
+ onClick={item.onClick}
+ role="button"
+ tabIndex={0}
+ >
+ {iconNode && <div className={toolsListStyles.itemIcon}>{iconNode}</div>}
+ <div className={toolsListStyles.itemContent}>{item.label}</div>
+ {item.extra}
+ </div>
+ );
+});
- // Regular item
- // icon can be: ReactNode (already rendered), LucideIcon/ForwardRef (needs Icon wrapper), or undefined
- const iconNode = item.icon ? (
- isValidElement(item.icon) ? (
- item.icon
- ) : (
- <Icon icon={item.icon as any} size={20} />
- )
- ) : null;
-
- return (
- <div
- className={toolsListStyles.item}
- key={item.key || `item-${index}`}
- onClick={item.onClick}
- role="button"
- tabIndex={0}
- >
- {iconNode && <div className={toolsListStyles.itemIcon}>{iconNode}</div>}
- <div className={toolsListStyles.itemContent}>{item.label}</div>
- {item.extra}
- </div>
- );
- };
+const GroupItem = memo<{ index: number; item: ToolItemData }>(({ item, index }) => (
+ <Fragment key={item.key || `group-${index}`}>
+ <Text className={toolsListStyles.groupLabel} fontSize={12} type="secondary">
+ {item.label}
+ </Text>
+ {item.children?.map((child, childIndex) => (
+ <ToolListItem index={childIndex} item={child} key={child.key || `item-${childIndex}`} />
+ ))}
+ </Fragment>
+));
+const ToolListItem = memo<{ index: number; item: ToolItemData | null }>(({ item, index }) => {
+ if (!item) return null;
+ if (item.type === 'divider') return <DividerItem index={index} />;
+ if (item.type === 'group') return <GroupItem index={index} item={item} />;
+ return <RegularItem index={index} item={item} />;
+});
+
+const ToolsList = memo<ToolsListProps>(({ items }) => {
return (
<Flexbox gap={0} padding={4}>
- {items.map((item, index) => renderItem(item as ToolItemData, index))}
+ {items.map((item, index) => (
+ <ToolListItem
+ index={index}
+ item={item as ToolItemData | null}
+ key={item?.key || `item-${index}`}
+ />
+ ))}
</Flexbox>
);
});
diff --git a/src/features/ChatInput/ActionBar/components/ActionDropdown.tsx b/src/features/ChatInput/ActionBar/components/ActionDropdown.tsx
index c688928e4d7..e39a7c4afd7 100644
--- a/src/features/ChatInput/ActionBar/components/ActionDropdown.tsx
+++ b/src/features/ChatInput/ActionBar/components/ActionDropdown.tsx
@@ -17,6 +17,7 @@ import { createStaticStyles, cx } from 'antd-style';
import {
type CSSProperties,
type ReactNode,
+ Suspense,
isValidElement,
memo,
useCallback,
@@ -26,6 +27,7 @@ import {
useState,
} from 'react';
+import DebugNode from '@/components/DebugNode';
import { useIsMobile } from '@/hooks/useIsMobile';
const styles = createStaticStyles(({ css }) => ({
@@ -271,7 +273,11 @@ const ActionDropdown = memo<ActionDropdownProps>(
hoverTrigger={Boolean(resolvedTriggerProps?.openOnHover)}
placement={isMobile ? 'top' : placement}
>
- <DropdownMenuPopup {...resolvedPopupProps}>{menuContent}</DropdownMenuPopup>
+ <DropdownMenuPopup {...resolvedPopupProps}>
+ <Suspense fallback={<DebugNode trace="ActionDropdown > popup" />}>
+ {menuContent}
+ </Suspense>
+ </DropdownMenuPopup>
</DropdownMenuPositioner>
</DropdownMenuPortal>
</DropdownMenuRoot>
diff --git a/src/features/ChatInput/ActionBar/components/ActionPopover.tsx b/src/features/ChatInput/ActionBar/components/ActionPopover.tsx
index 0f2bb8c7ffd..41ec0440503 100644
--- a/src/features/ChatInput/ActionBar/components/ActionPopover.tsx
+++ b/src/features/ChatInput/ActionBar/components/ActionPopover.tsx
@@ -2,8 +2,9 @@
import { Flexbox, Popover, type PopoverProps } from '@lobehub/ui';
import { createStaticStyles, cssVar, cx } from 'antd-style';
-import { type ReactNode, memo } from 'react';
+import { type ReactNode, Suspense, memo } from 'react';
+import DebugNode from '@/components/DebugNode';
import UpdateLoading from '@/components/Loading/UpdateLoading';
import { useIsMobile } from '@/hooks/useIsMobile';
@@ -65,16 +66,18 @@ const ActionPopover = memo<ActionPopoverProps>(
// Compose content with optional title
const popoverContent = (
- <>
- {title && (
- <Flexbox gap={8} horizontal justify={'space-between'} style={{ marginBottom: 16 }}>
- {title}
- {extra}
- {loading && <UpdateLoading style={{ color: cssVar.colorTextSecondary }} />}
- </Flexbox>
- )}
- {content}
- </>
+ <Suspense fallback={<DebugNode trace="ActionPopover > content" />}>
+ <>
+ {title && (
+ <Flexbox gap={8} horizontal justify={'space-between'} style={{ marginBottom: 16 }}>
+ {title}
+ {extra}
+ {loading && <UpdateLoading style={{ color: cssVar.colorTextSecondary }} />}
+ </Flexbox>
+ )}
+ {content}
+ </>
+ </Suspense>
);
return (