Skip to content

feat: lazy load things which are low-risk from main#2386

Open
bajrangCoder wants to merge 3 commits into
mainfrom
lazy-load-things
Open

feat: lazy load things which are low-risk from main#2386
bajrangCoder wants to merge 3 commits into
mainfrom
lazy-load-things

Conversation

@bajrangCoder

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR reduces the initial bundle size by converting ~20 eagerly-loaded modules to dynamic import() calls, gated behind the user actions that actually need them. Three new helper modules (lazyImports.js, registerPrettierFormatter.js, connectionState.js) are introduced to support the lazy-loading strategy without duplicating chunk-name boilerplate.

  • Lazy-loaded on demand: terminal, prettier formatter, welcome page, command palette, file browser, color dialog, plugin/settings pages, purchase handler, and more — all now fetched only when the relevant command or code path is first triggered.
  • connectionState.js extracts two lightweight LSP utilities from the heavy lspInfoDialog module so main.js can import only what it needs at startup.
  • registerPrettierFormatter.js splits registration metadata from the full prettier implementation, keeping the large prettier bundle out of the critical path until formatting is first invoked.

Confidence Score: 5/5

Safe to merge; all lazy-loading changes are behind user-triggered code paths and the refactored helper modules are straightforward extractions with no logic changes.

The change is a mechanical conversion of eager imports to dynamic import() calls. Every converted path is behind a user action so there is no risk of breaking the initial render. The three new helper modules are clean extractions of existing logic. The one gap — showTutorials swallowing a potential async failure silently — is non-critical because the tutorial is purely informational.

src/main.js — specifically the showTutorials function which lacks error handling for its async imports, unlike the terminal lazy-load added in the same file.

Important Files Changed

Filename Overview
src/main.js Core startup file: converts several eager imports (terminal, welcome, plugins, tutorial, appSettings, checkPluginsUpdate) to dynamic imports; showTutorials is now async but its returned Promise is unhandled when called via setTimeout
src/lib/commands.js Converts ~15 command handlers to async with dynamic imports; uses shared loadFileBrowser helper from lazyImports.js; changes look correct and consistent
src/lib/lazyImports.js New shared helper that wraps the FileBrowser dynamic import with a consistent chunk name; correctly replaces duplicated inline loaders
src/lib/registerPrettierFormatter.js New module that registers the prettier formatter with a lazy-loading callback so the full prettier bundle is only fetched when formatting is first invoked; clean separation from formatter implementation
src/cm/lsp/connectionState.js New lightweight utility module that extracts getServersForCurrentFile and hasConnectedServers from lspInfoDialog, letting main.js avoid eagerly loading the full dialog
src/lib/prettierFormatter.js Removes the registration logic and constants (now in registerPrettierFormatter.js); exports formatActiveFileWithPrettier for lazy invocation; old registerPrettierFormatter export removed but no callers remain
src/lib/openFolder.js Replaces eager FileBrowser and TerminalManager imports with lazy dynamic imports using shared loadFileBrowser helper; logic unchanged
src/components/lspInfoDialog/index.js Removes the three utility functions now living in connectionState.js; imports them back for re-export in the existing hasConnectedServers public API; clean refactor
src/lib/acode.js Lazy-loads purchaseListener and formatterSettings at their actual usage sites; both are behind conditional paths that are rarely hit, making lazy loading appropriate here
src/pages/welcome/welcome.js Removes welcome.scss import (now eagerly loaded in main.js to keep styles in the shadow-DOM-linked bundle); no logic changes

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[App Start / main.js] --> B[Eager: core editor, settings, LSP connectionState]
    A --> C[Lazy on first use]
    C --> D[welcome chunk\npages/welcome]
    C --> E[terminal chunk\ncomponents/terminal]
    C --> F[prettierFormatter chunk\nlib/prettierFormatter]
    C --> G[fileBrowser chunk\npages/fileBrowser]
    C --> H[checkPluginsUpdate chunk\nlib/checkPluginsUpdate]
    C --> I[tutorial + appSettings chunks\nshowTutorials]
    B --> J[commands.js async handlers]
    J --> K[commandPalette / changeMode / changeTheme / changeEncoding]
    J --> L[problems / plugins / about / mainSettings / helpSettings]
    J --> M[fileBrowser via lazyImports.js]
    J --> N[color dialog / browser plugin]
    B --> O[registerPrettierFormatter.js]
    O --> |on format invoke| F
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[App Start / main.js] --> B[Eager: core editor, settings, LSP connectionState]
    A --> C[Lazy on first use]
    C --> D[welcome chunk\npages/welcome]
    C --> E[terminal chunk\ncomponents/terminal]
    C --> F[prettierFormatter chunk\nlib/prettierFormatter]
    C --> G[fileBrowser chunk\npages/fileBrowser]
    C --> H[checkPluginsUpdate chunk\nlib/checkPluginsUpdate]
    C --> I[tutorial + appSettings chunks\nshowTutorials]
    B --> J[commands.js async handlers]
    J --> K[commandPalette / changeMode / changeTheme / changeEncoding]
    J --> L[problems / plugins / about / mainSettings / helpSettings]
    J --> M[fileBrowser via lazyImports.js]
    J --> N[color dialog / browser plugin]
    B --> O[registerPrettierFormatter.js]
    O --> |on format invoke| F
Loading

Reviews (2): Last reviewed commit: "fix" | Re-trigger Greptile

Comment thread src/lib/commands.js
Comment thread src/main.js
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder bajrangCoder requested a review from deadlyjack June 25, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant