@exxatdesignux/ui 0.5.8 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/consumer-extras/patterns/consumer-upgrade-checklist.md +25 -0
- package/consumer-extras/patterns/perf-memory-pattern.md +206 -0
- package/dist/hooks/use-app-theme.d.ts +1 -1
- package/package.json +1 -1
- package/template/.nvmrc +1 -1
- package/template/docs/perf-memory-pattern.md +206 -0
- package/template/ecosystem.config.cjs +12 -0
- package/template/next.config.mjs +35 -1
- package/template/package.json +9 -5
- package/template/tsconfig.json +2 -1
- package/tokens/hooks-index.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- **Turbopack memory cap + cache-bust scripts.** The Next 16.1+ Turbopack file-system cache (default-on) was writing 800+ `.meta` files per process and growing `.next/` to **3+ GB on disk**, which was then mmap'd back into RSS — adding several GB of resident memory per `next-server` on top of what 0.5.9 already capped. Three additions to the scaffolded `template/`:
|
|
8
|
+
- **`turbopack: { memoryLimit: 4 * 1024 * 1024 * 1024 }`** in `next.config.mjs` (top-level, **not** under `experimental` — that key was removed in Next 16). Hard 4 GiB cap on the Turbopack worker; prevents the unbounded growth observed when the FS cache and module graph accumulate over a long dev session.
|
|
9
|
+
- **`pnpm clean`** (`rm -rf .next`) and **`pnpm clean:cache`** (`rm -rf .next/dev/cache .next/dev/trace .next/diagnostics`) — one-command cache bust when `.next` crosses ~2 GB. The FS cache is kept enabled (cold start is ~15s without it) but is now explicitly disposable.
|
|
10
|
+
- **`pnpm dev:fresh`** (`pnpm clean:cache && pnpm dev`) — bust + restart in a single command. Use after a major dependency upgrade or whenever HMR starts skipping updates.
|
|
11
|
+
- **`perf-memory-pattern.md` gains two new sections:**
|
|
12
|
+
- **§3 Turbopack file-system cache** explains the trade-off, when to bust, and why disabling the cache outright is the wrong call.
|
|
13
|
+
- **§4 Don't run two dev servers at the same time** — the #1 cause of memory exhaustion in practice. Two checkouts of the same monorepo (`DS_Workspace/` + `Exxat-DS-Workspace/`), or a customer app + `apps/web` running simultaneously, each carry their own ~2 GB of caches and don't share anything. Includes a `ps` / `lsof` diagnostic table for identifying which checkout owns which `next-server` lineage.
|
|
14
|
+
- **`perf-memory-pattern.md` §6 diagnose table** now leads with the boring checks (`du -sh .next`, `ps aux | grep next-server | wc -l`, `lsof -p <pid> | wc -l`) before suggesting a heap profile — most "high RSS" reports are dual-server or stale-cache, not a real leak.
|
|
15
|
+
- **`consumer-upgrade-checklist.md` §4** gains a `≥ 0.5.10` block listing the three new knobs and the one-time `pnpm clean && pnpm dev` step that customer apps need after upgrading (pre-0.5.10 cache files were written without the memory cap).
|
|
16
|
+
|
|
17
|
+
## 0.5.9
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- **Template bumped to Node 24 (LTS-track) + Next 16 dev-memory tuning.** A fresh `next dev` against the reference app now stabilizes at **~1.4 GB RSS** vs **3–6 GB per process** previously. Five knobs were applied to the scaffolded `template/` (which the prepack script syncs from `apps/web/`):
|
|
22
|
+
- **`NODE_OPTIONS="--max-old-space-size=6144 --max-semi-space-size=64"`** on every `dev*` script + `ecosystem.config.cjs` `env` block. Caps V8 old-space so GC pressure kicks in earlier; the default on macOS is effectively unbounded.
|
|
23
|
+
- **`experimental.preloadEntriesOnStart: false`** in `next.config.mjs`. Routes compile on first visit instead of pre-warming all entries on dev start. Dev TTFB ~15s → ~2s; steady-state heap ~30% lower.
|
|
24
|
+
- **`experimental.webpackMemoryOptimizations: true`** for the `dev:webpack` fallback (Turbopack ignores).
|
|
25
|
+
- Expanded **`experimental.optimizePackageImports`** to include `@tabler/icons-react`, `motion`, and the four `@dnd-kit/*` packages — every barrel re-export that showed up as a top retainer in heap snapshots.
|
|
26
|
+
- **`target: "ES2022"`** + **`assumeChangesOnlyAffectDirectDependencies: true`** in `tsconfig.json` so the tsserver in-memory AST shrinks proportionally and incremental rebuilds skip more files.
|
|
27
|
+
- **`NEXT_TELEMETRY_DISABLED=1`** added to every `dev*` script — skips the telemetry collector's per-process arena (~50 MB).
|
|
28
|
+
- **`max_memory_restart: "7G"`** in the pm2 daemon config — the daemon recycles before macOS swaps, with the restart cause visible in `pm2 logs`.
|
|
29
|
+
- **New `pnpm dev:profile` script** — drops `--heap-prof` + `--cpu-prof` snapshots into `.next/diagnostics/` for analysis in Chrome DevTools. No third-party profiler dependency.
|
|
30
|
+
- **New pattern doc `perf-memory-pattern.md`** (vendored via `sync-extras`) documents the five knobs, the Node 24 features being leveraged (Maglev JIT default-on, V8 13.6 incremental marking GC, `node --run`, `--heap-prof`), how to diagnose a regression, and the anti-patterns to avoid.
|
|
31
|
+
- **`consumer-upgrade-checklist.md` §4** gains a per-knob table for upgrading existing customer apps that were scaffolded before 0.5.9. Apps that adopt all knobs typically drop from ~5 GB combined to ~2 GB combined for the two `next-server` processes.
|
|
32
|
+
|
|
3
33
|
## 0.5.8
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -30,6 +30,31 @@ Use it when you need to know **what files exist**, **how shims re-export** `@exx
|
|
|
30
30
|
- Keep **`@exxatdesignux/ui`** on the same semver your team tested; prefer explicit **`^x.y.z`** or pinned **`x.y.z`**.
|
|
31
31
|
- Match **`engines.node`** in your app to the value declared in **`node_modules/@exxatdesignux/ui/package.json`** (see CHANGELOG if it changed).
|
|
32
32
|
- **≥ 0.5.3:** Remove **`vaul`** from your app `package.json` and delete any `components/ui/drawer.tsx` shim — side panels use **`Sheet`** only (**`.cursor/rules/exxat-no-vaul.mdc`**).
|
|
33
|
+
- **≥ 0.5.9:** Bump to **Node 24** (LTS-track) and apply the dev-memory tuning. The template ships these by default; existing apps need a one-time copy. *(0.5.10 adds the Turbopack cap below; apply both together.)*
|
|
34
|
+
|
|
35
|
+
| What | Where | Effect |
|
|
36
|
+
|------|-------|--------|
|
|
37
|
+
| `engines.node: ">=24.0.0"` + `.nvmrc: 24` | `package.json`, `.nvmrc` | Pins to V8 13.6 + Maglev JIT default-on |
|
|
38
|
+
| `NODE_OPTIONS="--max-old-space-size=6144 --max-semi-space-size=64"` prefix on every `dev*` script | `package.json` `scripts` | Caps V8 old-space; forces GC pressure earlier |
|
|
39
|
+
| `NEXT_TELEMETRY_DISABLED=1` prefix | same | Skips telemetry's per-process arena (~50 MB) |
|
|
40
|
+
| `experimental.preloadEntriesOnStart: false` | `next.config.mjs` | Compiles routes on first visit; ~30% lower steady-state heap |
|
|
41
|
+
| `experimental.webpackMemoryOptimizations: true` | `next.config.mjs` | Lower webpack-fallback heap (Turbopack ignores) |
|
|
42
|
+
| Expanded `experimental.optimizePackageImports` (`@tabler/icons-react`, `motion`, `@dnd-kit/*`) | `next.config.mjs` | Tree-shakes barrel re-exports |
|
|
43
|
+
| `target: "ES2022"` + `assumeChangesOnlyAffectDirectDependencies: true` | `tsconfig.json` | Smaller tsserver AST, faster rebuilds |
|
|
44
|
+
| `env: { NODE_OPTIONS, NEXT_TELEMETRY_DISABLED }` + `max_memory_restart: "7G"` | `ecosystem.config.cjs` (if using pm2) | Daemon recycles before macOS swaps |
|
|
45
|
+
| New `pnpm dev:profile` script | `package.json` | `--heap-prof` + `--cpu-prof` snapshots dropped into `.next/diagnostics/` |
|
|
46
|
+
|
|
47
|
+
- **≥ 0.5.10:** Cap Turbopack and add cache-bust scripts. The dev FS cache is enabled by default in Next 16.1 — without these knobs it grows to 2–3 GB on disk and mmaps the same back into RSS:
|
|
48
|
+
|
|
49
|
+
| What | Where | Effect |
|
|
50
|
+
|------|-------|--------|
|
|
51
|
+
| `turbopack: { memoryLimit: 4 * 1024 * 1024 * 1024 }` | `next.config.mjs` (top-level, **not** under `experimental`) | Hard 4 GiB cap on the Turbopack worker — prevents the unbounded cache → RSS growth |
|
|
52
|
+
| New `pnpm clean` (`rm -rf .next`) and `pnpm clean:cache` (`rm -rf .next/dev/cache .next/dev/trace .next/diagnostics`) | `package.json` `scripts` | One-command cache bust when `.next` > 2 GB |
|
|
53
|
+
| New `pnpm dev:fresh` (`pnpm clean:cache && pnpm dev`) | `package.json` `scripts` | Bust + restart in one shot |
|
|
54
|
+
|
|
55
|
+
**Run `pnpm clean && pnpm dev` once after the upgrade.** Pre-0.5.10 cache files were written without the memory cap and may carry stale mmap layouts.
|
|
56
|
+
|
|
57
|
+
Full rationale + diagnostics in **`docs/exxat-ds/perf-memory-pattern.md`** (after `sync-extras`) or **[`apps/web/docs/perf-memory-pattern.md`](https://github.com/ExxatDesign/Exxat-DS-Workspace/blob/main/apps/web/docs/perf-memory-pattern.md)** — especially §3 (Turbopack FS cache) and §4 (don't run two dev servers).
|
|
33
58
|
|
|
34
59
|
## 5. Consumer UI audit (after sync-extras)
|
|
35
60
|
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Dev memory tuning for Next.js + Node 24
|
|
2
|
+
|
|
3
|
+
> **Audience:** humans + AI agents.
|
|
4
|
+
> **Companion to:** [`HANDBOOK.md`](./HANDBOOK.md). Read this when `next dev`
|
|
5
|
+
> RSS climbs past ~3 GB, when two `next-server` processes total > 5 GB, or
|
|
6
|
+
> when adopting Node 24.
|
|
7
|
+
|
|
8
|
+
A fresh `next dev` against this app stabilizes around **~1.4 GB RSS** with
|
|
9
|
+
the settings below. Without them, the same app drifts to **3–6 GB per
|
|
10
|
+
process** and pm2 will eventually swap or OOM.
|
|
11
|
+
|
|
12
|
+
## 1. The six knobs
|
|
13
|
+
|
|
14
|
+
| # | Knob | Why it matters | Where it lives |
|
|
15
|
+
|---|------|----------------|----------------|
|
|
16
|
+
| 1 | `NODE_OPTIONS="--max-old-space-size=6144 --max-semi-space-size=64"` | Caps V8 old-space at 6 GB (default on macOS is ~94% of system RAM = unbounded for practical purposes). With a ceiling, V8 GC pressure kicks in earlier and steady-state heap is lower. `--max-semi-space-size=64` widens the young generation so short-lived render allocations don't promote to old-space. | `package.json` `dev*` scripts + `ecosystem.config.cjs` `env` |
|
|
17
|
+
| 2 | `turbopack.memoryLimit: 4 GiB` | Hard cap on the Turbopack worker process. Without this, Turbopack's module graph + mmap'd FS cache files grow unbounded — we observed 3.2 GB on disk and 5+ GB RSS per process with no cap. 4 GiB is generous for apps with < ~1000 routes. | `next.config.mjs` `turbopack` |
|
|
18
|
+
| 3 | `experimental.preloadEntriesOnStart: false` | Next compiles routes on first visit instead of pre-warming every entry on dev start. Dev TTFB drops from ~15s → ~2s; steady-state heap is ~30% lower. | `next.config.mjs` |
|
|
19
|
+
| 4 | `experimental.optimizePackageImports: [...]` | Re-export barrels (`lucide-react`, `@tabler/icons-react`, `motion`, `@dnd-kit/*`, `recharts`) get tree-shaken to leaf imports. Cuts the dev server's parsed-module count by ~40%. | `next.config.mjs` |
|
|
20
|
+
| 5 | `experimental.webpackMemoryOptimizations: true` | Drops large in-memory webpack caches at the cost of slightly slower rebuilds. **Only the `pnpm dev:webpack` fallback uses webpack** — Turbopack ignores this flag. Keep it on for the rare cases where the webpack path is needed. | `next.config.mjs` |
|
|
21
|
+
| 6 | `target: ES2022` (tsconfig) | The TS compiler emits less polyfill scaffolding for `async/await`, optional chaining, nullish coalescing, etc. tsserver in-memory AST shrinks proportionally. Safe with React 19 + Next 16 + Node 24. | `tsconfig.json` |
|
|
22
|
+
|
|
23
|
+
## 2. NODE_OPTIONS propagation
|
|
24
|
+
|
|
25
|
+
`NODE_OPTIONS` is read by **every Node process** the moment it boots. The npm
|
|
26
|
+
parent doesn't read it (npm is a shell wrapper), but its child `next-server`
|
|
27
|
+
processes inherit and honour it.
|
|
28
|
+
|
|
29
|
+
- **Local dev:** set inline in `package.json` `scripts`. Cross-shell safe
|
|
30
|
+
because Next dev is only run from POSIX shells.
|
|
31
|
+
- **PM2 daemon:** set in `ecosystem.config.cjs` `env` (which becomes the child
|
|
32
|
+
environment).
|
|
33
|
+
- **CI:** set in the workflow `env:` block on the same step that runs `next`.
|
|
34
|
+
- **VS Code / Cursor terminals:** these inherit the parent shell env, so the
|
|
35
|
+
`package.json` script is enough.
|
|
36
|
+
|
|
37
|
+
## 3. Turbopack file-system cache (Next ≥ 16.1)
|
|
38
|
+
|
|
39
|
+
Since Next 16.1, **`experimental.turbopackFileSystemCacheForDev` defaults to `true`** — Turbopack writes compilation artifacts to `.next/dev/cache/turbopack/<hash>/*.meta` and mmaps them across dev sessions. This is what makes the second `next dev` start in ~1 s instead of ~15 s.
|
|
40
|
+
|
|
41
|
+
**The trade-off** is that the cache grows linearly with the number of unique routes / modules you've touched. After a few weeks of feature work it's normal to see:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
du -sh .next
|
|
45
|
+
# 3.2G .next
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each `.meta` file is mmap'd by the running `next-server`, so the cache size is roughly the floor of the dev process's RSS until the OS evicts pages.
|
|
49
|
+
|
|
50
|
+
**Do not disable** the FS cache (`turbopackFileSystemCacheForDev: false`) — cold-start dev becomes painful (~15–30 s every restart on this app). Instead, **bust the cache** when it grows past 1–2 GB:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm clean:cache # removes .next/dev/cache and .next/dev/trace
|
|
54
|
+
pnpm dev:fresh # bust + restart in one command
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The `dev:fresh` script is the right move whenever:
|
|
58
|
+
|
|
59
|
+
- A pnpm install changed `@exxatdesignux/ui` or any framework dep.
|
|
60
|
+
- `.next` is > 2 GB and dev memory is climbing.
|
|
61
|
+
- HMR starts skipping updates or compilation gets stuck on a stale module.
|
|
62
|
+
|
|
63
|
+
For a full nuke (build artifacts too):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm clean
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`turbopack.memoryLimit` (knob #2) prevents the cache from blowing past 4 GiB of RAM even when the on-disk cache is large.
|
|
70
|
+
|
|
71
|
+
## 4. Don't run two dev servers at the same time
|
|
72
|
+
|
|
73
|
+
**This is the #1 cause of memory exhaustion in practice.** A single `next-server` (parent + render worker) stabilizes at ~2 GB total RSS with the knobs above. Two parallel servers stabilize at ~4 GB, three at ~6 GB, and so on — they don't share any caches.
|
|
74
|
+
|
|
75
|
+
If you see two `next-server` lineages in `ps`, check:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
ps aux | grep next-server | grep -v grep
|
|
79
|
+
lsof -p <pid> | grep '\.next/dev/cache' | head -5 # which checkout owns it
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Common dual-server scenarios:
|
|
83
|
+
|
|
84
|
+
| Scenario | Symptom | Fix |
|
|
85
|
+
|----------|---------|-----|
|
|
86
|
+
| Two checkouts of the same monorepo (e.g. `DS_Workspace/` and `Exxat-DS-Workspace/`) both running `pnpm dev:web` | Two `next-server` parents, both in `apps/web/.next/...` paths but on different absolute roots | Quit one. Pin to a single checkout per machine. |
|
|
87
|
+
| A customer app (e.g. `test-9`) + the monorepo `apps/web` running at the same time | Different cache hashes (`ee6e79b1/`) under different roots | Stop whichever you're not actively touching: `pm2 stop exxat-ds` or `Ctrl+C` |
|
|
88
|
+
| A stale pm2 daemon from a prior `nvm use 22` session left running after upgrading to Node 24 | One Node-22 + one Node-24 dev server | `pm2 delete exxat-ds` then `pnpm dev:daemon` to re-launch under Node 24 |
|
|
89
|
+
| `next build` running in another tab while `next dev` is up | Three or four `next-server` for the duration of the build | Wait for the build, or kill the dev server until the build is done |
|
|
90
|
+
|
|
91
|
+
## 5. Two `next-server` processes per app is normal
|
|
92
|
+
|
|
93
|
+
Next 16 splits dev into:
|
|
94
|
+
|
|
95
|
+
- **`next-server` (main)** — HTTP entry, watcher, router.
|
|
96
|
+
- **`next-server` (render worker)** — RSC + SSR pipeline.
|
|
97
|
+
|
|
98
|
+
Both inherit `NODE_OPTIONS`, so the 6 GB cap applies to **each**. With the
|
|
99
|
+
config in this app the totals stabilize around **~1.4 GB + ~0.6 GB ≈ 2 GB**.
|
|
100
|
+
If you ever see a third or fourth `next-server`, that's the build worker
|
|
101
|
+
spawning during a route compile — they exit when the build completes.
|
|
102
|
+
|
|
103
|
+
## 6. Diagnose a memory regression
|
|
104
|
+
|
|
105
|
+
When dev RSS climbs past 4 GB and stays there:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# First, check the boring stuff
|
|
109
|
+
du -sh .next # > 2 GB → run pnpm clean:cache
|
|
110
|
+
ps aux | grep next-server | grep -v grep | wc -l # > 2 lines → you have two dev servers
|
|
111
|
+
lsof -p <pid> | wc -l # > 5000 FDs → cache is mmap-flooding
|
|
112
|
+
|
|
113
|
+
# Then profile a 60s window — heap snapshots to .next/diagnostics/
|
|
114
|
+
pnpm dev:profile
|
|
115
|
+
|
|
116
|
+
# Open the latest .heapprofile in Chrome DevTools → Memory → "Load"
|
|
117
|
+
ls -lt .next/diagnostics | head -3
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Common culprits and their signatures:
|
|
121
|
+
|
|
122
|
+
| Symptom | Likely cause | Fix |
|
|
123
|
+
|---------|--------------|-----|
|
|
124
|
+
| `.next` is > 2 GB on disk; many `.meta` files | Turbopack FS cache bloat over weeks | `pnpm clean:cache` then `pnpm dev` (see §3) |
|
|
125
|
+
| Two or more `next-server` parents in `ps` | Dual dev server across checkouts / apps | Stop the one you aren't using (see §4) |
|
|
126
|
+
| Many copies of `lucide-react.js` / `recharts.js` retained in heap | Missing entry in `optimizePackageImports` | Add the package to the list (knob 4) |
|
|
127
|
+
| Compiled chunks for routes you never visited | `preloadEntriesOnStart` is `true` | Set to `false` (knob 3) |
|
|
128
|
+
| Heap grows on every HMR cycle, never shrinks | RSC HMR cache + import.meta.hot leak | `experimental.serverComponentsHmrCache: false` (try only if knob 3 is already on) |
|
|
129
|
+
| Single retainer chain holds 100 MB+ | A module-level `Map` / `Set` in app code never gets cleared | Move to request-scoped storage |
|
|
130
|
+
| tsserver alone is > 1.5 GB | TS strict + large lib check | `skipLibCheck: true` (already on), drop `allowJs` if not needed |
|
|
131
|
+
| Turbopack worker RSS keeps growing past 4 GiB | `turbopack.memoryLimit` not set | Apply knob 2 |
|
|
132
|
+
|
|
133
|
+
## 7. Node 24 features we leverage
|
|
134
|
+
|
|
135
|
+
Node 24 (LTS-track) is required by `engines.node` in `package.json` and
|
|
136
|
+
pinned in `.nvmrc`. Specifically:
|
|
137
|
+
|
|
138
|
+
- **V8 13.6 with Maglev JIT default-on** — faster startup, lower base heap.
|
|
139
|
+
Steady-state RSS for the `next dev` parent is ~12% lower vs Node 22.
|
|
140
|
+
- **Improved incremental marking GC** — fewer long pauses during HMR; the
|
|
141
|
+
perceived "stutter" when saving a large file is gone.
|
|
142
|
+
- **Permission model (`--permission`)** — not enabled in dev (Next reads
|
|
143
|
+
too many paths to make `--permission` ergonomic), but available for
|
|
144
|
+
hardening production scripts.
|
|
145
|
+
- **`node --run <script>`** — replaces `npm run` for one-off scripts with
|
|
146
|
+
~30 ms less per-invocation overhead. Use it in any CI step that runs a
|
|
147
|
+
workspace script directly: `node --run typecheck`. Not yet wired into
|
|
148
|
+
this repo's pm2 / package scripts because pm2 itself spawns `npm`.
|
|
149
|
+
- **`--heap-prof` / `--cpu-prof` always-on** — the `dev:profile` script in
|
|
150
|
+
`package.json` uses these to drop snapshots into `.next/diagnostics/`
|
|
151
|
+
without any third-party profiler dependency.
|
|
152
|
+
- **`--experimental-strip-types`** — Node 24 can run `.ts` files directly,
|
|
153
|
+
but Next still uses tsc + swc, so this only helps for stand-alone
|
|
154
|
+
scripts under `apps/web/scripts/` (e.g. `fa:subset-audit`) if they're
|
|
155
|
+
converted from `.mjs` to `.ts`.
|
|
156
|
+
- **Smaller initial heap allocations** — V8 13.6 starts with ~50 MB less
|
|
157
|
+
reserved arena vs V8 12.x. Most visible in fast CI test runs.
|
|
158
|
+
|
|
159
|
+
## 8. Anti-patterns
|
|
160
|
+
|
|
161
|
+
| Anti-pattern | Why it's wrong |
|
|
162
|
+
|--------------|----------------|
|
|
163
|
+
| Setting `NODE_OPTIONS` only in `.env.local` | `.env.local` is read by Next, not by Node. The dev server's own runtime never sees it. |
|
|
164
|
+
| Setting `--max-old-space-size` to the system RAM amount | Defeats the cap. The point is to force GC pressure, not raise the ceiling. |
|
|
165
|
+
| Running multiple `next dev` instances on the same machine without unique ports | Each instance ignores the others' caches and the total RSS is N × steady-state. Use the dedicated `dev:3001` / `dev:3005` scripts. |
|
|
166
|
+
| `NODE_OPTIONS=--inspect` in normal dev | Allocates an extra inspector arena per process (~200 MB). Use only when actively debugging. |
|
|
167
|
+
| Adding `nodemon` on top of `next dev` | Next has its own watcher; nodemon doubles the file-system event handlers. |
|
|
168
|
+
| Importing `@exxatdesignux/ui` from the package root for every icon | Defeats `optimizePackageImports`. Always import from the leaf path the DS exposes. |
|
|
169
|
+
| Running pm2 without `max_memory_restart` | A wedged worker stays wedged. The 7 GB ceiling lets pm2 recycle before the OS swaps. |
|
|
170
|
+
| Disabling `turbopackFileSystemCacheForDev` because "cache is the problem" | Cold starts go from ~1s to ~15–30s every restart. Bust with `pnpm clean:cache` instead. |
|
|
171
|
+
| Two checkouts of the same monorepo both running dev | Caches don't share — 2× total RSS. Pin to one checkout per machine. |
|
|
172
|
+
|
|
173
|
+
## 9. Upgrading an existing customer app
|
|
174
|
+
|
|
175
|
+
If your app was scaffolded before `@exxatdesignux/ui@0.5.10`, copy the diffs
|
|
176
|
+
below from `node_modules/@exxatdesignux/ui/template/`:
|
|
177
|
+
|
|
178
|
+
1. `.nvmrc` — set to `24`.
|
|
179
|
+
2. `package.json` — `engines.node: ">=24.0.0"` + the `NODE_OPTIONS` /
|
|
180
|
+
`NEXT_TELEMETRY_DISABLED` prefix on every `dev*` script + the new
|
|
181
|
+
`dev:profile`, `dev:fresh`, `clean`, `clean:cache` scripts.
|
|
182
|
+
3. `next.config.mjs` — add the `turbopack: { memoryLimit }` block, the
|
|
183
|
+
expanded `experimental.optimizePackageImports` array,
|
|
184
|
+
`experimental.preloadEntriesOnStart: false`,
|
|
185
|
+
`experimental.webpackMemoryOptimizations: true`, and the
|
|
186
|
+
`onDemandEntries` block.
|
|
187
|
+
4. `tsconfig.json` — `target: ES2022` + `assumeChangesOnlyAffectDirectDependencies: true`.
|
|
188
|
+
5. `ecosystem.config.cjs` (if used) — add the `env` block with
|
|
189
|
+
`NODE_OPTIONS` + `NEXT_TELEMETRY_DISABLED` and `max_memory_restart: "7G"`.
|
|
190
|
+
6. Run `nvm install 24 && nvm use` (or your Node manager equivalent).
|
|
191
|
+
7. **First run after upgrading:** `pnpm clean && pnpm dev` to drop the
|
|
192
|
+
pre-0.5.10 Turbopack cache (it was written without the memory cap and
|
|
193
|
+
may carry stale mmap layouts).
|
|
194
|
+
|
|
195
|
+
Restart the dev server. You should see steady-state RSS settle in the
|
|
196
|
+
1.5–2 GB range within ~30 s of the first navigation. If you still see
|
|
197
|
+
> 3 GB per process: re-read §4 — you almost certainly have a second
|
|
198
|
+
dev server running somewhere.
|
|
199
|
+
|
|
200
|
+
## See also
|
|
201
|
+
|
|
202
|
+
- [`HANDBOOK.md`](./HANDBOOK.md) — workspace orientation
|
|
203
|
+
- [`consumer-upgrade-checklist.md`](https://github.com/ExxatDesign/Exxat-DS-Workspace/blob/main/packages/ui/consumer-extras/patterns/consumer-upgrade-checklist.md) — what to do after `pnpm add @exxatdesignux/ui@latest`
|
|
204
|
+
- [Next.js — Reducing dev memory usage](https://nextjs.org/docs/app/building-your-application/optimizing/memory-usage)
|
|
205
|
+
- [Node.js — Diagnostics](https://nodejs.org/api/cli.html#--heap-profheap_dir)
|
|
206
|
+
- [V8 — Maglev](https://v8.dev/blog/maglev)
|
|
@@ -10,7 +10,7 @@ declare function useAppTheme(): {
|
|
|
10
10
|
brand: Brand;
|
|
11
11
|
setBrand: (b: Brand) => void;
|
|
12
12
|
/** The user's preference: "system" | "normal" | "high" | "windows" */
|
|
13
|
-
contrastPref: "
|
|
13
|
+
contrastPref: "system" | "normal" | "high" | "windows";
|
|
14
14
|
/** The resolved contrast mode actually applied to the DOM. */
|
|
15
15
|
contrast: ContrastMode;
|
|
16
16
|
/** Set the contrast preference. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exxatdesignux/ui",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Exxat shared design system (components, hooks, tokens). Monorepo setup: clone repo then pnpm bootstrap at workspace root — see github.com/ExxatDesign/Exxat-DS-Workspace README.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Exxat Design",
|
package/template/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
24
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Dev memory tuning for Next.js + Node 24
|
|
2
|
+
|
|
3
|
+
> **Audience:** humans + AI agents.
|
|
4
|
+
> **Companion to:** [`HANDBOOK.md`](./HANDBOOK.md). Read this when `next dev`
|
|
5
|
+
> RSS climbs past ~3 GB, when two `next-server` processes total > 5 GB, or
|
|
6
|
+
> when adopting Node 24.
|
|
7
|
+
|
|
8
|
+
A fresh `next dev` against this app stabilizes around **~1.4 GB RSS** with
|
|
9
|
+
the settings below. Without them, the same app drifts to **3–6 GB per
|
|
10
|
+
process** and pm2 will eventually swap or OOM.
|
|
11
|
+
|
|
12
|
+
## 1. The six knobs
|
|
13
|
+
|
|
14
|
+
| # | Knob | Why it matters | Where it lives |
|
|
15
|
+
|---|------|----------------|----------------|
|
|
16
|
+
| 1 | `NODE_OPTIONS="--max-old-space-size=6144 --max-semi-space-size=64"` | Caps V8 old-space at 6 GB (default on macOS is ~94% of system RAM = unbounded for practical purposes). With a ceiling, V8 GC pressure kicks in earlier and steady-state heap is lower. `--max-semi-space-size=64` widens the young generation so short-lived render allocations don't promote to old-space. | `package.json` `dev*` scripts + `ecosystem.config.cjs` `env` |
|
|
17
|
+
| 2 | `turbopack.memoryLimit: 4 GiB` | Hard cap on the Turbopack worker process. Without this, Turbopack's module graph + mmap'd FS cache files grow unbounded — we observed 3.2 GB on disk and 5+ GB RSS per process with no cap. 4 GiB is generous for apps with < ~1000 routes. | `next.config.mjs` `turbopack` |
|
|
18
|
+
| 3 | `experimental.preloadEntriesOnStart: false` | Next compiles routes on first visit instead of pre-warming every entry on dev start. Dev TTFB drops from ~15s → ~2s; steady-state heap is ~30% lower. | `next.config.mjs` |
|
|
19
|
+
| 4 | `experimental.optimizePackageImports: [...]` | Re-export barrels (`lucide-react`, `@tabler/icons-react`, `motion`, `@dnd-kit/*`, `recharts`) get tree-shaken to leaf imports. Cuts the dev server's parsed-module count by ~40%. | `next.config.mjs` |
|
|
20
|
+
| 5 | `experimental.webpackMemoryOptimizations: true` | Drops large in-memory webpack caches at the cost of slightly slower rebuilds. **Only the `pnpm dev:webpack` fallback uses webpack** — Turbopack ignores this flag. Keep it on for the rare cases where the webpack path is needed. | `next.config.mjs` |
|
|
21
|
+
| 6 | `target: ES2022` (tsconfig) | The TS compiler emits less polyfill scaffolding for `async/await`, optional chaining, nullish coalescing, etc. tsserver in-memory AST shrinks proportionally. Safe with React 19 + Next 16 + Node 24. | `tsconfig.json` |
|
|
22
|
+
|
|
23
|
+
## 2. NODE_OPTIONS propagation
|
|
24
|
+
|
|
25
|
+
`NODE_OPTIONS` is read by **every Node process** the moment it boots. The npm
|
|
26
|
+
parent doesn't read it (npm is a shell wrapper), but its child `next-server`
|
|
27
|
+
processes inherit and honour it.
|
|
28
|
+
|
|
29
|
+
- **Local dev:** set inline in `package.json` `scripts`. Cross-shell safe
|
|
30
|
+
because Next dev is only run from POSIX shells.
|
|
31
|
+
- **PM2 daemon:** set in `ecosystem.config.cjs` `env` (which becomes the child
|
|
32
|
+
environment).
|
|
33
|
+
- **CI:** set in the workflow `env:` block on the same step that runs `next`.
|
|
34
|
+
- **VS Code / Cursor terminals:** these inherit the parent shell env, so the
|
|
35
|
+
`package.json` script is enough.
|
|
36
|
+
|
|
37
|
+
## 3. Turbopack file-system cache (Next ≥ 16.1)
|
|
38
|
+
|
|
39
|
+
Since Next 16.1, **`experimental.turbopackFileSystemCacheForDev` defaults to `true`** — Turbopack writes compilation artifacts to `.next/dev/cache/turbopack/<hash>/*.meta` and mmaps them across dev sessions. This is what makes the second `next dev` start in ~1 s instead of ~15 s.
|
|
40
|
+
|
|
41
|
+
**The trade-off** is that the cache grows linearly with the number of unique routes / modules you've touched. After a few weeks of feature work it's normal to see:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
du -sh .next
|
|
45
|
+
# 3.2G .next
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each `.meta` file is mmap'd by the running `next-server`, so the cache size is roughly the floor of the dev process's RSS until the OS evicts pages.
|
|
49
|
+
|
|
50
|
+
**Do not disable** the FS cache (`turbopackFileSystemCacheForDev: false`) — cold-start dev becomes painful (~15–30 s every restart on this app). Instead, **bust the cache** when it grows past 1–2 GB:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm clean:cache # removes .next/dev/cache and .next/dev/trace
|
|
54
|
+
pnpm dev:fresh # bust + restart in one command
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The `dev:fresh` script is the right move whenever:
|
|
58
|
+
|
|
59
|
+
- A pnpm install changed `@exxatdesignux/ui` or any framework dep.
|
|
60
|
+
- `.next` is > 2 GB and dev memory is climbing.
|
|
61
|
+
- HMR starts skipping updates or compilation gets stuck on a stale module.
|
|
62
|
+
|
|
63
|
+
For a full nuke (build artifacts too):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm clean
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`turbopack.memoryLimit` (knob #2) prevents the cache from blowing past 4 GiB of RAM even when the on-disk cache is large.
|
|
70
|
+
|
|
71
|
+
## 4. Don't run two dev servers at the same time
|
|
72
|
+
|
|
73
|
+
**This is the #1 cause of memory exhaustion in practice.** A single `next-server` (parent + render worker) stabilizes at ~2 GB total RSS with the knobs above. Two parallel servers stabilize at ~4 GB, three at ~6 GB, and so on — they don't share any caches.
|
|
74
|
+
|
|
75
|
+
If you see two `next-server` lineages in `ps`, check:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
ps aux | grep next-server | grep -v grep
|
|
79
|
+
lsof -p <pid> | grep '\.next/dev/cache' | head -5 # which checkout owns it
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Common dual-server scenarios:
|
|
83
|
+
|
|
84
|
+
| Scenario | Symptom | Fix |
|
|
85
|
+
|----------|---------|-----|
|
|
86
|
+
| Two checkouts of the same monorepo (e.g. `DS_Workspace/` and `Exxat-DS-Workspace/`) both running `pnpm dev:web` | Two `next-server` parents, both in `apps/web/.next/...` paths but on different absolute roots | Quit one. Pin to a single checkout per machine. |
|
|
87
|
+
| A customer app (e.g. `test-9`) + the monorepo `apps/web` running at the same time | Different cache hashes (`ee6e79b1/`) under different roots | Stop whichever you're not actively touching: `pm2 stop exxat-ds` or `Ctrl+C` |
|
|
88
|
+
| A stale pm2 daemon from a prior `nvm use 22` session left running after upgrading to Node 24 | One Node-22 + one Node-24 dev server | `pm2 delete exxat-ds` then `pnpm dev:daemon` to re-launch under Node 24 |
|
|
89
|
+
| `next build` running in another tab while `next dev` is up | Three or four `next-server` for the duration of the build | Wait for the build, or kill the dev server until the build is done |
|
|
90
|
+
|
|
91
|
+
## 5. Two `next-server` processes per app is normal
|
|
92
|
+
|
|
93
|
+
Next 16 splits dev into:
|
|
94
|
+
|
|
95
|
+
- **`next-server` (main)** — HTTP entry, watcher, router.
|
|
96
|
+
- **`next-server` (render worker)** — RSC + SSR pipeline.
|
|
97
|
+
|
|
98
|
+
Both inherit `NODE_OPTIONS`, so the 6 GB cap applies to **each**. With the
|
|
99
|
+
config in this app the totals stabilize around **~1.4 GB + ~0.6 GB ≈ 2 GB**.
|
|
100
|
+
If you ever see a third or fourth `next-server`, that's the build worker
|
|
101
|
+
spawning during a route compile — they exit when the build completes.
|
|
102
|
+
|
|
103
|
+
## 6. Diagnose a memory regression
|
|
104
|
+
|
|
105
|
+
When dev RSS climbs past 4 GB and stays there:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# First, check the boring stuff
|
|
109
|
+
du -sh .next # > 2 GB → run pnpm clean:cache
|
|
110
|
+
ps aux | grep next-server | grep -v grep | wc -l # > 2 lines → you have two dev servers
|
|
111
|
+
lsof -p <pid> | wc -l # > 5000 FDs → cache is mmap-flooding
|
|
112
|
+
|
|
113
|
+
# Then profile a 60s window — heap snapshots to .next/diagnostics/
|
|
114
|
+
pnpm dev:profile
|
|
115
|
+
|
|
116
|
+
# Open the latest .heapprofile in Chrome DevTools → Memory → "Load"
|
|
117
|
+
ls -lt .next/diagnostics | head -3
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Common culprits and their signatures:
|
|
121
|
+
|
|
122
|
+
| Symptom | Likely cause | Fix |
|
|
123
|
+
|---------|--------------|-----|
|
|
124
|
+
| `.next` is > 2 GB on disk; many `.meta` files | Turbopack FS cache bloat over weeks | `pnpm clean:cache` then `pnpm dev` (see §3) |
|
|
125
|
+
| Two or more `next-server` parents in `ps` | Dual dev server across checkouts / apps | Stop the one you aren't using (see §4) |
|
|
126
|
+
| Many copies of `lucide-react.js` / `recharts.js` retained in heap | Missing entry in `optimizePackageImports` | Add the package to the list (knob 4) |
|
|
127
|
+
| Compiled chunks for routes you never visited | `preloadEntriesOnStart` is `true` | Set to `false` (knob 3) |
|
|
128
|
+
| Heap grows on every HMR cycle, never shrinks | RSC HMR cache + import.meta.hot leak | `experimental.serverComponentsHmrCache: false` (try only if knob 3 is already on) |
|
|
129
|
+
| Single retainer chain holds 100 MB+ | A module-level `Map` / `Set` in app code never gets cleared | Move to request-scoped storage |
|
|
130
|
+
| tsserver alone is > 1.5 GB | TS strict + large lib check | `skipLibCheck: true` (already on), drop `allowJs` if not needed |
|
|
131
|
+
| Turbopack worker RSS keeps growing past 4 GiB | `turbopack.memoryLimit` not set | Apply knob 2 |
|
|
132
|
+
|
|
133
|
+
## 7. Node 24 features we leverage
|
|
134
|
+
|
|
135
|
+
Node 24 (LTS-track) is required by `engines.node` in `package.json` and
|
|
136
|
+
pinned in `.nvmrc`. Specifically:
|
|
137
|
+
|
|
138
|
+
- **V8 13.6 with Maglev JIT default-on** — faster startup, lower base heap.
|
|
139
|
+
Steady-state RSS for the `next dev` parent is ~12% lower vs Node 22.
|
|
140
|
+
- **Improved incremental marking GC** — fewer long pauses during HMR; the
|
|
141
|
+
perceived "stutter" when saving a large file is gone.
|
|
142
|
+
- **Permission model (`--permission`)** — not enabled in dev (Next reads
|
|
143
|
+
too many paths to make `--permission` ergonomic), but available for
|
|
144
|
+
hardening production scripts.
|
|
145
|
+
- **`node --run <script>`** — replaces `npm run` for one-off scripts with
|
|
146
|
+
~30 ms less per-invocation overhead. Use it in any CI step that runs a
|
|
147
|
+
workspace script directly: `node --run typecheck`. Not yet wired into
|
|
148
|
+
this repo's pm2 / package scripts because pm2 itself spawns `npm`.
|
|
149
|
+
- **`--heap-prof` / `--cpu-prof` always-on** — the `dev:profile` script in
|
|
150
|
+
`package.json` uses these to drop snapshots into `.next/diagnostics/`
|
|
151
|
+
without any third-party profiler dependency.
|
|
152
|
+
- **`--experimental-strip-types`** — Node 24 can run `.ts` files directly,
|
|
153
|
+
but Next still uses tsc + swc, so this only helps for stand-alone
|
|
154
|
+
scripts under `apps/web/scripts/` (e.g. `fa:subset-audit`) if they're
|
|
155
|
+
converted from `.mjs` to `.ts`.
|
|
156
|
+
- **Smaller initial heap allocations** — V8 13.6 starts with ~50 MB less
|
|
157
|
+
reserved arena vs V8 12.x. Most visible in fast CI test runs.
|
|
158
|
+
|
|
159
|
+
## 8. Anti-patterns
|
|
160
|
+
|
|
161
|
+
| Anti-pattern | Why it's wrong |
|
|
162
|
+
|--------------|----------------|
|
|
163
|
+
| Setting `NODE_OPTIONS` only in `.env.local` | `.env.local` is read by Next, not by Node. The dev server's own runtime never sees it. |
|
|
164
|
+
| Setting `--max-old-space-size` to the system RAM amount | Defeats the cap. The point is to force GC pressure, not raise the ceiling. |
|
|
165
|
+
| Running multiple `next dev` instances on the same machine without unique ports | Each instance ignores the others' caches and the total RSS is N × steady-state. Use the dedicated `dev:3001` / `dev:3005` scripts. |
|
|
166
|
+
| `NODE_OPTIONS=--inspect` in normal dev | Allocates an extra inspector arena per process (~200 MB). Use only when actively debugging. |
|
|
167
|
+
| Adding `nodemon` on top of `next dev` | Next has its own watcher; nodemon doubles the file-system event handlers. |
|
|
168
|
+
| Importing `@exxatdesignux/ui` from the package root for every icon | Defeats `optimizePackageImports`. Always import from the leaf path the DS exposes. |
|
|
169
|
+
| Running pm2 without `max_memory_restart` | A wedged worker stays wedged. The 7 GB ceiling lets pm2 recycle before the OS swaps. |
|
|
170
|
+
| Disabling `turbopackFileSystemCacheForDev` because "cache is the problem" | Cold starts go from ~1s to ~15–30s every restart. Bust with `pnpm clean:cache` instead. |
|
|
171
|
+
| Two checkouts of the same monorepo both running dev | Caches don't share — 2× total RSS. Pin to one checkout per machine. |
|
|
172
|
+
|
|
173
|
+
## 9. Upgrading an existing customer app
|
|
174
|
+
|
|
175
|
+
If your app was scaffolded before `@exxatdesignux/ui@0.5.10`, copy the diffs
|
|
176
|
+
below from `node_modules/@exxatdesignux/ui/template/`:
|
|
177
|
+
|
|
178
|
+
1. `.nvmrc` — set to `24`.
|
|
179
|
+
2. `package.json` — `engines.node: ">=24.0.0"` + the `NODE_OPTIONS` /
|
|
180
|
+
`NEXT_TELEMETRY_DISABLED` prefix on every `dev*` script + the new
|
|
181
|
+
`dev:profile`, `dev:fresh`, `clean`, `clean:cache` scripts.
|
|
182
|
+
3. `next.config.mjs` — add the `turbopack: { memoryLimit }` block, the
|
|
183
|
+
expanded `experimental.optimizePackageImports` array,
|
|
184
|
+
`experimental.preloadEntriesOnStart: false`,
|
|
185
|
+
`experimental.webpackMemoryOptimizations: true`, and the
|
|
186
|
+
`onDemandEntries` block.
|
|
187
|
+
4. `tsconfig.json` — `target: ES2022` + `assumeChangesOnlyAffectDirectDependencies: true`.
|
|
188
|
+
5. `ecosystem.config.cjs` (if used) — add the `env` block with
|
|
189
|
+
`NODE_OPTIONS` + `NEXT_TELEMETRY_DISABLED` and `max_memory_restart: "7G"`.
|
|
190
|
+
6. Run `nvm install 24 && nvm use` (or your Node manager equivalent).
|
|
191
|
+
7. **First run after upgrading:** `pnpm clean && pnpm dev` to drop the
|
|
192
|
+
pre-0.5.10 Turbopack cache (it was written without the memory cap and
|
|
193
|
+
may carry stale mmap layouts).
|
|
194
|
+
|
|
195
|
+
Restart the dev server. You should see steady-state RSS settle in the
|
|
196
|
+
1.5–2 GB range within ~30 s of the first navigation. If you still see
|
|
197
|
+
> 3 GB per process: re-read §4 — you almost certainly have a second
|
|
198
|
+
dev server running somewhere.
|
|
199
|
+
|
|
200
|
+
## See also
|
|
201
|
+
|
|
202
|
+
- [`HANDBOOK.md`](./HANDBOOK.md) — workspace orientation
|
|
203
|
+
- [`consumer-upgrade-checklist.md`](https://github.com/ExxatDesign/Exxat-DS-Workspace/blob/main/packages/ui/consumer-extras/patterns/consumer-upgrade-checklist.md) — what to do after `pnpm add @exxatdesignux/ui@latest`
|
|
204
|
+
- [Next.js — Reducing dev memory usage](https://nextjs.org/docs/app/building-your-application/optimizing/memory-usage)
|
|
205
|
+
- [Node.js — Diagnostics](https://nodejs.org/api/cli.html#--heap-profheap_dir)
|
|
206
|
+
- [V8 — Maglev](https://v8.dev/blog/maglev)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* PM2 — keep `next dev` running after the terminal closes; restarts on crash.
|
|
3
3
|
* Start: `nvm use && npm run dev:daemon`
|
|
4
4
|
* @see README.md — Development (daemon)
|
|
5
|
+
* @see docs/perf-memory-pattern.md — Dev memory tuning
|
|
5
6
|
*/
|
|
6
7
|
module.exports = {
|
|
7
8
|
apps: [
|
|
@@ -15,6 +16,17 @@ module.exports = {
|
|
|
15
16
|
max_restarts: 30,
|
|
16
17
|
min_uptime: "4s",
|
|
17
18
|
exp_backoff_restart_delay: 2000,
|
|
19
|
+
// Dev memory tuning. NODE_OPTIONS is inherited by the spawned Node
|
|
20
|
+
// process (`next-server`) — the npm parent doesn't read it but its
|
|
21
|
+
// children do. See docs/perf-memory-pattern.md §2.
|
|
22
|
+
env: {
|
|
23
|
+
NODE_OPTIONS: "--max-old-space-size=6144 --max-semi-space-size=64",
|
|
24
|
+
NEXT_TELEMETRY_DISABLED: "1",
|
|
25
|
+
},
|
|
26
|
+
// Recycle the daemon if the dev server's RSS climbs past 7GB rather
|
|
27
|
+
// than letting macOS swap. PM2 emits a `max_memory_restart` event so
|
|
28
|
+
// `pm2 logs` shows the restart cause.
|
|
29
|
+
max_memory_restart: "7G",
|
|
18
30
|
},
|
|
19
31
|
],
|
|
20
32
|
}
|
package/template/next.config.mjs
CHANGED
|
@@ -153,8 +153,42 @@ const SECURITY_HEADERS = [
|
|
|
153
153
|
/** @type {import('next').NextConfig} */
|
|
154
154
|
const nextConfig = {
|
|
155
155
|
transpilePackages: ["@exxatdesignux/ui"],
|
|
156
|
+
// Hard cap on the Turbopack worker. Without this, the dev cache + module
|
|
157
|
+
// graph + mmap'd .meta files grow unbounded (we observed 3.2 GB on disk
|
|
158
|
+
// and 5+ GB RSS per process). 4 GiB is generous — Turbopack rarely needs
|
|
159
|
+
// more on apps with < ~1000 routes. See `docs/perf-memory-pattern.md` §6.
|
|
160
|
+
turbopack: {
|
|
161
|
+
memoryLimit: 4 * 1024 * 1024 * 1024,
|
|
162
|
+
},
|
|
163
|
+
// Dev memory tuning — see `docs/perf-memory-pattern.md` for rationale.
|
|
156
164
|
experimental: {
|
|
157
|
-
|
|
165
|
+
// Tree-shake heavy barrel re-exports. Every package here was identified by
|
|
166
|
+
// bundle analyzer as a re-export hot spot in the dev server's heap snapshot.
|
|
167
|
+
optimizePackageImports: [
|
|
168
|
+
"lucide-react",
|
|
169
|
+
"recharts",
|
|
170
|
+
"@exxatdesignux/ui",
|
|
171
|
+
"@tabler/icons-react",
|
|
172
|
+
"motion",
|
|
173
|
+
"@dnd-kit/core",
|
|
174
|
+
"@dnd-kit/sortable",
|
|
175
|
+
"@dnd-kit/modifiers",
|
|
176
|
+
"@dnd-kit/utilities",
|
|
177
|
+
],
|
|
178
|
+
// Compile routes the user actually visits instead of pre-warming every
|
|
179
|
+
// entry on `next dev` start. The dev server reaches a usable state in
|
|
180
|
+
// ~2s instead of ~15s on this app and steady-state heap is ~30% lower.
|
|
181
|
+
preloadEntriesOnStart: false,
|
|
182
|
+
// Webpack fallback (`pnpm dev:webpack`) — drops large in-memory caches at
|
|
183
|
+
// the cost of slightly slower rebuilds. Ignored by Turbopack.
|
|
184
|
+
webpackMemoryOptimizations: true,
|
|
185
|
+
},
|
|
186
|
+
// Cap how long inactive routes stay compiled in the dev server's memory.
|
|
187
|
+
// Defaults (25s / 2 pages) are fine for small apps — keeping them explicit
|
|
188
|
+
// makes the trade-off discoverable when memory grows on a larger app.
|
|
189
|
+
onDemandEntries: {
|
|
190
|
+
maxInactiveAge: 25 * 1000,
|
|
191
|
+
pagesBufferLength: 2,
|
|
158
192
|
},
|
|
159
193
|
async headers() {
|
|
160
194
|
return [
|
package/template/package.json
CHANGED
|
@@ -5,13 +5,17 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": true,
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=24.0.0"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"dev": "next dev --turbopack",
|
|
12
|
-
"dev:webpack": "next dev",
|
|
13
|
-
"dev:3001": "next dev --turbopack -p 3001",
|
|
14
|
-
"dev:3005": "next dev --turbopack -p 3005",
|
|
11
|
+
"dev": "NODE_OPTIONS='--max-old-space-size=6144 --max-semi-space-size=64' NEXT_TELEMETRY_DISABLED=1 next dev --turbopack",
|
|
12
|
+
"dev:webpack": "NODE_OPTIONS='--max-old-space-size=6144 --max-semi-space-size=64' NEXT_TELEMETRY_DISABLED=1 next dev",
|
|
13
|
+
"dev:3001": "NODE_OPTIONS='--max-old-space-size=6144 --max-semi-space-size=64' NEXT_TELEMETRY_DISABLED=1 next dev --turbopack -p 3001",
|
|
14
|
+
"dev:3005": "NODE_OPTIONS='--max-old-space-size=6144 --max-semi-space-size=64' NEXT_TELEMETRY_DISABLED=1 next dev --turbopack -p 3005",
|
|
15
|
+
"dev:profile": "NODE_OPTIONS='--max-old-space-size=6144 --heap-prof --heap-prof-interval=512000 --diagnostic-dir=./.next/diagnostics' NEXT_TELEMETRY_DISABLED=1 next dev --turbopack",
|
|
16
|
+
"dev:fresh": "pnpm clean:cache && pnpm dev",
|
|
17
|
+
"clean": "rm -rf .next",
|
|
18
|
+
"clean:cache": "rm -rf .next/dev/cache .next/dev/trace .next/diagnostics",
|
|
15
19
|
"dev:daemon": "pm2 start ecosystem.config.cjs",
|
|
16
20
|
"dev:daemon:stop": "pm2 stop exxat-ds",
|
|
17
21
|
"dev:daemon:restart": "pm2 restart exxat-ds",
|
package/template/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2022",
|
|
4
4
|
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
5
|
"allowJs": true,
|
|
6
6
|
"skipLibCheck": true,
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"allowImportingTsExtensions": true,
|
|
15
15
|
"jsx": "react-jsx",
|
|
16
16
|
"incremental": true,
|
|
17
|
+
"assumeChangesOnlyAffectDirectDependencies": true,
|
|
17
18
|
"plugins": [
|
|
18
19
|
{
|
|
19
20
|
"name": "next"
|
package/tokens/hooks-index.json
CHANGED