nanocoder
nanocoder copied to clipboard
[Feature] Lazy-load the welcome banner libraries (cfonts, gradient-string) instead of at startup
Summary
The welcome banner uses ink-big-text (which loads cfonts) and ink-gradient (which loads gradient-string, tinygradient, tinycolor2). They are imported at the top of welcome-message.tsx, so about 30 modules load on every start before the first frame, even though the banner only draws a short text.
Steps to reproduce
pnpm run build- 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');
const count = re => [...seen].filter(u => re.test(u)).length;
console.log('total modules:', seen.size);
console.log('banner:', count(/node_modules\/(cfonts|ink-big-text|ink-gradient|gradient-string)\//));"
Expected behaviour
The banner libraries load only when the banner is first drawn, or after the first frame, not as part of the app import.
Actual behaviour
total modules: 1504
banner: 29
Blocking the edges into ink-big-text, cfonts, ink-gradient, gradient-string, tinygradient and tinycolor2 removes 44 of 1,478 modules from the startup import graph.
Environment
- OS: Windows 11 (10.0.26300)
- Node: 22.22.3
- Nanocoder: 1.31.0 (main at be428fc7)
Suggested fix
source/components/welcome-message.tsx:2-3(imports) and:222-224(<Gradient><BigText .../></Gradient>).- Load the two packages with a dynamic
import()after the first frame (for example in an effect), and show the plain title until they arrive. - Note: the font is a user preference with 12 shapes (
NanocoderShapeinsource/types/ui.ts), so pre-rendering every shape into constants is not a simple option. - Tests:
source/components/welcome-message.spec.tsx; check a narrow and a wide terminal.
@addyCooks would like to work on this