Remove await-thenable lint rule and fix invalid await usage#1353
Remove await-thenable lint rule and fix invalid await usage#1353nickspaargaren wants to merge 4 commits intoh3js:mainfrom
await-thenable lint rule and fix invalid await usage#1353Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRemoved a lint override from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
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 Tip You can enable review details to help with troubleshooting, context usage and more.Enable the |
commit: |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/utils/proxy.ts (1)
21-21:⚠️ Potential issue | 🔴 CriticalBreaking change:
onResponsecallback can be async but is no longer awaited.The
ProxyOptions.onResponsetype signature=> voiddoesn't prevent async functions—TypeScript allowsasync () => void. The existing test attest/proxy.test.ts:458-472explicitly uses an asynconResponsethat returns a Promise:onResponse(_event) { return new Promise((resolve) => { resolve(event.res.headers.set("x-custom", "hello")); }); }With
awaitremoved at line 132, this Promise is fire-and-forget, causing the response to be returned beforeonResponsecompletes. This is inconsistent withH3Config.onResponse(src/types/h3.ts:40), which usesMaybePromise<void>and is awaited viaPromise.resolve().then()in src/response.ts:29, and with theonResponsemiddleware (src/utils/middleware.ts:27), which awaits the callback.To fix while preserving async support:
- Update the type to explicitly allow async callbacks:
onResponse?: (event: H3Event, response: Response) => void | Promise<void>;- Add await at line 132:
await opts.onResponse(event, response);Proposed fix
export interface ProxyOptions { headers?: HeadersInit; forwardHeaders?: string[]; filterHeaders?: string[]; fetchOptions?: RequestInit & { duplex?: "half" | "full" }; cookieDomainRewrite?: string | Record<string, string>; cookiePathRewrite?: string | Record<string, string>; - onResponse?: (event: H3Event, response: Response) => void; + onResponse?: (event: H3Event, response: Response) => void | Promise<void>; }if (opts.onResponse) { - opts.onResponse(event, response); + await opts.onResponse(event, response); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/proxy.ts` at line 21, ProxyOptions.onResponse currently allows async callbacks but the implementation no longer awaits them, causing fire-and-forget behavior; update the onResponse type signature to explicitly allow promises (onResponse?: (event: H3Event, response: Response) => void | Promise<void>) and restore awaiting the callback where it is invoked (await opts.onResponse(event, response)); modify the type for ProxyOptions.onResponse and change the invocation of opts.onResponse to be awaited so async handlers complete before the response is returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/utils/proxy.ts`:
- Line 21: ProxyOptions.onResponse currently allows async callbacks but the
implementation no longer awaits them, causing fire-and-forget behavior; update
the onResponse type signature to explicitly allow promises (onResponse?: (event:
H3Event, response: Response) => void | Promise<void>) and restore awaiting the
callback where it is invoked (await opts.onResponse(event, response)); modify
the type for ProxyOptions.onResponse and change the invocation of
opts.onResponse to be awaited so async handlers complete before the response is
returned.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5a0fd54c-ee04-4ddf-b199-3e11b90d10da
📒 Files selected for processing (4)
.oxlintrc.jsonsrc/utils/proxy.tstest/bench/bench.test.tstest/happydom.test.ts
💤 Files with no reviewable changes (1)
- .oxlintrc.json
This PR removes the
typescript/await-thenablelint rule and updates a few call sites that were incorrectly usingawait,Why
await-thenable.How to test
pnpm testpnpm lintSummary by CodeRabbit