Skip to content

Perf/lazy load heavy libs - #242

Merged
itsmeakhil merged 2 commits into
mainfrom
perf/lazy-load-heavy-libs
Jul 6, 2026
Merged

Perf/lazy load heavy libs#242
itsmeakhil merged 2 commits into
mainfrom
perf/lazy-load-heavy-libs

Conversation

@itsmeakhil

Copy link
Copy Markdown
Collaborator

No description provided.

itsmeakhil and others added 2 commits July 4, 2026 00:37
Defer ~1.3MB of tool-specific JS off route-initial bundles by loading
heavy libraries on first use instead of statically:

- svgo (525KB): dynamic import in svg-optimize.ts, loads on first optimize
- sql-formatter (278KB): dynamic import in sql-formatter-layout
- vanilla-jsoneditor (485KB): JSONEditor dynamic-imported on mount in
  vanilla-editor; json-formatter-layout's Mode/toTextContent made
  type-only so the editor barrel is no longer dragged into the route
  chunk. toTextContent reimplemented locally (compact JSON, matches
  upstream default — verified against vanilla-jsoneditor across 10 cases).

Also:
- Delete dead exportUtils.ts (orphaned; only static xlsx import in repo;
  live consumers already lazy-load xlsx).
- Pin Node floor: engines.node >=20.19.0 + .nvmrc=22. Below 20.19,
  undici in /api/proxy-ntlm breaks the build (markAsUncloneable).
- Fix analyze script: next build --webpack (@next/bundle-analyzer is a
  no-op under Next 16's default Turbopack).

Verified: Turbopack prod build green (86 routes), tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
svg-optimizer runs on every (debounced) keystroke; on large documents
svgo's parse/optimize blocked the main thread and janked typing. Move it
off-thread, mirroring the existing bcrypt/mock-data worker pattern:

- svg-optimize.worker.ts + use-svg-optimize-worker.ts (id-keyed
  request/response, lazy worker, reject in-flight on unmount/error,
  main-thread fallback).
- shouldUseSvgWorker gates on SVG_WORKER_MIN_CHARS (15k) — below that,
  main-thread optimize beats the worker round-trip + svgo chunk load.
- svg-optimizer-layout calls the hook instead of optimizeSvgMarkup
  directly; svgo now loads inside the worker, never on the main thread
  (fallback aside).

Verified: Turbopack prod build green (worker chunk emitted), tsc clean,
svgo optimize contract checked (strips comments, shrinks output).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mydevtools-tech Ready Ready Preview, Comment Jul 6, 2026 9:31am

@itsmeakhil
itsmeakhil merged commit c10f1de into main Jul 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant