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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev": "nuxt dev playground",
"dev:ssl": "nuxt dev playground --https",
"dev:prepare": "pnpm -r dev:prepare && nuxt prepare && nuxt prepare playground && pnpm prepare:fixtures",
"prepare:fixtures": "nuxt prepare test/fixtures/basic && nuxt prepare test/fixtures/cdn && nuxt prepare test/fixtures/extend-registry && nuxt prepare test/fixtures/partytown && nuxt prepare test/fixtures/first-party && nuxt prepare test/fixtures/linkedin-insight && nuxt prepare test/fixtures/linkedin-insight-cdn && nuxt prepare test/fixtures/tiktok-pixel && nuxt prepare test/fixtures/calendly && nuxt prepare test/fixtures/calendly-cdn && nuxt prepare test/fixtures/ahrefs-analytics && nuxt prepare test/fixtures/ahrefs-analytics-cdn && nuxt prepare test/fixtures/usercentrics",
"prepare:fixtures": "nuxt prepare test/fixtures/basic && nuxt prepare test/fixtures/cdn && nuxt prepare test/fixtures/extend-registry && nuxt prepare test/fixtures/partytown && nuxt prepare test/fixtures/first-party && nuxt prepare test/fixtures/linkedin-insight && nuxt prepare test/fixtures/linkedin-insight-cdn && nuxt prepare test/fixtures/tiktok-pixel && nuxt prepare test/fixtures/calendly && nuxt prepare test/fixtures/calendly-cdn && nuxt prepare test/fixtures/ahrefs-analytics && nuxt prepare test/fixtures/ahrefs-analytics-cdn && nuxt prepare test/fixtures/usercentrics && nuxt prepare test/fixtures/unhead-v3",
"typecheck": "nuxt typecheck",
"release": "pnpm build && bumpp -r --output=CHANGELOG.md",
"lint": "eslint .",
Expand Down
2 changes: 1 addition & 1 deletion packages/script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@types/google.maps": "^3.58.1",
"@types/vimeo__player": "^2.18.3",
"@types/youtube": "^0.1.0",
"@unhead/vue": "^2.0.3",
"@unhead/vue": "^2.0.3 || ^3.0.0",
"posthog-js": "^1.0.0"
},
"peerDependenciesMeta": {
Expand Down
7 changes: 0 additions & 7 deletions packages/script/src/assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { NitroConfig } from 'nitropack'
import { addDevServerHandler, extendRouteRules, tryUseNuxt, useNuxt } from '@nuxt/kit'
import { createError, eventHandler, lazyEventHandler, setHeader } from 'h3'
import { fetch } from 'ofetch'
Expand All @@ -8,12 +7,6 @@ import { createStorage } from 'unstorage'

import fsDriver from 'unstorage/drivers/fs-lite'

declare module '@nuxt/schema' {
interface NuxtHooks {
'nitro:config': (config: NitroConfig) => void | Promise<void>
}
}

const renderedScript = new Map<string, {
content: Buffer
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ const rootStyle = computed(() => ({
overflow: 'hidden',
}))

if (import.meta.server) {
if (import.meta.server && !useProxy) {
useHead({
link: [
{
rel: props.loading === 'eager' ? 'preconnect' : 'dns-prefetch',
href: useProxy ? undefined : 'https://maps.googleapis.com',
href: 'https://maps.googleapis.com',
},
].filter(l => l.href),
],
})
}

Expand Down
11 changes: 6 additions & 5 deletions packages/script/src/runtime/composables/useScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
throw new Error('useScript with partytown requires a src')
}
useHead({
script: [{ src, type: 'text/partytown' }],
script: [{ src, type: 'text/partytown' as 'text/javascript' }],
})
const nuxtApp = useNuxtApp() as NuxtScriptsApp
ensureScripts(nuxtApp)
Expand Down Expand Up @@ -238,10 +238,11 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
// browser hint optimizations
const nuxtApp = useNuxtApp() as NuxtScriptsApp
const id = String(resolveScriptKey(input))
options.head = options.head || injectHead()
options.head = options.head || injectHead() as NonNullable<typeof options.head>
if (!options.head) {
throw new Error('useScript() has been called without Nuxt context.')
}
const headHooks = options.head.hooks!
ensureScripts(nuxtApp)
const exists = !!(nuxtApp.$scripts as Record<string, any>)?.[id]

Expand Down Expand Up @@ -318,7 +319,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
...ctx,
trigger: typeof trigger === 'object' ? (trigger instanceof Promise ? 'promise' : JSON.stringify(trigger)) : trigger,
})
options.head.hooks.hook('script:updated', (entry) => {
headHooks.hook('script:updated', (entry) => {
if (entry.script.id !== instance.id)
return
const status = entry.script.status
Expand Down Expand Up @@ -369,7 +370,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
}

if (!nuxtApp._scripts[instance.id]) {
options.head.hooks.hook('script:updated', (ctx) => {
headHooks.hook('script:updated', (ctx) => {
if (ctx.script.id !== instance.id)
return
// convert the status to a timestamp
Expand All @@ -382,7 +383,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
syncScripts()
})
// @ts-expect-error untyped
options.head.hooks.hook('script:instance-fn', (ctx) => {
headHooks.hook('script:instance-fn', (ctx) => {
if (ctx.script.id !== instance.id || String(ctx.fn).startsWith('__v_'))
return
// log all events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useScriptEventPage(onChange?: (payload: TrackedPage) => void) {
// possibly no head update is needed
new Promise(resolve => setTimeout(resolve, 100)),
new Promise<void>((resolve) => {
stopDomWatcher = head.hooks.hook('dom:rendered', () => resolve())
stopDomWatcher = head.hooks!.hook('dom:rendered', () => resolve())
}),
])
.finally(stopDomWatcher)
Expand Down
Loading
Loading