feat(bunny): add support for native waitUntil#186
Conversation
📝 WalkthroughWalkthroughThis PR refactors the Bunny adapter to introduce a public Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/adapters/bunny.ts`:
- Around line 46-50: Guard accesses to the unstable namespace and avoid
duplicating the lambda: change uses of Bunny.unstable.waitUntil to use optional
chaining (e.g., Bunny.unstable?.waitUntil) and make this.waitUntil a safe
wrapper that checks Bunny.unstable before calling it; then reuse this.waitUntil
when defining request.waitUntil inside fetch instead of redefining the arrow
function. Update symbols: Bunny.unstable, this.waitUntil, fetch, and the
request.waitUntil property to perform a no-op or safe call when Bunny.unstable
is undefined.
| this.waitUntil = (promise: Promise<unknown>) => Bunny.unstable.waitUntil(promise); | ||
|
|
||
| this.fetch = (request: Request) => { | ||
| Object.defineProperties(request, { | ||
| waitUntil: { value: this.#wait?.waitUntil }, | ||
| waitUntil: { value: (promise: Promise<unknown>) => Bunny.unstable.waitUntil(promise) }, |
There was a problem hiding this comment.
Missing null-safety guard for Bunny.unstable; duplicate lambda.
Two concerns here:
1. No guard for Bunny.unstable (major): Bunny.unstable is accessed without optional chaining. Unlike Bunny.v1, which is guarded by Bunny.v1?.serve inside serve(), Bunny.unstable is never checked. If the runtime doesn't expose this namespace yet (e.g., on an older edge node during a phased rollout, or during local development with manual: true before serve() throws), any call to server.waitUntil() or request.waitUntil() from a request handler will throw TypeError: Cannot read properties of undefined (reading 'waitUntil'). Since the unstable namespace name itself signals it could be removed or absent, defensive access is warranted.
2. Duplicate lambda (optional): The same arrow function is defined twice — once at line 46 for this.waitUntil and again at line 50 for the request property. The fetch handler can simply reuse this.waitUntil.
🛡️ Proposed fix: optional chaining + dedup lambda
- this.waitUntil = (promise: Promise<unknown>) => Bunny.unstable.waitUntil(promise);
+ this.waitUntil = (promise: Promise<unknown>) => Bunny.unstable?.waitUntil(promise);
this.fetch = (request: Request) => {
Object.defineProperties(request, {
- waitUntil: { value: (promise: Promise<unknown>) => Bunny.unstable.waitUntil(promise) },
+ waitUntil: { value: this.waitUntil },
runtime: { enumerable: true, value: { name: "bunny" } },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/adapters/bunny.ts` around lines 46 - 50, Guard accesses to the unstable
namespace and avoid duplicating the lambda: change uses of
Bunny.unstable.waitUntil to use optional chaining (e.g.,
Bunny.unstable?.waitUntil) and make this.waitUntil a safe wrapper that checks
Bunny.unstable before calling it; then reuse this.waitUntil when defining
request.waitUntil inside fetch instead of redefining the arrow function. Update
symbols: Bunny.unstable, this.waitUntil, fetch, and the request.waitUntil
property to perform a no-op or safe call when Bunny.unstable is undefined.
waitUntilwaitUntil
Followup for #182
Summary by CodeRabbit
Release Notes
Bunny.unstable.waitUntilAPI surface for managing asynchronous operationswaitUntilmethod