You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(prerender): skip fastResponse on Bun and fail on rejected routes - #5186
📖 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):
Skip fast-responseglobalThis.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.
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.
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
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
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
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Resolves #5184
❓ Type of change
📚 Description
Fixes two issues uncovered by running prerender under Bun when a second
srvxcopy is bundled (#5184):fast-responseglobalThis.Responseswap on Bun and resolve"bun"condition during prerender:src/runtime/internal/polyfills/fast-response.tswith!("Bun" in globalThis)so Bun's nativeResponseis never replaced withsrvx's NodeFastResponsewrapper even if a bundle resolvedsrvxvia thenodecondition."bun"toexportConditionsinprerendererConfig(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.prerenderer.fetch(req)andres.arrayBuffer()rejections ingenerateRoute, record them in_route.errorandfailedRoutes, and emit"prerender:route"so"Prerendered 0 routes..."andprerender.failOnErrorreject as expected.{ errors }returned byrunParallelso unexpected unhandled route errors also fail the build whenfailOnErroris enabled or 0 routes were written.📝 Checklist