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.

⚡️ perf(spa): fold first-screen @lobehub/ui members into vendor-ui-core (#19062)

Innei0877876478bd
diff --git a/plugins/vite/lobeUiImports.ts b/plugins/vite/lobeUiImports.ts
index be827da9b79..171801fcec1 100644
--- a/plugins/vite/lobeUiImports.ts
+++ b/plugins/vite/lobeUiImports.ts
@@ -90,9 +90,16 @@ const namedExportProxy = (maps: Record<string, Barrel>): Plugin => ({
return `export { ${entry.imported} as default } from ${JSON.stringify(source)};`;
},
- resolveId(id) {
+ resolveId(id, importer) {
if (!id.startsWith(NAMED_EXPORT_PREFIX)) return;
+ const [barrel, member] = id.slice(NAMED_EXPORT_PREFIX.length).split(':');
+ const entry = maps[barrel]?.members[member];
+ // A default export needs no proxy module; pointing straight at the source
+ // avoids one facade chunk per member shared between routes.
+ if (entry?.imported === 'default' && entry.source.startsWith('@lobehub/ui/es/'))
+ return this.resolve(entry.source, importer);
+
return `\0${id}`;
},
});
diff --git a/plugins/vite/sharedRendererConfig.test.ts b/plugins/vite/sharedRendererConfig.test.ts
index c0417c78ada..59f5be46de1 100644
--- a/plugins/vite/sharedRendererConfig.test.ts
+++ b/plugins/vite/sharedRendererConfig.test.ts
@@ -189,6 +189,19 @@ describe('sharedManualChunks', () => {
});
});
+describe('isUiCoreModule', () => {
+ it('folds first-screen @lobehub/ui members into vendor-ui-core and leaves heavy ones lazy', () => {
+ const es = '/repo/node_modules/.pnpm/@lobehub+ui@5/node_modules/@lobehub/ui/es/';
+ expect(__testing.isUiCoreModule(`${es}Flex/FlexBasic.mjs`)).toBe(true);
+ expect(__testing.isUiCoreModule(`${es}base-ui/Button/Button.mjs`)).toBe(true);
+ expect(__testing.isUiCoreModule(`${es}hooks/useIsClient.mjs`)).toBe(true);
+ expect(__testing.isUiCoreModule(`${es}Markdown/Markdown.mjs`)).toBe(false);
+ expect(__testing.isUiCoreModule(`${es}hooks/useMarkdown/index.mjs`)).toBe(false);
+ expect(__testing.isUiCoreModule(`${es}base-ui/Select/Select.mjs`)).toBe(false);
+ expect(__testing.isUiCoreModule('/repo/node_modules/antd/es/index.js')).toBe(false);
+ });
+});
+
describe('sharedChunkFileNames', () => {
it('routes only the complete deferred model catalog to on-demand assets', () => {
expect(
diff --git a/plugins/vite/sharedRendererConfig.ts b/plugins/vite/sharedRendererConfig.ts
index 05859829e8c..3e6649ff38b 100644
--- a/plugins/vite/sharedRendererConfig.ts
+++ b/plugins/vite/sharedRendererConfig.ts
@@ -319,6 +319,21 @@ interface SharedRolldownOutputOptions {
strictExecutionOrder?: boolean;
}
+// @lobehub/ui members on the first-screen path of dist/desktop, measured with
+// bundle-size-gate --type entry-graph. lobeUiImports splits the barrel into one
+// module per member; folding the eager ones back into one chunk keeps the heavy
+// members (Markdown, Mermaid, EmojiPicker, Highlighter, Image) on lazy routes.
+const UI_CORE_MEMBER_RE =
+ /^(?:Accordion|ActionIcon|Block|Collapse|ConfigProvider|Flex|FluentEmoji|Grid|Hotkey|Icon|Img|Modal|MotionProvider|Skeleton|Text|ThemeProvider|color|styles|utils|hooks\/use(?:IsClient|NativeButton|TextOverflow)|icons\/lucideExtra|base-ui\/(?:ActionIcon|Avatar|Button|Checkbox|ContextMenu|Modal|Popover|Switch|Text|Toast|Tooltip|controlSize|focusRing|zIndex))(?:\/|\.)/;
+
+const isUiCoreModule = (id: string) => {
+ const member = id.replaceAll('\\', '/').split('/node_modules/@lobehub/ui/es/')[1];
+
+ return Boolean(member && UI_CORE_MEMBER_RE.test(member));
+};
+
+// Rolldown groups also capture their modules' dependencies; a higher priority
+// keeps the explicit groups above (and antd) from being pulled into ui-core.
export const createSharedRolldownOutput = (options: SharedRolldownOutputOptions = {}) => ({
chunkFileNames: sharedChunkFileNames,
strictExecutionOrder: options.strictExecutionOrder ?? true,
@@ -326,7 +341,14 @@ export const createSharedRolldownOutput = (options: SharedRolldownOutputOptions
groups: [
{
name: (moduleId: string) => sharedManualChunks(moduleId) ?? null,
+ priority: 3,
},
+ {
+ name: 'vendor-antd',
+ priority: 2,
+ test: /[\\/]node_modules[\\/](?:antd|@ant-design|@rc-component)[\\/]/,
+ },
+ { name: 'vendor-ui-core', priority: 1, test: isUiCoreModule },
],
},
});
@@ -433,7 +455,4 @@ export const sharedOptimizeDeps = {
// snapshots. They must still share one LexicalComposerContext at runtime.
export const sharedRendererDedupe = ['@lobehub/editor', 'react', 'react-dom'];
-export const __testing = {
- sharedChunkFileNames,
- sharedManualChunks,
-};
+export const __testing = { isUiCoreModule, sharedChunkFileNames, sharedManualChunks };