Skip to content

presets(vercel): support immutable static files - #4434

Merged
pi0 merged 8 commits into
v2from
vercel-immutable-v2
Nov 10, 2026
Merged

pi0 merged 8 commits into
v2from
vercel-immutable-v2

Conversation

@pi0x

@pi0x pi0x commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

backport draft of #4432 for v2

undocumented and mainly for current nuxt v4 with manual integration with new options.buildAssetsDir (config name might change)

pending until #4432 lands, released and well-tested on real projects.

preview pkg for e2e testing:

{
  "nitro": "https://pkg.pr.new/nitropack@4434"
}

@vercel

vercel Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
nitro.build Ready Ready Preview Nov 10, 2026 9:49am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Jul 16, 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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73a1bcb3-5b56-47bf-b7c1-b1481d08c29a

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
Finishing Touches

🧪 Generate unit tests (beta)

  • Create PR with unit tests
  • Commit unit tests in branch vercel-immutable-v2
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@pi0
pi0 changed the base branch from main to v2 July 16, 2026 08:13
@pi0 pi0 added pending Blocked on an upstream change or a decision v2 labels Jul 16, 2026
@pi0 pi0 changed the title vercel immutable v2 presets(vercel): support immutable static files (v2) Jul 16, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitropack@4434

commit: 55d68da

@pi0x pi0x added enhancement New feature or improvement (PRs; issues use the Feature type) preset Deployment presets in general preset:vercel assets Public and server assets, static serving labels Sep 2, 2026
@pi0x pi0x changed the title presets(vercel): support immutable static files (v2) feat(vercel): support immutable static files (v2) Sep 2, 2026
@pi0 pi0 changed the title feat(vercel): support immutable static files (v2) feat(vercel): support immutable static files Nov 10, 2026
@pi0 pi0 changed the title feat(vercel): support immutable static files presets(vercel): support immutable static files Nov 10, 2026
- opt in via `NITRO_VERCEL_IMMUTABLE_STATIC_FILES_ENABLED`; `VERCEL_IMMUTABLE_STATIC_FILES_ENABLED` only signals platform support
- skip with a warning on unsupported Vercel deployments and non-root `baseURL`
- normalize `buildAssetsDir` (config + hash salt)
- warn when no immutable assets were emitted
- add unit tests
@pi0
pi0 marked this pull request as ready for review November 10, 2026 09:30
@pi0
pi0 self-requested a review as a code owner November 10, 2026 09:30
@pi0x

pi0x commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@danielroe heads up on the Nuxt side of this one. The branch is now synced with what landed on main in #4432.

  • Opt in: this should stay opt-in for users. Nuxt shouldn't turn it on by default, only pass through what the user sets: nitro.vercel.immutableStaticFiles: true in their config, or NITRO_VERCEL_IMMUTABLE_STATIC_FILES_ENABLED=1. VERCEL_IMMUTABLE_STATIC_FILES_ENABLED only means the Vercel deployment supports it; it doesn't turn the feature on. When a user opts in but the Vercel deployment doesn't support it, Nitro skips immutable output with a warning. A non-root baseURL is skipped too.
  • Assets dir: when active, the preset sets nitro.options.buildAssetsDir to _vercel/immutable/[VERCEL_HASH_SALT/]nuxt. Nuxt needs to use it in place of app.buildAssetsDir for the client and SSR Vite builds (build.assetsDir) and for the publicAssets entry, so files and their URLs end up under it. Nitro then lists that dir in the public output and writes .vercel/output/immutable.json. If it finds nothing there, it warns.
  • Hash length: the manifest uses the file path itself as the content hash, so file names need a long hash. On main the Vite plugin uses [hash:16]; Vite's default is 8.
  • Timing: the preset now sets buildAssetsDir from a preset module during createNitro, so it's already set by Nuxt's nitro:init, before Vite runs. Nuxt can read nitro.options.buildAssetsDir there; if it's set, immutable output is active.
  • Prerender: prerendering runs in a separate Nitro instance created from nitro.options._config, so the preset module doesn't run there. If Nuxt changes app.buildAssetsDir/publicAssets only on nitro.options in nitro:init, prerendered HTML will still point at /_nuxt/. The same change needs to go into nitro.options._config too, like Nuxt already does for storage.
  • Only hashed files: Nitro lists every file under buildAssetsDir in the manifest and uses the path as the hash. So only the hashed Vite output should go there, not the whole app.buildAssetsDir. For example, the changing builds/latest.json from experimental.appManifest must stay outside it, or Vercel may keep serving the first deployment's copy.

(This comment was written with an AI assistant.)

Run `setupImmutableStaticFiles` as a preset module instead of a `build:before`
hook so frameworks that build the client before Nitro (Nuxt runs Vite before
`build(nitro)`) can read `nitro.options.buildAssetsDir` from `nitro:init`.
… test real output

- warn and skip when immutable static files were enabled after init
- read `immutable.json` right after the vercel build and assert its contents with a fixture asset
- clarify `buildAssetsDir` docs for v2 (frameworks apply it)
@pi0
pi0 merged commit 27afbd6 into v2 Nov 10, 2026
10 checks passed
@pi0
pi0 deleted the vercel-immutable-v2 branch November 10, 2026 10:29
@pi0x pi0x removed the v2 label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assets Public and server assets, static serving enhancement New feature or improvement (PRs; issues use the Feature type) pending Blocked on an upstream change or a decision preset:vercel preset Deployment presets in general

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants