nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] `clipboardy` (and its `execa`/`semver` chain) is loaded at startup only for a copy button in the model database view

Open addyCooks opened this issue 1 month ago • 2 comments

Description

ModelDatabaseDisplay is imported statically by the modal selectors, and source/commands/model-database.tsx imports clipboardy at the top only for a copy action. clipboardy pulls in execa (113 modules), get-stream, human-signals and, through clipboard-image -> run-jxa -> macos-version, semver (46 modules), even on Linux and Windows.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 5c2e6935)

Steps to Reproduce

  1. Build, then register a module.registerHooks load hook that counts loaded files.
  2. Import dist/app/index.js and list the modules under node_modules/execa and node_modules/semver.
  3. Follow the import chain from App.js.

Evidence

  • Chain: app/App.js -> app/sections/interactive-app.js -> app/components/modal-selectors.js -> commands/model-database.js -> clipboardy/index.js -> clipboard-image -> run-jxa -> macos-version -> semver/index.js (source/app/components/modal-selectors.tsx:2, source/commands/model-database.tsx:1).
  • Blocking the edges into clipboardy and execa in the startup import graph removes 232 of 1,459 modules (16%).
  • clipboardy is also used by source/commands/copy.ts and commit.ts, but those are lazy commands, so only model-database matters.

Proposed Change

  • In source/commands/model-database.tsx, replace the top-level import with const {default: clipboard} = await import('clipboardy') inside the copy handler.
  • Optionally lazy-load the component itself from modal-selectors.tsx, the way lazy-registry.ts does for commands.

Expected Behavior

  • The startup module list contains no execa, semver or clipboardy.
  • Copying from the model database view still works.
  • pnpm run test:all passes.

Additional Context

  • Effort: S. Start with source/commands/model-database.tsx and source/app/components/modal-selectors.tsx.
  • Estimated saving: about 0.6-0.9 s on the test host (about 2.5-4 ms per module, mostly file-system calls); far less on a fast SSD with a warm cache. Confidence high on the module count, medium on the time.
  • Risk: the first copy pays the import once. Specs: modal-selectors.spec.tsx, model-database.spec.tsx.

addyCooks avatar Oct 15 '26 15:10 addyCooks

hi @addyCooks can i take this one..

Vishesh-Verma-07 avatar Oct 15 '26 17:10 Vishesh-Verma-07

Go for it @Vishesh-Verma-07 !

addyCooks avatar Oct 16 '26 06:10 addyCooks