Skip to content

fix(prerender): skip fastResponse on Bun and fail on rejected routes - #5186

Open
aloneangel45 wants to merge 1 commit into
nitrojs:mainfrom
aloneangel45:fix/5184-bun-prerender-errors
Open

aloneangel45 wants to merge 1 commit into
nitrojs:mainfrom
aloneangel45:fix/5184-bun-prerender-errors

Conversation

@aloneangel45

Copy link
Copy Markdown

🔗 Linked issue

Resolves #5184

❓ 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

Fixes two issues uncovered by running prerender under Bun when a second srvx copy is bundled (#5184):

  1. Skip fast-response globalThis.Response swap on Bun and resolve "bun" condition during prerender:
    • Guard src/runtime/internal/polyfills/fast-response.ts with !("Bun" in globalThis) so Bun's native Response is never replaced with srvx's Node FastResponse wrapper even if a bundle resolved srvx via the node condition.
    • Prepend "bun" to exportConditions in prerendererConfig (src/prerender/prerender.ts) when running under Bun (process.versions.bun && nitro.options.node !== false) so the prerender bundle resolves the "bun" condition (e.g. srvx's Bun adapter), while preserving user overrides / "!bun" negations.
  2. Surface rejected route fetches/reads instead of exiting 0 with missing output:
    • Catch prerenderer.fetch(req) and res.arrayBuffer() rejections in generateRoute, record them in _route.error and failedRoutes, and emit "prerender:route" so "Prerendered 0 routes..." and prerender.failOnError reject as expected.
    • Check { errors } returned by runParallel so unexpected unhandled route errors also fail the build when failOnError is enabled or 0 routes were written.

📝 Checklist

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

@aloneangel45
aloneangel45 requested a review from pi0 as a code owner November 27, 2026 23:40
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@aloneangel45 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 Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The prerenderer now applies Bun-specific export conditions and records route fetch or response-body failures. The Response polyfill leaves Bun’s Response unchanged. Tests cover Bun and Node.js polyfill behavior and prerender build outcomes.

Changes: Prerender behavior

Layer / File(s) Summary
Bun runtime compatibility
src/prerender/prerender.ts, src/runtime/internal/polyfills/fast-response.ts, test/unit/fast-response.test.ts
When running on Bun with nitro.options.node !== false, the prerenderer prepends the bun export condition. The polyfill does not replace Bun’s Response. Tests cover Bun and Node.js behavior.
Route failure handling
src/prerender/prerender.ts, test/prerender/fail-on-error.test.ts, test/prerender/status-fixture/server.ts
Fetch and response-body errors are recorded on failed routes. The build checks errors returned by runParallel and throws the first error when failOnError is enabled or no routes were written. Tests exercise stream failures with and without successful routes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Issue 5033 reports that route-generation errors can be ignored, allowing the build to exit successfully. This change records fetch and response-body failures and checks errors returned by runParallel.

Possibly related PRs

  • nitrojs/nitro#4922: Both changes alter prerender build-failure decisions involving failOnError and ignored status codes.
  • nitrojs/nitro#5034: Both changes record route-generation errors and affect prerender build-failure behavior.
  • nitrojs/nitro#5135: Both changes attach route-generation errors to failed routes and affect the failOnError path.

Suggested labels: bug, prerender

Merge Risk: Minimal · up to 5d4b3

This change makes Bun prerendering work with the Response polyfill and records route fetch failures so they fail the build instead of passing silently. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(prerender): skip fastResponse on Bun and fail on rejected routes" follows the conventional commits format with type "fix" and scope "prerender". It describes both fixes in the changeset…
Description check Passed The description links issue #5184, marks the change as a bug fix, and explains both fixes. It covers the fast-response guard, the "bun" export condition in prerender.ts, and the route error handling i…
Linked Issues check Passed The only directly linked active issue is #5184. Its coding requirements are: (1) prevent or address the Bun response incompatibility that leaves prerender output unwritten, and (2) ensure rejected rou…
Out of Scope Changes check Passed Every changed file maps to the objectives of #5184. The fast-response guard and the bun export-condition change address the Bun incompatibility. The generateRoute error capture and the runParallel err…
Full details: Title check

Explanation

The title "fix(prerender): skip fastResponse on Bun and fail on rejected routes" follows the conventional commits format with type "fix" and scope "prerender". It describes both fixes in the changeset: skipping the fast-response Response swap on Bun and failing the build on rejected route fetches.

Full details: Description check

Explanation

The description links issue #5184, marks the change as a bug fix, and explains both fixes. It covers the fast-response guard, the "bun" export condition in prerender.ts, and the route error handling in generateRoute and runParallel, which match the changeset.

Full details: Linked Issues check

Explanation

The only directly linked active issue is #5184. Its coding requirements are: (1) prevent or address the Bun response incompatibility that leaves prerender output unwritten, and (2) ensure rejected route fetches count as failures so the build does not exit 0 with missing output. The PR addresses requirement (1) in two places. It guards src/runtime/internal/polyfills/fast-response.ts with !("Bun" in globalThis), so Bun's native Response is not replaced. It also prepends "bun" to exportConditions in src/prerender/prerender.ts when running under Bun with nitro.options.node !== false, so the prerender bundle resolves the Bun adapter. It addresses requirement (2) in generateRoute by catching prerenderer.fetch(req) and res.arrayBuffer() rejections, recording them in _route.error and failedRoutes, and emitting "prerender:route". It also checks the { errors } returned by runParallel, so failOnError and the zero-routes check fail the build. New tests in test/prerender/fail-on-error.test.ts, the status-fixture /stream-error route, and test/unit/fast-response.test.ts cover the rejection and polyfill behavior. The issue lists the nested NodeResponse unwrap in toNativeResponse as one possible fix, but it is not a required outcome, and the PR does not need it. This assessment relies on the AI-generated PR summary and the PR description; I did not re-read the source hunks.

Full details: Out of Scope Changes check

Explanation

Every changed file maps to the objectives of #5184. The fast-response guard and the bun export-condition change address the Bun incompatibility. The generateRoute error capture and the runParallel error check address silent failure. The test and fixture changes (fail-on-error.test.ts, status-fixture/server.ts, unit/fast-response.test.ts) support those behaviors. The PR does not add unrelated functional changes according to the summary. The summary is AI-generated, and I did not inspect the diff hunks to confirm it, so the assessment depends on that summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • 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

Recent review info

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: c40df039-c350-4c4b-b6f3-250152053d35
Commits

Reviewing files that changed from the base of the PR and between 925c135 and 5d4b308.

Files selected for processing: 5

  • src/prerender/prerender.ts
  • src/runtime/internal/polyfills/fast-response.ts
  • test/prerender/fail-on-error.test.ts
  • test/prerender/status-fixture/server.ts
  • test/unit/fast-response.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
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.

Prerender writes nothing under the Bun runtime when the app bundles a second srvx copy (fastResponse polyfill), and the build still exits 0

1 participant