Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/script/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ export default defineNuxtModule<ModuleOptions>({
const proxyHandlerPath = await resolvePath('./runtime/server/proxy-handler')
addServerHandler({ route: `${proxyPrefix}/**`, handler: proxyHandlerPath })

// In dev, sink Vercel Analytics insight POSTs to `/_vercel/insights/*` so
// they don't 404. Vercel's edge serves this path in production; locally
// there's no upstream, so we return 204 to keep the script happy.
if (nuxt.options.dev && config.registry?.vercelAnalytics) {
addServerHandler({
route: '/_vercel/insights/**',
handler: await resolvePath('./runtime/server/vercel-insights-sink'),
})
}
Comment on lines +530 to +538
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether the vercelAnalytics registry entry sets a dev-specific default trigger of 'manual'.
fd -t f 'vercel-analytics' packages/script/src/runtime/registry
rg -nP -C5 "vercelAnalytics|vercel-analytics" packages/script/src/runtime/registry

Repository: nuxt/scripts

Length of output: 1545


🏁 Script executed:

cat -n packages/script/src/runtime/registry/vercel-analytics.ts

Repository: nuxt/scripts

Length of output: 5887


Dev-only insights sink wiring looks correct, but verify trigger behavior matches PR description.

The guard on nuxt.options.dev && config.registry?.vercelAnalytics is right: after normalizeRegistryConfig a disabled entry (false) is filtered/falsy, and any truthy registration becomes a tuple, so the handler is registered exactly when expected. Route is registered before the later per-script serverHandlers loop, which is fine since vercelAnalytics doesn't declare its own handlers for this path.

However, the sink alone does not prevent the script from loading in dev. The registry sets trigger: 'client' (line 90 of vercel-analytics.ts), meaning the script will load on client hydration regardless of dev/prod. The PR description claims a dev trigger of "manual" to prevent loading, but that change is not presentβ€”the sink only prevents 404s on POST requests. Confirm both the trigger default and the sink land together, otherwise the script will still auto-load in dev as it currently does.

πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/script/src/module.ts` around lines 530 - 538, The dev-only insights
sink is registered correctly (nuxt.options.dev &&
config.registry?.vercelAnalytics) but the registry still sets trigger: 'client'
in vercel-analytics.ts (around the trigger on line ~90) so the script will
auto-load in dev; update the registry entry created in normalizeRegistryConfig
or in vercel-analytics.ts to set trigger: 'manual' when running in dev (or make
normalizeRegistryConfig convert a truthy dev-only vercelAnalytics entry to
['vercel-analytics', { trigger: 'manual' }]), and re-run the build so the sink
(runtime/server/vercel-insights-sink) plus the trigger change are delivered
together to prevent client auto-loading while keeping the POST sink for 204s.


const composables = [
'useScript',
'useScriptEventPage',
Expand Down
6 changes: 6 additions & 0 deletions packages/script/src/runtime/server/vercel-insights-sink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineEventHandler, setResponseStatus } from 'h3'

export default defineEventHandler((event) => {
setResponseStatus(event, 204)
return null
})
Loading