Skip to content

fix(nitro): scope runtime config probes to active major version#340

Open
HugoRCD wants to merge 4 commits into
mainfrom
fix/nitro-bridge-active-runtime
Open

fix(nitro): scope runtime config probes to active major version#340
HugoRCD wants to merge 4 commits into
mainfrom
fix/nitro-bridge-active-runtime

Conversation

@HugoRCD
Copy link
Copy Markdown
Owner

@HugoRCD HugoRCD commented May 10, 2026

🔗 Linked issue

Closes #312

📚 Description

On Vercel + Bun + Nitro v3, every request crashed with bun is unable to write files: ReadOnlyFileSystem. Root cause: the shared config bridge probed nitropack/runtime/internal/config even though only nitro (v3) was installed. Bun's auto-install kicked in on the missing dynamic import and tried to write node_modules/.cache, which is read-only on Vercel functions.

The fix introduces an internal setActiveNitroRuntime('v2' | 'v3') declaration. Both Nitro plugins call it as their first synchronous statement, and the bridge probes only the matching runtime — nitro/runtime-config for v3, nitropack/... for v2. Adapters resolving config through runtimeConfig.evlog.<adapter> benefit from the same restriction, so createPostHogDrain() (and any resolveAdapterConfig consumer) no longer triggers cross-version probes.

process.env.__EVLOG_CONFIG remains the highest-priority lookup; the historical fallback chain still applies when no runtime has been declared (standalone use outside Nitro).

No public-API change.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented a runtime crash on Vercel + Bun by avoiding runtime probing that triggered writes to a read-only filesystem.
  • New Features

    • Evlog configuration is now inlined into Nitro bundles at build time so runtime resolution no longer depends on probing deployed bundles.
  • Tests

    • Added tests covering runtime configuration resolution and fallback behavior across Nitro versions and env fallbacks.

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

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

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 May 21, 2026 8:00pm
just-use-evlog Ready Ready Preview, Comment May 21, 2026 8:00pm

@github-actions github-actions Bot added the bug Something isn't working label May 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 10, 2026

Thank you for following the naming conventions! 🙏

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

📝 Walkthrough

Walkthrough

Evlog inlines module config into Nitro bundles via EVLOG_CONFIG and adds setActiveNitroRuntime so the shared bridge reads inlined config first and probes only the declared Nitro major runtime (v2 or v3), avoiding cross-version dynamic imports at runtime.

Changes

Nitro Runtime Version Activation for Config Probing

Layer / File(s) Summary
Runtime state & inline config docs
packages/evlog/src/shared/nitroConfigBridge.ts
Adds documentation of lookup order and introduces module-level activeNitroRuntime state and inline-config handling.
Inline config extraction & runtime setters
packages/evlog/src/shared/nitroConfigBridge.ts
Exports readEvlogConfigFromInline(), setActiveNitroRuntime(version) and resetActiveNitroRuntime(); declares guarded __EVLOG_CONFIG__ access.
Config resolution and runtime-record logic
packages/evlog/src/shared/nitroConfigBridge.ts
resolveEvlogConfigForNitroPlugin() now prefers inlined/global env, then process.env.__EVLOG_CONFIG, then probes only the runtime selected by activeNitroRuntime; getNitroRuntimeConfigRecord() returns a synthetic { evlog: <inline> } when inlined and otherwise returns only the matching runtime's useRuntimeConfig() or historical fallback when unset.
Plugin runtime activation
packages/evlog/src/nitro/plugin.ts, packages/evlog/src/nitro-v3/plugin.ts
Both modules import and call setActiveNitroRuntime() early ('v2' for v2, 'v3' for v3) before resolving evlog config.
Bundle-time injection
packages/evlog/src/nitro/module.ts, packages/evlog/src/nitro-v3/module.ts, .changeset/nitro-bridge-active-runtime.md
Add nitro.options.replace.__EVLOG_CONFIG__ JSON literal injection so evlog options are baked into Nitro bundles; changeset documents the patch release and Vercel+Bun fix.
Tests: resolution precedence & probing behavior
packages/evlog/test/shared/nitroConfigBridge.test.ts
Adds Vitest harness and tests that assert v3-only and v2-only probing when active, env/global inline precedence, ignoring non-object inlined values, and historical fallback when no runtime declared.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: scoping runtime config probes to the active Nitro major version to avoid cross-version module resolution.
Description check ✅ Passed The description includes linked issue, detailed explanation of the problem and solution, and follows the required template structure with completed checklist items.
Linked Issues check ✅ Passed All objectives from #312 are addressed: scoped probes, inline config via nitro.options.replace, adapter restriction, env precedence, and fallback preservation without public API changes.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: Nitro plugin runtime activation, config bridge scoping, inline config injection, and corresponding test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nitro-bridge-active-runtime

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 10, 2026

Benchmark report

Bundle size

Threshold: 5% · 🔴 larger · 🟡 warning · 🟢 smaller · ⚪ unchanged · 🆕 new

Status Entry Base (gzip) Current (gzip) Change Raw delta
🟡 framework/nitro 7.16 kB 7.31 kB +2.0% +574 B
framework/express 727 B 739 B +1.7% +49 B
framework/nestjs 1.25 kB 1.26 kB +0.4% +41 B
toolkit 781 B 783 B +0.3% 0 B
adapter/better-stack 1.26 kB 1.26 kB +0.2% 0 B
framework/fastify 1.02 kB 1.02 kB +0.2% 0 B
framework/hono 615 B 616 B +0.2% 0 B
adapter/axiom 1.50 kB 1.50 kB +0.1% 0 B
adapter/otlp 2.14 kB 2.14 kB +0.1% 0 B
core (index) 2.15 kB 2.16 kB +0.1% 0 B
adapter/hyperdx 1.18 kB 1.18 kB +0.1% 0 B
adapter/datadog 2.48 kB 2.48 kB +0.1% 0 B
workers 1.30 kB 1.31 kB +0.1% 0 B
adapter/posthog 1.47 kB 1.47 kB +0.1% 0 B
framework/sveltekit 1.59 kB 1.59 kB +0.1% 0 B
adapter/sentry 2.40 kB 2.41 kB +0.0% 0 B
adapter/fs 3.35 kB 3.35 kB +0.0% 0 B
framework/next 5.20 kB 5.20 kB +0.0% 0 B
framework/ai 4.67 kB 4.67 kB 0.0% 0 B
framework/vite 2.40 kB 2.40 kB 0.0% 0 B
enrichers 1.99 kB 1.99 kB 0.0% 0 B
utils 1.58 kB 1.58 kB 0.0% 0 B
error 1.57 kB 1.57 kB 0.0% 0 B
pipeline 1.35 kB 1.35 kB 0.0% 0 B
framework/elysia 1.33 kB 1.33 kB 0.0% 0 B
http 1.24 kB 1.24 kB 0.0% 0 B
browser 289 B 289 B 0.0% 0 B
client 128 B 128 B 0.0% 0 B
types 31 B 31 B 0.0% 0 B
logger 229 B 225 B -1.7% 0 B
Total 54.33 kB 54.51 kB +0.3% +664 B

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 10, 2026

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

commit: 984193d

@HugoRCD
Copy link
Copy Markdown
Owner Author

HugoRCD commented May 10, 2026

@gtothesquare Can you try running npm i https://pkg.pr.new/evlog@340 using this pkg.pr.new and see if that fixes your issue?

@gtothesquare
Copy link
Copy Markdown

Can you try running npm i https://pkg.pr.new/evlog@340 using this pkg.pr.new and see if that fixes your issue?

@HugoRCD sorry for the late reply I was a week off without my computer. Still an issue, i (codex :) ) have created a minimal repo so you can reproduce https://github.com/gtothesquare/evlog-340-repo maybe there is something i did wrong in the setup.

Seems like it still has to do a runtime dynamic import to get config

The Nitro plugin's runtime probe of `nitro/runtime-config` transitively
imports `#nitro/virtual/runtime-config`, a build-only virtual module
that does not exist in deployed bundles. On Vercel + Bun the missing
virtual triggered Bun's package auto-installer and crashed every request
with `ReadOnlyFileSystem`. The previous `setActiveNitroRuntime` fix
only narrowed which runtime to probe — the v3 probe itself still ran
and still crashed.

Bake the evlog config into the bundle as a literal via
`nitro.options.replace.__EVLOG_CONFIG__`. The shared bridge reads that
literal first and short-circuits all runtime probing — both for the
plugin (`resolveEvlogConfigForNitroPlugin`) and for adapters resolving
through `useRuntimeConfig().evlog.<ns>` (`getNitroRuntimeConfigRecord`
returns a synthetic record). No dynamic import, no env propagation
guesswork.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/nitro-bridge-active-runtime.md:
- Line 5: Add a top-level H1 heading immediately after the existing frontmatter
to satisfy markdownlint rule MD041; update the .changeset markdown so it
contains a single-line H1 (e.g., "# Nitro bridge active runtime") right after
the YAML frontmatter block to remove the lint warning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c2bd96d5-a540-433a-b81d-1b28418a07d9

📥 Commits

Reviewing files that changed from the base of the PR and between add960c and 984193d.

📒 Files selected for processing (5)
  • .changeset/nitro-bridge-active-runtime.md
  • packages/evlog/src/nitro-v3/module.ts
  • packages/evlog/src/nitro/module.ts
  • packages/evlog/src/shared/nitroConfigBridge.ts
  • packages/evlog/test/shared/nitroConfigBridge.test.ts

Comment thread .changeset/nitro-bridge-active-runtime.md
@HugoRCD
Copy link
Copy Markdown
Owner Author

HugoRCD commented May 21, 2026

Can you try running npm i https://pkg.pr.new/evlog@340 using this pkg.pr.new and see if that fixes your issue?

@HugoRCD sorry for the late reply I was a week off without my computer. Still an issue, i (codex :) ) have created a minimal repo so you can reproduce gtothesquare/evlog-340-repo maybe there is something i did wrong in the setup.

Seems like it still has to do a runtime dynamic import to get config

Could you try again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Evlog Nitro v3 adapter triggers Bun package-manager cache writes on Vercel runtime

2 participants