Skip to content

Commit 61de93a

Browse files
m4dm4rtig4nClément VALENTINclaude
authored
fix(web): use object-based manualChunks to prevent circular deps (#66)
The function-based manualChunks was creating circular dependencies between chunks (react-vendor importing from chart-vendor). This caused race conditions where React.forwardRef could be undefined when ui-vendor loaded before react-vendor finished initializing. Switch to object-based syntax which Rollup handles more safely, consolidating all core dependencies into a single vendor chunk. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Clément VALENTIN <clement.valentin@blacktiger.tech> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2a75fbf commit 61de93a

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

apps/web/vite.config.ts

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,24 @@ export default defineConfig(({ mode }) => {
3030
entryFileNames: 'assets/[name]-[hash].js',
3131
chunkFileNames: 'assets/[name]-[hash].js',
3232
assetFileNames: 'assets/[name]-[hash].[ext]',
33-
manualChunks(id) {
34-
// Core React + React-dependent UI libs - must stay together
35-
// @headlessui/react uses React.forwardRef, so it must be in the same chunk
36-
if (id.includes('node_modules/react/') ||
37-
id.includes('node_modules/react-dom/') ||
38-
id.includes('node_modules/react-router-dom/') ||
39-
id.includes('@headlessui/react')) {
40-
return 'react-vendor';
41-
}
42-
// UI utilities - no React dependency
43-
if (id.includes('lucide-react') ||
44-
id.includes('clsx')) {
45-
return 'ui-vendor';
46-
}
47-
// Charts - only on dashboard/consumption pages
48-
if (id.includes('recharts')) {
49-
return 'chart-vendor';
50-
}
51-
// Data fetching - loaded on most pages
52-
if (id.includes('@tanstack/react-query') ||
53-
id.includes('axios') ||
54-
id.includes('zustand')) {
55-
return 'query-vendor';
56-
}
57-
// Heavy dependencies - lazy loaded
58-
if (id.includes('swagger-ui-react')) {
59-
return 'swagger-ui';
60-
}
61-
if (id.includes('jspdf') || id.includes('html2canvas')) {
62-
return 'pdf-vendor';
63-
}
33+
manualChunks: {
34+
// Core vendor - all node_modules except heavy lazy-loaded ones
35+
// Using object syntax prevents circular dependency issues
36+
vendor: [
37+
'react',
38+
'react-dom',
39+
'react-router-dom',
40+
'@headlessui/react',
41+
'@tanstack/react-query',
42+
'axios',
43+
'zustand',
44+
'lucide-react',
45+
'clsx',
46+
],
47+
// Charts - lazy loaded on dashboard/consumption pages
48+
charts: ['recharts'],
49+
// PDF generation - lazy loaded
50+
pdf: ['jspdf', 'html2canvas'],
6451
},
6552
},
6653
},

0 commit comments

Comments
 (0)