Skip to content

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

Merged
deadlyjack merged 11 commits into
mainfrom
lazy-load-things
Jun 27, 2026
Merged

feat: lazy load things which are low-risk from main#2386
deadlyjack merged 11 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 lazy-loads a large number of previously eager modules from main.js and commands.js (terminal, file browser, palettes, plugins page, purchase handler, prettier formatter, etc.) to reduce the initial bundle size and startup time. It also refactors the LSP logging system from a global console monkey-patch into a first-class cm/lsp/logs module with explicit instrumentation at each log site.

  • Lazy-loading: Dynamic import() calls with explicit webpackChunkName annotations are introduced for ~15 modules; a new lib/lazyImports.js centralises the repeated FileBrowser loader.
  • LSP logging: The old lspInfoDialog console-interception approach (patching console.info/warn/error) is replaced by a dedicated cm/lsp/logs.ts module; all existing [LSP:] console call sites are explicitly instrumented with addLspLog/addLspLogFor.
  • Misc fixes: isfilesRestored guards prevent premature save-state calls during file restoration; dotfile keywords (e.g. .gitignore) are now correctly resolved in language mode recommendations; the quicktools toggler correctly starts hidden.

Confidence Score: 5/5

Safe to merge — the lazy-loading changes are well-isolated behind dynamic imports, the LSP log migration is comprehensive, and no regressions were identified.

All dynamic imports are guarded with proper chunk names. The isfilesRestored session-storage key is set in a finally block, so the save-state guard in onEditorUpdate is reliable. The LSP log migration from console-patching to explicit addLspLog calls covers every [LSP:] console call site in the codebase. The openFolder ordering change (folder.listFiles set before emits) is an improvement. No functional regressions found.

No files require special attention.

Important Files Changed

Filename Overview
src/main.js Lazy-loads terminal, welcome tab, plugins page, tutorial, and appSettings; adds isfilesRestored guard around save-state in onEditorUpdate; moves registerPrettierFormatter import to the new lightweight module.
src/lib/commands.js Converts ~12 eager imports to dynamic imports; introduces loadFileBrowser from lazyImports.js for shared chunk naming.
src/cm/lsp/logs.ts New module providing a typed, bounded log store (max 200 entries per server) with ANSI stripping, message normalisation, ignore patterns, and a pub/sub listener API.
src/cm/lsp/connectionState.js New lightweight module extracted from lspInfoDialog to expose getCurrentFileLanguage, getServersForCurrentFile, and hasConnectedServers without pulling in the heavy dialog.
src/components/lspInfoDialog/index.js Removes ~130 lines of console monkey-patching and local log storage; now imports from cm/lsp/logs and cm/lsp/connectionState; re-exports addLspLog/getLspLogs for backward compatibility.
src/lib/registerPrettierFormatter.js New file that holds the formatter registration logic; the format callback now lazily imports prettierFormatter, keeping the full prettier bundle out of the main bundle.
src/lib/prettierFormatter.js Removes registerPrettierFormatter and SUPPORTED_EXTENSIONS; exports formatActiveFileWithPrettier for dynamic import by the new registration shim.
src/lib/openFolder.js Removes eager FileBrowser and TerminalManager imports; folder.listFiles and addedFolder.push now happen before emit calls (a correct ordering improvement); FileList.addRoot properly catches errors.
src/lib/languageModeRecommendations.js Fixes dotfile keyword extraction (e.g. .gitignore → 'gitignore') and exports the function for use in tests.
src/cm/lsp/runtimes/builtinAlpine.ts canHandle short-circuits to true for any runtimeAction+launcher combination, routing install/uninstall checks through Alpine rather than the external WebSocket provider.
src/pages/welcome/welcome.js Replaces the heavy Logo component with an inlined PNG via ?inline query, removing the pseudo-element animation and simplifying the welcome header.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[App Start / main.js] --> B[Eager: core layout, settings, editorManager]
    A --> C[Eager: cm/lsp/connectionState\nhasConnectedServers]
    A --> D[Eager: lib/registerPrettierFormatter\nlightweight shim only]

    B --> E{User action}

    E -->|Open file browser| F[lazy: pages/fileBrowser\nwebpackChunkName: fileBrowser]
    E -->|Open terminal| G[lazy: components/terminal\nwebpackChunkName: terminal]
    E -->|Command palette| H[lazy: palettes/commandPalette]
    E -->|Settings| I[lazy: settings/mainSettings]
    E -->|Welcome tab| J[lazy: pages/welcome\nwebpackChunkName: welcome]
    E -->|Format file| K[lazy: lib/prettierFormatter\nfull prettier bundle]
    E -->|Run tests| L[lazy: test/tester]

    D -->|formatter callback| K

    subgraph LSP Logging
        M[cm/lsp/logs.ts\nlogsByServer Map\nlisteners Set]
        N[clientManager.ts] -->|addLspLog| M
        O[serverLauncher.ts] -->|addLspLog| M
        P[transport.ts] -->|addLspLog| M
        Q[workspace.ts] -->|addLspLogFor| M
        R[codeActions.ts] -->|addLspLogFor| M
        S[rename.ts] -->|addLspLogFor| M
        M -->|onLspLog| T[lspInfoDialog\nlazy UI consumer]
    end
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 layout, settings, editorManager]
    A --> C[Eager: cm/lsp/connectionState\nhasConnectedServers]
    A --> D[Eager: lib/registerPrettierFormatter\nlightweight shim only]

    B --> E{User action}

    E -->|Open file browser| F[lazy: pages/fileBrowser\nwebpackChunkName: fileBrowser]
    E -->|Open terminal| G[lazy: components/terminal\nwebpackChunkName: terminal]
    E -->|Command palette| H[lazy: palettes/commandPalette]
    E -->|Settings| I[lazy: settings/mainSettings]
    E -->|Welcome tab| J[lazy: pages/welcome\nwebpackChunkName: welcome]
    E -->|Format file| K[lazy: lib/prettierFormatter\nfull prettier bundle]
    E -->|Run tests| L[lazy: test/tester]

    D -->|formatter callback| K

    subgraph LSP Logging
        M[cm/lsp/logs.ts\nlogsByServer Map\nlisteners Set]
        N[clientManager.ts] -->|addLspLog| M
        O[serverLauncher.ts] -->|addLspLog| M
        P[transport.ts] -->|addLspLog| M
        Q[workspace.ts] -->|addLspLogFor| M
        R[codeActions.ts] -->|addLspLogFor| M
        S[rename.ts] -->|addLspLogFor| M
        M -->|onLspLog| T[lspInfoDialog\nlazy UI consumer]
    end
Loading

Reviews (6): Last reviewed commit: "fix: greptile review (#2401)" | 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.

@deadlyjack

This comment was marked as outdated.

Co-authored-by: Ajit Kumar <dellevenjack@gmail>
@bajrangCoder

This comment was marked as outdated.

@deadlyjack deadlyjack merged commit 6a52900 into main Jun 27, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Jun 27, 2026
@deadlyjack deadlyjack deleted the lazy-load-things branch June 27, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants