Skip to content

presets(vercel): allow overriding function config by route#4174

Draft
pi0 wants to merge 4 commits intov2from
vercel-fn-config-backport
Draft

presets(vercel): allow overriding function config by route#4174
pi0 wants to merge 4 commits intov2from
vercel-fn-config-backport

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Apr 2, 2026

Summary

Backport of 589e8ad (#4124) to v2.

Adds vercel.functionRules option for per-route serverless function configuration overrides. Routes matching functionRules get copied function directories (instead of symlinks) with merged .vc-config.json. Includes auto-derived consumer names for queue/v2beta triggers.

Usage

export default defineNitroConfig({
  vercel: {
    functionRules: {
      '/api/my-slow-routes/**': { maxDuration: 3600 },
      '/api/queues/fulfill-order': {
        experimentalTriggers: [{ type: 'queue/v2beta', topic: 'orders' }],
      },
    },
  },
})

Regression fixes

  • Spread order: handler, launcherType, shouldAddHelpers, supportsResponseStreaming are now enforced after the user spread, so they can't be accidentally overridden via vercel.functions
  • ISR route shadowing: functionRules patterns that overlap with ISR route rules are excluded from config.json routes, preventing ISR from being silently bypassed
  • Array merge: defu merges arrays by default — overrides with array fields (e.g. experimentalTriggers) now fully replace the base config arrays instead of merging
  • Leading slash normalization: functionRules pattern keys are normalized with a leading / to prevent broken output from normalizeRouteDest/normalizeRouteSrc
  • ISR + functionRules: ISR function directories correctly receive merged functionRules overrides (e.g. regions) via createFunctionDirWithCustomConfig
  • Observability route matching: use original route pattern (not PCRE regex) for radix3 matching, so functionRules wildcards correctly apply to dynamic observability routes
  • Duplicate config.json entries: functionRules routes that already appear in observability routes are deduplicated in config.json

Test plan

  • 57 vercel preset tests pass (55 existing + 2 new)
  • 34 vercel-edge preset tests pass
  • New tests for custom function directory creation, merged config, arbitrary fields, file copying, and base config isolation
  • New test verifying ISR function directories receive functionRules overrides (regions)
  • New test verifying wildcard functionRules apply to observability route directories (/api/storage/**/api/storage/dev.func)

Backport of #4124 (589e8ad) to v2.

Adds `vercel.functionRules` option for per-route serverless function
configuration overrides. Routes matching functionRules get copied
function directories (instead of symlinks) with merged .vc-config.json.
Includes auto-derived consumer names for queue/v2beta triggers.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

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

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Apr 2, 2026 8:47am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Draft detected.

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

Run ID: 4e2af452-2232-4396-9e5a-5923b9df8850

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-fn-config-backport

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 and usage tips.

@pi0 pi0 changed the title feat(vercel): allow overriding function config by route presets(vercel): allow overriding function config by route Apr 2, 2026
@pi0 pi0 requested a review from RihanArfan April 2, 2026 08:17
- Restore spread order so `handler`/`launcherType` can't be overridden
- Skip `functionRules` config.json routes that overlap with ISR rules
- Fix `defu` array merge to fully replace arrays from overrides
- Normalize leading slash on `functionRules` pattern keys
- Add test for ISR + functionRules config merge
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 2, 2026

Open in StackBlitz

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

commit: b8d6e0a

- use original route pattern (not regex) for radix3 matching in o11y loop
- deduplicate functionRules routes against o11y routes in config.json
- rename misleading `isrFuncDirs` variable to `isrBasePaths`
- add wildcard functionRules test covering o11y route code path
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