Skip to content

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

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

fix(nitro): scope runtime config probes to active major version#340
HugoRCD wants to merge 2 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

    • Fixed a runtime crash on Vercel when using Bun with Nitro v3 by preventing unnecessary dependency probing that caused Bun to attempt writing to the read-only filesystem.
  • Tests

    • Added test coverage for Nitro runtime configuration resolution logic.

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 10, 2026 7:03pm
just-use-evlog Ready Ready Preview, Comment May 10, 2026 7:03pm

@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 78373867-a724-4e41-b07f-a852d22aa779

📥 Commits

Reviewing files that changed from the base of the PR and between 62c3d49 and add960c.

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

📝 Walkthrough

Walkthrough

Evlog patches its Nitro runtime config bridge to declare the active major version (v2 or v3) early in plugin startup, so the bridge probes only the matching runtime module instead of attempting both. This prevents Bun from auto-installing missing optional dependencies on Vercel's read-only filesystem.

Changes

Nitro Runtime Version Activation for Config Probing

Layer / File(s) Summary
Runtime Version State & Setter Functions
packages/evlog/src/shared/nitroConfigBridge.ts
Introduces internal activeNitroRuntime state ('v2' | 'v3') and exports setActiveNitroRuntime(version) and resetActiveNitroRuntime() to control which runtime version is active at startup.
Conditional Config & Runtime Record Resolution
packages/evlog/src/shared/nitroConfigBridge.ts
resolveEvlogConfigForNitroPlugin() now probes only the declared runtime module (v3 probes nitro/runtime-config, v2 probes nitropack/...) after checking process.env.__EVLOG_CONFIG. getNitroRuntimeConfigRecord() returns config from only the declared runtime, falling back to v2-then-v3 order when no runtime is declared.
Nitro v2 & v3 Plugin Integration
packages/evlog/src/nitro/plugin.ts, packages/evlog/src/nitro-v3/plugin.ts
Both plugins call setActiveNitroRuntime() at startup ('v2' for v2, 'v3' for v3) before config resolution, ensuring the config bridge probes only the installed runtime.
Tests & Documentation
packages/evlog/test/shared/nitroConfigBridge.test.ts, .changeset/nitro-bridge-active-runtime.md
Test suite verifies v3-only and v2-only probing behavior, env-config fast path, and fallback behavior when no runtime is declared. Changeset documents the fix for the Vercel + Bun + Nitro v3 runtime crash.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 'fix(nitro): scope runtime config probes to active major version' directly and specifically describes the main change: scoping runtime config probes to the active Nitro major version to prevent cross-version module loading.
Description check ✅ Passed The description follows the template structure with linked issue, detailed explanation of the problem and fix, and a completed checklist that acknowledges documentation was not updated.
Linked Issues check ✅ Passed The PR directly addresses all coding objectives from issue #312: preventing Nitro v3 from probing v2 modules, allowing config passed at build-time without triggering imports, preserving fallback behavior outside Nitro, and fixing the Vercel+Bun read-only filesystem crash via the setActiveNitroRuntime mechanism.
Out of Scope Changes check ✅ Passed All changes directly support the scope of issue #312: the setActiveNitroRuntime helper, plugin updates to declare their version, runtime config bridge scoping, and comprehensive tests validating the fix—no unrelated modifications detected.

✏️ 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/express 727 B 739 B +1.7% +49 B
framework/nitro 7.16 kB 7.21 kB +0.7% +116 B
framework/nestjs 1.25 kB 1.26 kB +0.2% +41 B
adapter/better-stack 1.26 kB 1.26 kB +0.2% 0 B
adapter/posthog 1.47 kB 1.47 kB +0.1% 0 B
adapter/axiom 1.50 kB 1.50 kB +0.1% 0 B
adapter/otlp 2.14 kB 2.14 kB +0.0% 0 B
adapter/datadog 2.48 kB 2.48 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
adapter/fs 3.35 kB 3.35 kB 0.0% 0 B
adapter/sentry 2.40 kB 2.40 kB 0.0% 0 B
framework/vite 2.40 kB 2.40 kB 0.0% 0 B
core (index) 2.15 kB 2.15 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
workers 1.30 kB 1.30 kB 0.0% 0 B
http 1.24 kB 1.24 kB 0.0% 0 B
adapter/hyperdx 1.18 kB 1.18 kB 0.0% 0 B
framework/fastify 1.02 kB 1.02 kB 0.0% 0 B
toolkit 781 B 781 B 0.0% 0 B
framework/hono 615 B 615 B 0.0% 0 B
browser 289 B 289 B 0.0% 0 B
logger 229 B 229 B 0.0% 0 B
client 128 B 128 B 0.0% 0 B
types 31 B 31 B 0.0% 0 B
framework/sveltekit 1.59 kB 1.59 kB -0.1% 0 B
Total 54.33 kB 54.40 kB +0.1% +206 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: e11a13d

@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?

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

1 participant