Skip to content

fix(first-party): inject proxy endpoints for boolean/mock registry entries - #640

Merged
harlan-zw merged 2 commits into
nuxt:mainfrom
oritwoen:fix/auto-inject-boolean-registry
Mar 13, 2026
Merged

fix(first-party): inject proxy endpoints for boolean/mock registry entries#640
harlan-zw merged 2 commits into
nuxt:mainfrom
oritwoen:fix/auto-inject-boolean-registry

Conversation

@oritwoen

Copy link
Copy Markdown
Contributor

autoInjectProxyEndpoints skips registry scripts configured with boolean shorthand (posthog: true) or mock mode (posthog: 'mock'). The typeof entry !== 'object' guard bails before injecting apiHost/endpoint/hostUrl into runtimeConfig, so the SDK connects directly to third-party servers instead of going through the first-party proxy.

Traced the flow: module.ts creates runtimeConfig.public.scripts.posthog = { apiKey: '' } from REGISTRY_ENV_DEFAULTS, but config.registry.posthog stays true. When autoInjectProxyEndpoints runs, it sees typeof true !== 'object' and skips. The runtimeConfig entry never gets apiHost, so PostHog SDK defaults to https://us.i.posthog.com.

The fix handles true and 'mock' entries by computing the proxy endpoint value against a temporary empty config, then writing only to the runtimeConfig entry. The boolean in the registry stays untouched.

Affects all five scripts with auto-inject definitions: PostHog, Plausible, Umami, Rybbit, Databuddy.

Added 16 unit tests covering object/array/boolean/mock entries, empty arrays, falsy entries, custom prefixes, and EU region handling.

@vercel

vercelBot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

@oritwoen is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-newBot commented Mar 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@640

commit: 94c2bf4

@coderabbitai

coderabbitaiBot commented Mar 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR changes auto-injection logic in src/first-party/auto-inject.ts: registry entries are now skipped only when falsy; object entries (or first element of arrays) are processed as configs, while true or 'mock' entries derive configs from runtimeConfig or default to empty. computeValue is invoked and assigned to config fields only for object entries; when a runtimeConfig entry is present and is an object, the computed value is written into runtimeConfig instead. A comprehensive unit test suite was added at test/unit/auto-inject.test.ts covering objects, arrays, booleans, "mock", custom prefixes, and edge cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 50.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check❓ InconclusiveThe description explains the problem, root cause, and solution clearly, but is missing the required template sections like linked issue and type of change checkboxes.Fill out the remaining PR template sections: add linked issue if applicable, and check the appropriate type of change box (likely 'Bug fix').
✅ Passed checks (1 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly and concisely identifies the main fix: handling boolean/mock registry entries in proxy endpoint injection.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

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 the current code and only fix it if needed.
Inline comments:
In `@src/first-party/auto-inject.ts`:
- Around line 57-68: The bug is that when handling shorthand entries (entry ===
true || entry === 'mock') the code sets config = {} so
def.computeValue(collectPrefix, config) cannot see
runtimeConfig.public.scripts.posthog.region; change the shorthand branch to set
config to the runtime config for that integration (e.g. config =
runtimeConfig.public?.scripts?.posthog ?? {}) or merge the runtime region into
the empty config before calling def.computeValue so def.computeValue and
def.configField see the runtime-provided region; then add a regression test that
uses a shorthand entry (posthog: true) with rt.public.scripts.posthog.region =
'eu' and assert the injected path uses /ph-eu.
🪄 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: CHILL

Plan: Pro

Run ID: 12cc6340-5149-495a-aa4d-f796acac5faa

📥 Commits

Reviewing files that changed from the base of the PR and between 6f313b7 and e0b5c05.

📒 Files selected for processing (2)
  • src/first-party/auto-inject.ts
  • test/unit/auto-inject.test.ts

Comment threadsrc/first-party/auto-inject.ts

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/first-party/auto-inject.ts (1)

76-84: Consider adding a fallback when runtimeConfig entry is missing for boolean/mock entries.

For boolean/'mock' entries, if runtimeConfig.public.scripts[registryKey] doesn't exist (e.g., rtEntry is undefined), the computed value is never assigned anywhere—lines 77 and 83 are both skipped.

In practice, this is mitigated by module.ts (lines 347-350) which populates runtimeConfig from REGISTRY_ENV_DEFAULTS before this function is called. However, as a defensive measure, consider initializing the runtimeConfig entry if it's missing.

🛡️ Optional defensive initialization
 if (typeof entry === 'object') {
config[def.configField] = value
}
// Propagate to runtimeConfig
- if (rtEntry && typeof rtEntry === 'object') {- if (rtConfig)- rtConfig[def.configField] = value+ if (rtScripts) {+ if (rtEntry && typeof rtEntry === 'object') {+ if (rtConfig)+ rtConfig[def.configField] = value+ }+ else if (entry === true || entry === 'mock') {+ // Initialize runtimeConfig entry if missing for boolean/mock entries+ rtScripts[def.registryKey] = { [def.configField]: value }+ }
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/first-party/auto-inject.ts` around lines 76 - 84, The computed
boolean/'mock' values are never written when rtEntry is missing; modify the
logic in auto-inject.ts around config[def.configField], rtEntry, rtConfig and
registryKey to defensively initialize the runtimeConfig entry: if rtEntry is
falsy and rtConfig exists, create rtConfig.public ||= { scripts: {} } (or the
minimal path needed) and set rtConfig.public.scripts[registryKey] (or
rtConfig[def.configField] as appropriate) to the computed value before or
instead of the existing conditional, so boolean/'mock' entries always propagate
to runtimeConfig even when the rtEntry was undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/first-party/auto-inject.ts`:
- Around line 76-84: The computed boolean/'mock' values are never written when
rtEntry is missing; modify the logic in auto-inject.ts around
config[def.configField], rtEntry, rtConfig and registryKey to defensively
initialize the runtimeConfig entry: if rtEntry is falsy and rtConfig exists,
create rtConfig.public ||= { scripts: {} } (or the minimal path needed) and set
rtConfig.public.scripts[registryKey] (or rtConfig[def.configField] as
appropriate) to the computed value before or instead of the existing
conditional, so boolean/'mock' entries always propagate to runtimeConfig even
when the rtEntry was undefined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66935aa2-2ce0-4132-8336-3f15873c2642

📥 Commits

Reviewing files that changed from the base of the PR and between e0b5c05 and 6e90d95.

📒 Files selected for processing (2)
  • src/first-party/auto-inject.ts
  • test/unit/auto-inject.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/auto-inject.test.ts

@harlan-zw

Copy link
Copy Markdown
Collaborator

Thank you 💚

@harlan-zw
harlan-zw merged commit 569eeeb into nuxt:mainMar 13, 2026
3 of 4 checks passed
@harlan-zwharlan-zw mentioned this pull request Apr 15, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@oritwoen@harlan-zw