Skip to content

Commit fefd9fe

Browse files
fix(deps): add support for unhead v3 (#795)
Co-authored-by: Harlan Wilton <harlan@harlanzw.com>
1 parent 90aced6 commit fefd9fe

14 files changed

Lines changed: 873 additions & 35 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dev": "nuxt dev playground",
2020
"dev:ssl": "nuxt dev playground --https",
2121
"dev:prepare": "pnpm -r dev:prepare && nuxt prepare && nuxt prepare playground && pnpm prepare:fixtures",
22-
"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",
22+
"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",
2323
"typecheck": "nuxt typecheck",
2424
"release": "pnpm build && bumpp -r --output=CHANGELOG.md",
2525
"lint": "eslint .",

‎packages/script/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"@types/google.maps": "^3.58.1",
8080
"@types/vimeo__player": "^2.18.3",
8181
"@types/youtube": "^0.1.0",
82-
"@unhead/vue": "^2.0.3",
82+
"@unhead/vue": "^2.0.3 || ^3.0.0",
8383
"posthog-js": "^1.0.0"
8484
},
8585
"peerDependenciesMeta": {

‎packages/script/src/assets.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
importtype{NitroConfig}from'nitropack'
21
import{addDevServerHandler,extendRouteRules,tryUseNuxt,useNuxt}from'@nuxt/kit'
32
import{createError,eventHandler,lazyEventHandler,setHeader}from'h3'
43
import{fetch}from'ofetch'
@@ -8,12 +7,6 @@ import { createStorage } from 'unstorage'
87

98
importfsDriverfrom'unstorage/drivers/fs-lite'
109

11-
declare module '@nuxt/schema'{
12-
interfaceNuxtHooks{
13-
'nitro:config': (config: NitroConfig)=>void|Promise<void>
14-
}
15-
}
16-
1710
constrenderedScript=newMap<string,{
1811
content: Buffer
1912
/**

‎packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsStaticMap.vue‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ const rootStyle = computed(() => ({
250250
overflow: 'hidden',
251251
}))
252252
253-
if (import.meta.server) {
253+
if (import.meta.server&&!useProxy) {
254254
useHead({
255255
link: [
256256
{
257257
rel: props.loading==='eager'?'preconnect':'dns-prefetch',
258-
href: useProxy?undefined:'https://maps.googleapis.com',
258+
href: 'https://maps.googleapis.com',
259259
},
260-
].filter(l=>l.href),
260+
],
261261
})
262262
}
263263

‎packages/script/src/runtime/composables/useScript.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
171171
thrownewError('useScript with partytown requires a src')
172172
}
173173
useHead({
174-
script: [{ src,type: 'text/partytown'}],
174+
script: [{ src,type: 'text/partytown'as'text/javascript'}],
175175
})
176176
constnuxtApp=useNuxtApp()asNuxtScriptsApp
177177
ensureScripts(nuxtApp)
@@ -238,10 +238,11 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
238238
// browser hint optimizations
239239
constnuxtApp=useNuxtApp()asNuxtScriptsApp
240240
constid=String(resolveScriptKey(input))
241-
options.head=options.head||injectHead()
241+
options.head=options.head||injectHead()asNonNullable<typeofoptions.head>
242242
if(!options.head){
243243
thrownewError('useScript() has been called without Nuxt context.')
244244
}
245+
constheadHooks=options.head.hooks!
245246
ensureScripts(nuxtApp)
246247
constexists=!!(nuxtApp.$scriptsasRecord<string,any>)?.[id]
247248

@@ -318,7 +319,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
318319
...ctx,
319320
trigger: typeoftrigger==='object' ? (triggerinstanceofPromise ? 'promise' : JSON.stringify(trigger)) : trigger,
320321
})
321-
options.head.hooks.hook('script:updated',(entry)=>{
322+
headHooks.hook('script:updated',(entry)=>{
322323
if(entry.script.id!==instance.id)
323324
return
324325
conststatus=entry.script.status
@@ -369,7 +370,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
369370
}
370371

371372
if(!nuxtApp._scripts[instance.id]){
372-
options.head.hooks.hook('script:updated',(ctx)=>{
373+
headHooks.hook('script:updated',(ctx)=>{
373374
if(ctx.script.id!==instance.id)
374375
return
375376
// convert the status to a timestamp
@@ -382,7 +383,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
382383
syncScripts()
383384
})
384385
// @ts-expect-error untyped
385-
options.head.hooks.hook('script:instance-fn',(ctx)=>{
386+
headHooks.hook('script:instance-fn',(ctx)=>{
386387
if(ctx.script.id!==instance.id||String(ctx.fn).startsWith('__v_'))
387388
return
388389
// log all events

‎packages/script/src/runtime/composables/useScriptEventPage.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function useScriptEventPage(onChange?: (payload: TrackedPage) => void) {
2222
// possibly no head update is needed
2323
newPromise(resolve=>setTimeout(resolve,100)),
2424
newPromise<void>((resolve)=>{
25-
stopDomWatcher=head.hooks.hook('dom:rendered',()=>resolve())
25+
stopDomWatcher=head.hooks!.hook('dom:rendered',()=>resolve())
2626
}),
2727
])
2828
.finally(stopDomWatcher)

0 commit comments

Comments
 (0)