nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Load the VS Code websocket server (ws) only when --vscode is used

Open addyCooks opened this issue 1 month ago • 1 comments

Summary

App.tsx imports useVSCodeServer, which imports the whole vscode module graph and the ws package. The server only starts when --vscode is passed, but the modules load on every start.

Steps to reproduce

  1. pnpm run build
  2. From the repo root run:
node --input-type=module -e "
import {registerHooks} from 'node:module';
const seen = new Set();
registerHooks({load(url, ctx, next) { seen.add(url); return next(url, ctx); }});
await import('ink');
await import('./dist/app/index.js');
console.log('ws modules:', [...seen].filter(u => /node_modules\/ws\//.test(u)).length);"

Expected behaviour

ws is not loaded unless the VS Code mode is enabled.

Actual behaviour

ws modules: 14

Import chain: app/App.js -> hooks/useVSCodeServer.js -> vscode/index.js -> vscode/vscode-server.js -> ws. Blocking the dist/vscode/ subtree removes 19 modules from the startup graph.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node: 22.22.3
  • Nanocoder: 1.31.0 (main at be428fc7)

Suggested fix

  • source/hooks/useVSCodeServer.tsx:3: replace the static import {getVSCodeServer, VSCodeServer} from '@/vscode/index' with a dynamic import() inside the effect that already runs only when enabled is true (line 97). Keep the hook call unconditional.
  • source/vscode/vscode-server.ts:7 imports ws; keeping it inside the lazily loaded module is enough.
  • Tests: source/hooks/useVSCodeServer.spec.tsx.

addyCooks avatar Oct 18 '26 06:10 addyCooks

if no one is working on this would be happy to take this on @addyCooks

Vishesh-Verma-07 avatar Oct 18 '26 06:10 Vishesh-Verma-07