Skip to content

refactor(aws-lambda): add srvx lambda handlers#4052

Open
taylorfsteele wants to merge 8 commits into
nitrojs:mainfrom
taylorfsteele:fix/aws-lambda-preview-command
Open

refactor(aws-lambda): add srvx lambda handlers#4052
taylorfsteele wants to merge 8 commits into
nitrojs:mainfrom
taylorfsteele:fix/aws-lambda-preview-command

Conversation

@taylorfsteele
Copy link
Copy Markdown
Contributor

@taylorfsteele taylorfsteele commented Feb 22, 2026

🔗 Linked issue

#4051

❓ 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

Closes #4051

This PR removes the previous aws-lambda handlers in favor srvx's lambda handlers.

📝 Checklist

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

Export fetch from aws-lambda, aws-lambda-streaming presets
Add streaming preview shim
@taylorfsteele taylorfsteele requested a review from pi0 as a code owner February 22, 2026 18:19
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 22, 2026

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 22, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: da0684c6-a9e6-45fd-add5-9739f412a828

📥 Commits

Reviewing files that changed from the base of the PR and between dc5b6ce and a6af3e7.

📒 Files selected for processing (4)
  • src/build/vite/prod.ts
  • test/presets/aws-lambda.test.ts
  • test/vite/lambda-ssr-fixture/app/entry-server.ts
  • test/vite/lambda-ssr-fixture/vite.config.ts
✅ Files skipped from review due to trivial changes (2)
  • test/vite/lambda-ssr-fixture/vite.config.ts
  • test/vite/lambda-ssr-fixture/app/entry-server.ts

📝 Walkthrough

Walkthrough

Adds a preview command to the aws-lambda preset and rewrites both aws-lambda runtimes to use the srvx/aws-lambda adapter with streaming and preview-fallback support; adjusts Vite prod loader dispatch and expands tests/fixtures to cover streaming preview and SSR.

Changes

AWS Lambda Preset and Runtime Upgrade

Layer / File(s) Summary
Preset Configuration
src/presets/aws-lambda/preset.ts
A new preview command is added to the preset using npx srvx --prod ./.
Streaming runtime (srvx adapter)
src/presets/aws-lambda/runtime/aws-lambda-streaming.ts
Rewrites streaming runtime to use srvx/aws-lambda imports, builds lambdaHandler via toLambdaHandler, implements handlerWithPreviewFallback, optional streamifyResponse wrapper, retains named handler, and adds default export { fetch: (request) => invokeLambdaHandler(...) }.
Standard runtime wrapper
src/presets/aws-lambda/runtime/aws-lambda.ts
Creates exported handler via toLambdaHandler(...) and adds a default export object with fetch that delegates to invokeLambdaHandler(handler, request).
Vite prod loader dispatch
src/build/vite/prod.ts
lazyService(loader) now resolves modules without forcing .default normalization and dispatches to mod.fetch or mod.default?.fetch to support both default and named fetch exports.
Tests & fixtures
test/presets/aws-lambda.test.ts, test/vite/lambda-ssr-fixture/*
Expand Vitest imports, add tests for adapter default.fetch preview, add streaming and streaming-vite-ssr suites (including APIGatewayProxyEventV2 streaming test), and add fixture entry-server and vite.config for SSR streaming test.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • nitrojs/nitro#3814: Both modify the streaming Lambda handler implementation in aws-lambda-streaming.ts to address streaming behavior in the srvx-based adapter.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with scope (aws-lambda) and concise description of the refactor.
Description check ✅ Passed The description is directly related to the changeset, explaining it replaces aws-lambda handlers with srvx handlers to close issue #4051.
Linked Issues check ✅ Passed The code changes fully address issue #4051 by adding preview command support and srvx lambda handlers for the aws-lambda preset.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing srvx lambda handlers for aws-lambda preset and adding preview support; test additions align with the feature implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 22, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4052

commit: a6af3e7

martinmiglio added a commit to martinmiglio/tss-nitro-prerender-repro that referenced this pull request Apr 20, 2026
Standalone nitro + Vite build with a single route. Reproduces the preview
404 stub with preset: 'aws-lambda' (srvx loadServerEntry has no branch for
the handler-only export); returns 200 when swapped to preset: 'node-server'.

Targeted by nitrojs/nitro#4052.
@martinmiglio
Copy link
Copy Markdown

martinmiglio commented Apr 20, 2026

Confirming this PR fixes TSS prerender + link crawling on aws-lambda end-to-end.

Installed the pkg.pr.new build into a minimal @tanstack/react-start app with prerender: { enabled: true, crawlLinks: true } and nitro({ preset: 'aws-lambda' }):

  • Before (nitro nightly 3.0.260415-beta): fails with Error: Failed to fetch /: — silent 404 from src/preview.ts:74-75 default stub because srvx's loadServerEntry has no branch for { handler }-only exports (srvx src/loader.ts:163-178).
  • With this PR: 4 routes crawled, real HTML written to .output/public/{about,contact,pricing}/index.html, and .output/server/index.mjs still exports handler alongside the new default — Lambda deployment artifact intact. No regression on node-server / vercel / netlify.

Also reproduces the underlying bug without any framework: nitro-only/ — only nitro dep, nitro build + nitro preview + curl returns HTTP 404 with empty statusText for preset: "aws-lambda"; 200 for preset: "node-server".

Related: #4051 (this PR's linked issue), TanStack/router#6562 (stale, same root cause pre-#4011).

@taylorfsteele
Copy link
Copy Markdown
Contributor Author

Hey @pi0 / any other Nitro maintainers. It's been a little bit since I opened this PR, I think I opened it when I was on alpha.2. I should have some time this month to rework this if there's anything that needs to be fixed or changed, I would love to try to get this in for the next beta release. Or if we needed to wait for more things to go into the beta before these preset-specific fixes go in that's fine too. Let me know if there's anything I can do to assist, more than happy to help.

@pi0
Copy link
Copy Markdown
Member

pi0 commented May 5, 2026

Hi dear @taylorfsteele thanks for patience and help on this PR. We have recently added actual lamda compatibility to srvx via toLambdaHandler, invokeLambdaHandler (docs) which preview command can leverage it this way nitro|vite preview will work out of the box.

@taylorfsteele
Copy link
Copy Markdown
Contributor Author

@pi0 Fantastic! I've gone ahead and updated this branch to use the srvx handlers, let me know what you think

@taylorfsteele taylorfsteele changed the title fix(aws-lambda): add preview command refactor(aws-lambda): add srvx lambda handlers May 6, 2026
@martinmiglio
Copy link
Copy Markdown

Re-tested the reworked PR (pkg.pr.new build, commit b2ab1cb) against the same minimal @tanstack/react-start repro from my earlier comment — aws-lambda prerender now crawls and exits cleanly. vercel and netlify also build green in the same setup. 👍

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.

Preview support for aws-lambda

3 participants