Skip to content

lazy loading and bundle size reduction#23

Merged
benhalverson merged 2 commits intomainfrom
fix-warnings
Oct 28, 2025
Merged

lazy loading and bundle size reduction#23
benhalverson merged 2 commits intomainfrom
fix-warnings

Conversation

@benhalverson
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings October 28, 2025 07:56
@benhalverson benhalverson marked this pull request as ready for review October 28, 2025 07:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements lazy loading and bundle size optimizations by introducing code-splitting for route components, optimizing Three.js imports, and configuring manual chunks for better caching. The changes include a bundle analyzer plugin to monitor the impact of these optimizations.

  • Implemented React lazy loading for all page components with a Suspense fallback
  • Configured manual chunk splitting for major dependencies (React, Three.js, UI libraries, forms)
  • Reduced Three.js imports to only what's needed (Vector3 instead of entire namespace)

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vite.config.ts Added bundle analyzer plugin and manual chunk configuration for vendor splitting
src/App.tsx Converted page imports to lazy loading with Suspense boundary
src/components/PreviewComponent.tsx Optimized Three.js imports to use named import instead of namespace
src/pages/Product.tsx Updated Tailwind class from flex-shrink-0 to shrink-0 (shorthand)
package.json Added rollup-plugin-visualizer dev dependency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 28, 2025 07:59
@benhalverson benhalverson merged commit b11677c into main Oct 28, 2025
1 check passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +20
plugins: [viteReact(), tailwindcss(),
(isAnalyze) &&
visualizer({
filename: 'stats.html',
template: 'treemap', // 'sunburst' | 'network' | 'treemap'
brotliSize: true,
gzipSize: true,
open: true,
}),
].filter(Boolean),
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The conditional plugin inclusion using (isAnalyze) && followed by .filter(Boolean) could be clearer. Consider using a ternary operator or spreading the plugin conditionally: ...(isAnalyze ? [visualizer({ ... })] : []) to make the intent more explicit.

Suggested change
plugins: [viteReact(), tailwindcss(),
(isAnalyze) &&
visualizer({
filename: 'stats.html',
template: 'treemap', // 'sunburst' | 'network' | 'treemap'
brotliSize: true,
gzipSize: true,
open: true,
}),
].filter(Boolean),
plugins: [
viteReact(),
tailwindcss(),
...(isAnalyze ? [
visualizer({
filename: 'stats.html',
template: 'treemap', // 'sunburst' | 'network' | 'treemap'
brotliSize: true,
gzipSize: true,
open: true,
})
] : []),
],

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +35
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom') || id.includes('node_modules/react-router')) {
return 'react-vendor';
}
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This condition matches 'react-router' but the chunk name 'react-vendor' suggests it's only for React core libraries. Since react-router is routing-related rather than core React, consider creating a separate 'router-vendor' chunk for clarity and better cache granularity.

Suggested change
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom') || id.includes('node_modules/react-router')) {
return 'react-vendor';
}
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom')) {
return 'react-vendor';
}
if (id.includes('node_modules/react-router')) {
return 'router-vendor';
}

Copilot uses AI. Check for mistakes.
return 'react-three';
}
// Separate vendor chunks for better caching
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom') || id.includes('node_modules/react-router')) {
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition id.includes('node_modules/react') will incorrectly match packages like 'node_modules/react-hook-form' and 'node_modules/@react-three/', causing them to be bundled into 'react-vendor' instead of their intended chunks. Use more specific patterns like id.includes('node_modules/react/') or check for exact package boundaries.

Suggested change
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom') || id.includes('node_modules/react-router')) {
if (
id.includes('node_modules/react/') ||
id.includes('node_modules/react-dom/') ||
id.includes('node_modules/react-router/')
) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments