fix: Bun HTML imports returning empty object (#1771)#1788
fix: Bun HTML imports returning empty object (#1771)#1788NongTham wants to merge 5 commits intoelysiajs:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughMoved HTML bundle detection into a new Bun utils module, updated Bun adapter handlers to route HTML-bundle-shaped responses through Bun.file, removed the isHTMLBundle export from the adapter index, refactored hasElysiaMeta to a recursive check, and added tests for hasElysiaMeta and updated several tests to return shallow copies and adjusted expectations. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Adapter as BunAdapter
participant BunRuntime as Bun
participant FS as FileSystem
Client->>Adapter: send request
Adapter->>Adapter: mapResponse / mapEarlyResponse
alt response is HTML bundle (isHTMLBundle)
Adapter->>BunRuntime: call Bun.file(index)
BunRuntime->>FS: read file
FS-->>BunRuntime: file stream
BunRuntime-->>Adapter: file-based response
Adapter-->>Client: file-based response
else other response types
Adapter-->>Client: normal mapped response (JSON/String/FormData/Response/etc.)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/schema/schema-utils.test.ts (1)
175-176: Consider using ES module imports for consistency.The test file uses ES module imports elsewhere (
import { describe, it, expect } from 'bun:test'), buthasElysiaMetais imported viarequire. This creates inconsistency and may not benefit from static analysis or TypeScript type-checking.♻️ Suggested refactor
+import { hasElysiaMeta } from '../../src/schema' + describe('hasElysiaMeta', () => { - const { hasElysiaMeta } = require('../../src/schema') - it('finds elysiaMeta in Object properties even if placed after another property', () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/schema/schema-utils.test.ts` around lines 175 - 176, The test currently uses require to load hasElysiaMeta, causing inconsistent module syntax; replace the CommonJS require with an ES module import (e.g., add an import { hasElysiaMeta } from '../../src/schema' at the top of the test) so hasElysiaMeta is imported using the same ESM style as the rest of the file; update any existing require(...) reference in the describe('hasElysiaMeta', ...) block to use the imported symbol instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/adapter/bun/handler.ts`:
- Line 168: The mapEarlyResponse function currently returns new Response('')
when given undefined or null input, which breaks semantics—change the
early-return branch in src/adapter/bun/handler.ts (the guard that checks
response === undefined || response === null) to return undefined instead of new
Response(''), so mapEarlyResponse returns Response | undefined with undefined
preserved for null/undefined inputs and downstream checks like if (result) / if
(result !== undefined) behave correctly.
In `@src/adapter/bun/utils.ts`:
- Around line 1-8: The current isHTMLBundle duck-typing is too permissive
because it treats any object with a string index as an HTMLBundle; update
isHTMLBundle to require the existing toString() check OR both a string index and
a bundle-like property (e.g., a non-null object `files`) to better match
BunHTMLBundlelike. In other words, change the fallback from just `typeof
handle.index === 'string'` to `typeof handle.index === 'string' && typeof
handle.files === 'object' && handle.files !== null` (keep the original
toString() check) so the function `isHTMLBundle` only returns true for real
bundle-like shapes.
---
Nitpick comments:
In `@test/schema/schema-utils.test.ts`:
- Around line 175-176: The test currently uses require to load hasElysiaMeta,
causing inconsistent module syntax; replace the CommonJS require with an ES
module import (e.g., add an import { hasElysiaMeta } from '../../src/schema' at
the top of the test) so hasElysiaMeta is imported using the same ESM style as
the rest of the file; update any existing require(...) reference in the
describe('hasElysiaMeta', ...) block to use the imported symbol instead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 513afe18-978a-4ba9-8095-c4afe9f7438d
📒 Files selected for processing (6)
src/adapter/bun/handler-native.tssrc/adapter/bun/handler.tssrc/adapter/bun/index.tssrc/adapter/bun/utils.tssrc/schema.tstest/schema/schema-utils.test.ts
commit: |
This PR addresses a regression introduced during the transition to the system-level router (optimized in recent versions), where Bun's native
HTMLBundleobjects were no longer correctly identified during the response lifecycle, resulting in an empty JSON object{}fallback.Changes:
HTMLBundleUtility: Introduced a robust detection utility insrc/adapter/bun/utils.tsto replace localized and potentially fragiletoStringchecks. This ensures reliable identification of imported HTML files across all deployment environments, including compiled or minified production builds.mapResponse,mapEarlyResponse, andmapCompactResponse. This ensures that anyHTMLBundlereturned from a handler is correctly recognized and served via Bun's high-performance file-serving path (handleFile).(Note: This regression likely stemmed from the shift toward manual route handling for performance optimizations. Physical verification confirms that static, hook-based, and pure dynamic handlers now correctly serve imported HTML content with appropriate headers.)
Summary by CodeRabbit
Improvements
API
Tests