Skip to content

refactor(nitro): drop the dead !ctx operand in the v3 response hook - #796

Merged
HugoRCD merged 1 commit into
mainfrom
refactor/nitro-v3-dead-ctx-guard
Oct 9, 2026
Merged

HugoRCD merged 1 commit into
mainfrom
refactor/nitro-v3-dead-ctx-guard

Conversation

@evlogai

@evlogai evlogai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

In the nitro-v3 response hook (packages/evlog/src/nitro-v3/plugin.ts), the guard

if (ctx?._evlogEmitted || ctx?._evlogEmitting || !ctx?._evlogShouldEmit) return

const log = ctx?.log as RequestLogger | undefined
if (!log || !ctx) return

already returns when ctx is undefined: with ctx undefined, !ctx?._evlogShouldEmit is true, so control never reaches the second guard. The !ctx operand is therefore dead, and once it is gone the ?. on ctx?.log is dead with it (TypeScript narrows ctx past the compound guard, confirmed by pnpm run typecheck). The same shape already exists in the error hook two functions below, which reads ctx.log after if (!ctx?._evlogShouldEmit) return.

-    const log = ctx?.log as RequestLogger | undefined
-    if (!log || !ctx) return
+    const log = ctx.log as RequestLogger | undefined
+    if (!log) return

Behavior is preserved. The nitro-v3 integration suite (test/nitro-v3/nitro-v3.test.ts) is the matching test: it drives the response hook through h3 v2's real request driver, including the filtered-out and already-emitted branches this guard serves.

Checks

  • pnpm --filter evlog exec vitest run test/nitro-v3/: 5 files, 29 tests passed with the edit.
  • pnpm run lint, pnpm run typecheck, pnpm run test: all exit 0 with the edit (96 files, 2,014 tests). Typecheck is the load-bearing one here: it proves ctx is narrowed so the non-optional ctx.log and the later ctx._evlogStartTime read inside emitSuccessResponse stay valid.
  • No changeset: dead-code removal with no observable consumer change (per AGENTS.md).

Found by the repo-health sweep at revision 54dcc504; confirmed by the workflow's verifier and reproduced in the sandbox.

Note: this touches plugin.ts lines 246-247, just above the region PR #795 refactors; if #795 merges first this rebases cleanly, and vice versa.

ELI5

One safety check in the v3 request logger asked the same question twice in a row, and the second ask could never fail because the first had already handled it. Removing the repeated check makes the code read straight through; the automated tests confirm nothing changed at runtime.

The compound guard two lines above already returns when ctx is
undefined, so the !ctx check in the log guard is unreachable and
ctx?.log can read ctx.log directly.
@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
evi Ready Ready Preview Oct 9, 2026 8:22am UTC
evlog-telemetry Ready Ready Preview Oct 9, 2026 8:22am UTC
3 Skipped Deployments
Project Deployment Actions Updated
evlog-docs Skipped Skipped v0 Oct 9, 2026 8:22am UTC
evlog-render-lab Skipped Skipped Oct 9, 2026 8:22am UTC
just-use-evlog Skipped Skipped Oct 9, 2026 8:22am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 175f7f0a-ddd6-416d-a757-498b4f7b22fa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • 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

Comment @coderabbitai help to get the list of available commands.

@github-actions
github-actions Bot requested a review from HugoRCD October 9, 2026 08:20
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026

Copy link
Copy Markdown
@evlog/cli

npm i https://pkg.pr.new/@evlog/cli@796

evlog

npm i https://pkg.pr.new/evlog@796

@evlog/nuxthub

npm i https://pkg.pr.new/@evlog/nuxthub@796

@evlog/signals

npm i https://pkg.pr.new/@evlog/signals@796

@evlog/telemetry

npm i https://pkg.pr.new/@evlog/telemetry@796

commit: 92e5acc

@HugoRCD
HugoRCD merged commit b369837 into main Oct 9, 2026
20 checks passed
@HugoRCD
HugoRCD deleted the refactor/nitro-v3-dead-ctx-guard branch October 9, 2026 20:19

This branch was successfully deployed

2 active and 3 inactive deployments
Preview – evlog-telemetry — 92e5acca Deployed Oct 9, 2026 by vercel[bot]
Preview – evi — 92e5acca Deployed Oct 9, 2026 by vercel[bot]
Preview – evlog-render-lab — 92e5acca Deployed Oct 9, 2026 by vercel[bot]
Preview – just-use-evlog — 92e5acca Deployed Oct 9, 2026 by vercel[bot]
Preview – evlog-docs — 92e5acca Deployed Oct 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant