diff --git a/vite.config.ts b/vite.config.ts index 15adf71..74467d3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -99,8 +99,20 @@ export default defineConfig(() => ({ ) { return 'vendor-bitcoin'; } - // React ecosystem — very stable, long cache life - if (id.includes('react-dom') || id.includes('react-router')) { + // React ecosystem — very stable, long cache life. + // IMPORTANT: `react` (core, with useLayoutEffect etc.) MUST live in + // the SAME chunk as react-dom / react-router. If react-dom is split + // into vendor-react but core `react` lands elsewhere, react-dom runs + // before React is defined → "Cannot read properties of undefined + // (reading 'useLayoutEffect')". The `/react/` and scheduler matches + // below keep the whole React runtime together and loaded first. + if ( + id.includes('node_modules/react/') || + id.includes('node_modules/react-dom/') || + id.includes('node_modules/scheduler/') || + id.includes('react-router') || + id.includes('react/jsx-runtime') + ) { return 'vendor-react'; } // Radix UI components — large but stable