Skip to content

Comments

perf: implement route-based code splitting with React.lazy()#263

Open
jmanhype wants to merge 1 commit intoautomagik-dev:devfrom
jmanhype:claude/lazy-load-routes-01Doej4GyPh4ZVfKhQhXDsiD
Open

perf: implement route-based code splitting with React.lazy()#263
jmanhype wants to merge 1 commit intoautomagik-dev:devfrom
jmanhype:claude/lazy-load-routes-01Doej4GyPh4ZVfKhQhXDsiD

Conversation

@jmanhype
Copy link

Lazy load Settings, ReleaseNotes, and FullLogs pages to reduce initial bundle size. Each lazy-loaded route is wrapped in Suspense with a consistent loading fallback component.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jmanhype, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the application's initial loading performance by introducing route-based code splitting. By lazy-loading less frequently accessed pages such as the various settings sections, release notes, and full attempt logs, the initial JavaScript bundle size is reduced, leading to faster load times for users. A consistent loading indicator is displayed while these components are being fetched, ensuring a smooth user experience.

Highlights

  • Route-based Code Splitting: Implemented React.lazy() for several key routes to enable route-based code splitting, significantly reducing the initial bundle size.
  • Lazy-Loaded Pages: The Settings pages (General, Project, Agent, MCP), ReleaseNotes, and FullAttemptLogsPage are now dynamically imported and lazy-loaded only when accessed.
  • Consistent Loading Fallback: A new RouteLoadingFallback component has been introduced and integrated with Suspense to provide a uniform and user-friendly loading experience for all lazy-loaded routes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively implements route-based code splitting using React.lazy() and Suspense, which is a great performance improvement for the application's initial load time. The implementation is correct and covers all the intended routes. My only feedback is a suggestion to reduce some code repetition in the route definitions for better long-term maintainability. Overall, this is a solid contribution.

Comment on lines 302 to 343
<Route
path="/settings/*"
element={
<Suspense fallback={<RouteLoadingFallback />}>
<SettingsLayout />
</Suspense>
}
>
<Route index element={<Navigate to="general" replace />} />
<Route path="general" element={<GeneralSettings />} />
<Route path="projects" element={<ProjectSettings />} />
<Route path="agents" element={<AgentSettings />} />
<Route path="mcp" element={<McpSettings />} />
<Route
path="general"
element={
<Suspense fallback={<RouteLoadingFallback />}>
<GeneralSettings />
</Suspense>
}
/>
<Route
path="projects"
element={
<Suspense fallback={<RouteLoadingFallback />}>
<ProjectSettings />
</Suspense>
}
/>
<Route
path="agents"
element={
<Suspense fallback={<RouteLoadingFallback />}>
<AgentSettings />
</Suspense>
}
/>
<Route
path="mcp"
element={
<Suspense fallback={<RouteLoadingFallback />}>
<McpSettings />
</Suspense>
}
/>
</Route>
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While this correctly implements lazy loading for each settings page, there's significant repetition with the <Suspense> wrapper for each nested route. This can make the routing configuration harder to read and maintain.

A more maintainable pattern would be to centralize the Suspense boundary. Ideally, this would be inside the SettingsLayout component, wrapping the <Outlet />. This would handle the loading state for all nested settings pages automatically.

Since SettingsLayout.tsx isn't modified in this PR, a good alternative is to create a small wrapper component within App.tsx to reduce this boilerplate.

For example, you could define a wrapper:

const Suspended = ({ children }: { children: React.ReactNode }) => (
  <Suspense fallback={<RouteLoadingFallback />}>
    {children}
  </Suspense>
);

And then use it like this:

<Route path="general" element={<Suspended><GeneralSettings /></Suspended>} />
<Route path="projects" element={<Suspended><ProjectSettings /></Suspended>} />
// ... and so on

This would make the route definitions cleaner and less repetitive.

Lazy load Settings, ReleaseNotes, and FullLogs pages to reduce initial
bundle size. Each lazy-loaded route is wrapped in Suspense with a
consistent loading fallback component.

Co-authored-by: Automagik Genie 🧞 <genie@namastex.ai>
@namastex888
Copy link
Contributor

@codex review this pr

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import { ClickedElementsProvider } from '@/contexts/ClickedElementsProvider';
import { GenieMasterWidget } from '@/components/genie-widgets/GenieMasterWidget';
import { SubGenieProvider } from '@/context/SubGenieContext';
import { SubGenieProvider } from '@/contexts/SubGenieContext';

Choose a reason for hiding this comment

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

P1 Badge Restore SubGenieProvider import to existing context path

The new import points to @/contexts/SubGenieContext, but the provider lives in frontend/src/context/SubGenieContext.tsx (singular directory). There is no contexts/SubGenieContext module, so any build or test that includes App.tsx will now fail with a module-not-found error, preventing the app from compiling.

Useful? React with 👍 / 👎.

@jmanhype
Copy link
Author

@codex review this pr

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import { ClickedElementsProvider } from '@/contexts/ClickedElementsProvider';
import { GenieMasterWidget } from '@/components/genie-widgets/GenieMasterWidget';
import { SubGenieProvider } from '@/context/SubGenieContext';
import { SubGenieProvider } from '@/contexts/SubGenieContext';

Choose a reason for hiding this comment

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

P1 Badge Fix SubGenieProvider import path

The commit changes the SubGenie provider import to @/contexts/SubGenieContext, but the only implementation lives at frontend/src/context/SubGenieContext.tsx (singular). With no matching file under contexts/, the build will fail with a module resolution error before the app can start, blocking any route rendering. Point the import back to the existing context path to restore compilation.

Useful? React with 👍 / 👎.

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.

3 participants