Skip to content

feat(serverAssets): opt-in embed modes for large catalogs - #4507

Open
s00d wants to merge 6 commits into
nitrojs:v2from
s00d:fix/server-assets-perf-v2
Open

feat(serverAssets): opt-in embed modes for large catalogs#4507
s00d wants to merge 6 commits into
nitrojs:v2from
s00d:fix/server-assets-perf-v2

Conversation

@s00d

@s00d s00d commented Aug 4, 2026

Copy link
Copy Markdown

🔗 Linked issue

#1833

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Large serverAssets catalogs (thousands of small JSON files) make Nitro builds slow / OOM because production mode creates one Rollup raw: module per file (#1833). Nuxt 4.x apps that ship translation trees hit this hard.

This PR adds an opt-in embed flag on ServerAssetDir. Default stays true (same historical raw: behavior — no silent auto-inline).

embed Build behavior
true / omitted One lazy raw: chunk per file (unchanged)
"inline" Single virtual module (like public-assets inline)
false Copy to server/assets/<baseName>; meta+path at build; readFile at runtime (like public-assets node)

Also skips per-file gzip in the server size tree for chunks/raw/** (logging only).

Example

export default defineNitroConfig({
  serverAssets: [{
    baseName: 'i18n',
    dir: './i18n-data',
    embed: 'inline', // or false for Node disk reads
  }],
})

Real-world use

nuxt-i18n-micro can register locale JSON trees as serverAssets and set embed: 'inline' or embed: false so Node SSR builds stay fast without dual-writing payloads to public/.

Benchmark (same fixture: 1296 JSON, compressedSizes: true)

Era nitropack strategy ms (run 1 / 2) chunks/raw
Nuxt 4.1.2 2.12.5 raw: 3228 / 3986 1296
Nuxt 4.2 2.12.9 raw: 3286 1296
Nuxt 4.4+ 2.13.4 raw: 4605 / 3124 1296
this PR 2.13.4+fix embed: "inline" 1608 0
this PR 2.13.4+fix embed: false 3288 0

Notes:

  • Published 2.12.x → 2.13.x already used N× raw: per file; cost is the same strategy, wall time varies with machine/noise.
  • Default with this PR remains N× raw: (same as 2.12.5 / 2.13.4). Speedup requires explicit embed.
  • Extra check on 625 JSON, minify off, compressedSizes: false: default ~2270 ms / 625 raw; inline ~610 ms / 0; false ~1130 ms / 0.

Tests

  • test/unit/server-assets-perf.test.ts — default unchanged, inline/false runtime, binary, ignore, pattern, mixed dirs
  • Also green: test/unit/ + test/presets/node.test.ts (99 passed, no regressions)

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

s00d and others added 6 commits August 4, 2026 19:10
Auto-inline ≥50 small text/json files into one virtual module instead of
N× raw: Rollup chunks; add embed:false|inline; skip gzip of chunks/raw in
fs-tree. Brings multi-thousand JSON serverAssets builds back under ~2s.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Drop silent auto-inline; default embed:true keeps historical raw: modules.
Use createEtag, runParallel error handling, and serverDir-relative paths
like public-assets. Tests cover raw / inline / fs modes explicitly.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep default embed:true as historical raw: path; harden embed:false
meta via mime; cover runtime/binary/ignore/pattern/mixed modes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Drop fsDriver/mime runtime wrappers. Bake meta+relative path at
build time; readFile at runtime. Default raw: template unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@s00d
s00d requested a review from pi0 as a code owner August 4, 2026 14:12
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

@s00d is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 600eb2ff-c63c-4d68-87f4-7a0ddba8d847

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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