Skip to content

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

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

feat: lazy load things which are low-risk from main#2386
bajrangCoder wants to merge 9 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 numerous eagerly-loaded modules (terminal, file browser, palettes, plugins, welcome page, prettier) into dynamic import() chunks, and it refactors the LSP logging subsystem away from console monkey-patching into a dedicated logs.ts module with explicit addLspLog call-sites.

  • Lazy loading: ~15 modules in commands.js, main.js, openFolder.js, and acode.js are now split into named webpack chunks loaded on first use; a new lazyImports.js centralises the FileBrowser loader.
  • LSP logging refactor: lspInfoDialog no longer monkey-patches console.*; log capture is now explicit via addLspLog in clientManager, serverLauncher, and transport; connection-state helpers are extracted to connectionState.js.
  • openFolder fix: the async IIFE is removed; addedFolder.push and folder.listFiles now execute synchronously before the add-folder events fire, so event handlers can reliably query addedFolder.

Confidence Score: 5/5

Safe to merge; changes are well-scoped lazy-loading refactors and a cleaner LSP logging architecture with no impact on core editor behaviour.

All lazy-load conversions are straightforward dynamic imports with existing fallback patterns. The LSP logging refactor replaces fragile console monkey-patching with explicit call-sites and is fully backward-compatible. The openFolder ordering fix is strictly better. The only concrete issue found is a CSS @supports scope leak in welcome.scss that only materialises on browsers lacking gap support — not a concern for Acode's Android WebView target.

src/pages/welcome/welcome.scss — @supports not (gap: 1px) block now at top level instead of inside #welcome-tab.

Important Files Changed

Filename Overview
src/main.js Eagerly-loaded modules (terminal, plugins, tutorial, appSettings, checkPluginsUpdate, welcome) converted to dynamic imports; hasConnectedServers import moved from lspInfoDialog to the new connectionState module; save-state is now called explicitly after file restoration, with onFileUpdate guarded by the isfilesRestored sessionStorage flag to avoid writes during the restore phase.
src/lib/commands.js All heavy UI modules (commandPalette, fileBrowser, themes, about, plugins, terminal, browser, color dialog, etc.) are now dynamically imported on first use, with a shared loadFileBrowser helper from lazyImports.js.
src/lib/openFolder.js Async IIFE removed; folder.listFiles and addedFolder.push now happen synchronously before the add-folder events fire (correct ordering), and FileList.addRoot errors are explicitly caught and logged. TerminalManager import is now lazy.
src/cm/lsp/logs.ts New module providing structured in-memory LSP log storage (MAX_LOGS=200), ANSI stripping, pattern filtering, and a listener/unsubscribe API; replaces the console monkey-patching that was previously in lspInfoDialog.
src/cm/lsp/connectionState.js New standalone module that extracts getCurrentFileLanguage, getServersForCurrentFile, and hasConnectedServers from lspInfoDialog so main.js can import them without pulling in the heavy dialog code.
src/lib/registerPrettierFormatter.js New module containing registerPrettierFormatter; the actual formatter callback is now a dynamic import of prettierFormatter.js so the Prettier bundle is only fetched on first format action.
src/pages/welcome/welcome.scss Indentation refactored from 4-space nested to 2-space flat; @supports not (gap: 1px) block moved outside #welcome-tab, causing its selectors to lose the parent-element scope (affects legacy browsers only).
src/lib/lazyImports.js New shared helper that lazy-loads FileBrowser with a consistent chunk name, removing the duplicate loader boilerplate across commands.js and openFolder.js.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[App Boot / main.js] --> B[Eager: core editor, settings, sidebar]
    A --> C{files restored?}
    C -->|no files| D["lazy: pages/welcome ⟶ openWelcomeTab()"]
    C -->|has files| E[restoreFiles]
    E --> F[sessionStorage: isfilesRestored=true]
    F --> G[acode.exec save-state]
    G --> H[initFileList]
    H --> I["lazy: components/terminal ⟶ restorePersistedSessions()"]

    A --> J[User action]
    J --> K{command?}
    K -->|files / open-file / open-folder| L["lazy: pages/fileBrowser (shared chunk)"]
    K -->|command-palette / find-file| M["lazy: palettes/*"]
    K -->|syntax / change-theme| N["lazy: palettes/changeMode / changeTheme"]
    K -->|new-terminal| O["lazy: components/terminal"]
    K -->|open settings/help/plugins/about| P["lazy: settings/* / pages/*"]
    K -->|open-inapp-browser| Q["lazy: plugins/browser"]
    K -->|format| R["lazy: lib/prettierFormatter via registerPrettierFormatter"]

    style D fill:#e8f5e9
    style L fill:#e8f5e9
    style M fill:#e8f5e9
    style N fill:#e8f5e9
    style O fill:#e8f5e9
    style P fill:#e8f5e9
    style Q fill:#e8f5e9
    style R fill:#e8f5e9
    style I fill:#e8f5e9
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 Boot / main.js] --> B[Eager: core editor, settings, sidebar]
    A --> C{files restored?}
    C -->|no files| D["lazy: pages/welcome ⟶ openWelcomeTab()"]
    C -->|has files| E[restoreFiles]
    E --> F[sessionStorage: isfilesRestored=true]
    F --> G[acode.exec save-state]
    G --> H[initFileList]
    H --> I["lazy: components/terminal ⟶ restorePersistedSessions()"]

    A --> J[User action]
    J --> K{command?}
    K -->|files / open-file / open-folder| L["lazy: pages/fileBrowser (shared chunk)"]
    K -->|command-palette / find-file| M["lazy: palettes/*"]
    K -->|syntax / change-theme| N["lazy: palettes/changeMode / changeTheme"]
    K -->|new-terminal| O["lazy: components/terminal"]
    K -->|open settings/help/plugins/about| P["lazy: settings/* / pages/*"]
    K -->|open-inapp-browser| Q["lazy: plugins/browser"]
    K -->|format| R["lazy: lib/prettierFormatter via registerPrettierFormatter"]

    style D fill:#e8f5e9
    style L fill:#e8f5e9
    style M fill:#e8f5e9
    style N fill:#e8f5e9
    style O fill:#e8f5e9
    style P fill:#e8f5e9
    style Q fill:#e8f5e9
    style R fill:#e8f5e9
    style I fill:#e8f5e9
Loading

Reviews (4): Last reviewed commit: "improved lsp logs and fix lsp settings" | 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
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

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.

2 participants