Skip to content

Commit 985ab11

Browse files
committed
fix: broken $script write
1 parent 9384e18 commit 985ab11

15 files changed

+491
-3
lines changed

src/runtime/composables/useScript.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ import { resolveTrigger } from '#build/nuxt-scripts-trigger-resolver'
55
import { useScript as _useScript } from '@unhead/vue/scripts'
66
import { defu } from 'defu'
77
import { injectHead, onNuxtReady, useHead, useNuxtApp, useRuntimeConfig } from 'nuxt/app'
8-
import { reactive, ref } from 'vue'
8+
import { ref } from 'vue'
99
import { logger } from '../logger'
1010

1111
type NuxtScriptsApp = ReturnType<typeof useNuxtApp> & {
1212
$scripts: Record<string, UseScriptContext<any> | undefined>
1313
_scripts: Record<string, NuxtDevToolsScriptInstance>
1414
}
1515

16+
function ensureScripts(nuxtApp: NuxtScriptsApp) {
17+
// When registry scripts are configured, the plugin provides $scripts via Nuxt's
18+
// provide() which creates a getter-only property. We must not reassign it.
19+
// When no plugin provides it, we need to initialize it ourselves.
20+
if (!nuxtApp.$scripts) {
21+
nuxtApp.$scripts = {}
22+
}
23+
}
24+
1625
function useNuxtScriptRuntimeConfig() {
1726
return useRuntimeConfig().public['nuxt-scripts'] as {
1827
defaultScriptOptions: NuxtUseScriptOptions
@@ -39,7 +48,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
3948
})
4049
// Register with nuxtApp.$scripts for DevTools visibility
4150
const nuxtApp = useNuxtApp() as NuxtScriptsApp
42-
nuxtApp.$scripts = nuxtApp.$scripts! || reactive({})
51+
ensureScripts(nuxtApp)
4352
const status = ref('loaded')
4453
const stub = {
4554
id: src,
@@ -74,7 +83,7 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
7483
if (!options.head) {
7584
throw new Error('useScript() has been called without Nuxt context.')
7685
}
77-
nuxtApp.$scripts = nuxtApp.$scripts! || reactive({})
86+
ensureScripts(nuxtApp)
7887
const exists = !!(nuxtApp.$scripts as Record<string, any>)?.[id]
7988

8089
const err = options._validate?.()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"method": "GET",
4+
"original": {
5+
"body": null,
6+
"query": {},
7+
},
8+
"passthroughBody": false,
9+
"path": "/_proxy/clarity-scripts/0.8.56/clarity.js",
10+
"privacy": {
11+
"hardware": true,
12+
"ip": true,
13+
"language": true,
14+
"screen": false,
15+
"timezone": false,
16+
"userAgent": false,
17+
},
18+
"stripped": {
19+
"body": null,
20+
"query": {},
21+
},
22+
"targetUrl": "https://scripts.clarity.ms/0.8.56/clarity.js",
23+
},
24+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"headers": {
3+
"x-forwarded-for": {
4+
"anonymized": "127.0.0.0",
5+
"original": "<absent>",
6+
},
7+
},
8+
"method": "GET",
9+
"target": "scripts.clarity.ms/0.8.56/clarity.js",
10+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[
2+
{
3+
"method": "GET",
4+
"original": {
5+
"body": null,
6+
"query": {
7+
"domain": "127.0.0.1",
8+
"ex_m": "100,193,142,22,69,70,135,65,64,11,150,86,16,129,122,72,75,128,147,152,8,4,5,7,6,3,87,97,153,158,207,59,174,175,52,251,30,71,219,218,217,23,32,99,58,10,60,93,94,95,101,125,31,29,127,124,123,143,73,146,144,145,47,57,118,15,149,42,239,240,238,26,27,28,45,136,74,108,18,20,41,37,39,38,80,88,92,106,134,137,43,107,24,21,114,66,35,139,138,140,131,130,25,34,56,105,148,67,17,141,110,78,63,19,81,82,111,33,264,200,189,190,188,267,259,49,201,103,126,77,116,51,44,46,109,115,121,55,61,50,53,96,151,1,119,14,117,12,2,54,89,62,113,85,84,154,155,90,91,9,120,98,48,132,83,76,68,112,102,40,133,0,79,36,104,13,156",
9+
"hme": "8830461b0a3fda5230edea4335366eb6d682f53a525e54f7adf6ff7b70c96c39",
10+
"r": "stable",
11+
"v": "2.9.274",
12+
},
13+
},
14+
"passthroughBody": false,
15+
"path": "/_proxy/meta/signals/config/3925006?v=2.9.274&r=stable&domain=127.0.0.1&hme=8830461b0a3fda5230edea4335366eb6d682f53a525e54f7adf6ff7b70c96c39&ex_m=100%2C193%2C142%2C22%2C69%2C70%2C135%2C65%2C64%2C11%2C150%2C86%2C16%2C129%2C122%2C72%2C75%2C128%2C147%2C152%2C8%2C4%2C5%2C7%2C6%2C3%2C87%2C97%2C153%2C158%2C207%2C59%2C174%2C175%2C52%2C251%2C30%2C71%2C219%2C218%2C217%2C23%2C32%2C99%2C58%2C10%2C60%2C93%2C94%2C95%2C101%2C125%2C31%2C29%2C127%2C124%2C123%2C143%2C73%2C146%2C144%2C145%2C47%2C57%2C118%2C15%2C149%2C42%2C239%2C240%2C238%2C26%2C27%2C28%2C45%2C136%2C74%2C108%2C18%2C20%2C41%2C37%2C39%2C38%2C80%2C88%2C92%2C106%2C134%2C137%2C43%2C107%2C24%2C21%2C114%2C66%2C35%2C139%2C138%2C140%2C131%2C130%2C25%2C34%2C56%2C105%2C148%2C67%2C17%2C141%2C110%2C78%2C63%2C19%2C81%2C82%2C111%2C33%2C264%2C200%2C189%2C190%2C188%2C267%2C259%2C49%2C201%2C103%2C126%2C77%2C116%2C51%2C44%2C46%2C109%2C115%2C121%2C55%2C61%2C50%2C53%2C96%2C151%2C1%2C119%2C14%2C117%2C12%2C2%2C54%2C89%2C62%2C113%2C85%2C84%2C154%2C155%2C90%2C91%2C9%2C120%2C98%2C48%2C132%2C83%2C76%2C68%2C112%2C102%2C40%2C133%2C0%2C79%2C36%2C104%2C13%2C156",
16+
"privacy": {
17+
"hardware": true,
18+
"ip": true,
19+
"language": true,
20+
"screen": true,
21+
"timezone": true,
22+
"userAgent": true,
23+
},
24+
"stripped": {
25+
"body": null,
26+
"query": {
27+
"domain": "127.0.0.1",
28+
"ex_m": "100,193,142,22,69,70,135,65,64,11,150,86,16,129,122,72,75,128,147,152,8,4,5,7,6,3,87,97,153,158,207,59,174,175,52,251,30,71,219,218,217,23,32,99,58,10,60,93,94,95,101,125,31,29,127,124,123,143,73,146,144,145,47,57,118,15,149,42,239,240,238,26,27,28,45,136,74,108,18,20,41,37,39,38,80,88,92,106,134,137,43,107,24,21,114,66,35,139,138,140,131,130,25,34,56,105,148,67,17,141,110,78,63,19,81,82,111,33,264,200,189,190,188,267,259,49,201,103,126,77,116,51,44,46,109,115,121,55,61,50,53,96,151,1,119,14,117,12,2,54,89,62,113,85,84,154,155,90,91,9,120,98,48,132,83,76,68,112,102,40,133,0,79,36,104,13,156",
29+
"hme": "8830461b0a3fda5230edea4335366eb6d682f53a525e54f7adf6ff7b70c96c39",
30+
"r": "stable",
31+
"v": "2.9.274",
32+
},
33+
},
34+
"targetUrl": "https://connect.facebook.net/signals/config/3925006?v=2.9.274&r=stable&domain=127.0.0.1&hme=8830461b0a3fda5230edea4335366eb6d682f53a525e54f7adf6ff7b70c96c39&ex_m=100%2C193%2C142%2C22%2C69%2C70%2C135%2C65%2C64%2C11%2C150%2C86%2C16%2C129%2C122%2C72%2C75%2C128%2C147%2C152%2C8%2C4%2C5%2C7%2C6%2C3%2C87%2C97%2C153%2C158%2C207%2C59%2C174%2C175%2C52%2C251%2C30%2C71%2C219%2C218%2C217%2C23%2C32%2C99%2C58%2C10%2C60%2C93%2C94%2C95%2C101%2C125%2C31%2C29%2C127%2C124%2C123%2C143%2C73%2C146%2C144%2C145%2C47%2C57%2C118%2C15%2C149%2C42%2C239%2C240%2C238%2C26%2C27%2C28%2C45%2C136%2C74%2C108%2C18%2C20%2C41%2C37%2C39%2C38%2C80%2C88%2C92%2C106%2C134%2C137%2C43%2C107%2C24%2C21%2C114%2C66%2C35%2C139%2C138%2C140%2C131%2C130%2C25%2C34%2C56%2C105%2C148%2C67%2C17%2C141%2C110%2C78%2C63%2C19%2C81%2C82%2C111%2C33%2C264%2C200%2C189%2C190%2C188%2C267%2C259%2C49%2C201%2C103%2C126%2C77%2C116%2C51%2C44%2C46%2C109%2C115%2C121%2C55%2C61%2C50%2C53%2C96%2C151%2C1%2C119%2C14%2C117%2C12%2C2%2C54%2C89%2C62%2C113%2C85%2C84%2C154%2C155%2C90%2C91%2C9%2C120%2C98%2C48%2C132%2C83%2C76%2C68%2C112%2C102%2C40%2C133%2C0%2C79%2C36%2C104%2C13%2C156",
35+
},
36+
{
37+
"method": "GET",
38+
"original": {
39+
"body": null,
40+
"query": {
41+
"coo": "false",
42+
"dl": "http://127.0.0.1:<PORT>/meta",
43+
"ec": "0",
44+
"ev": "PageView",
45+
"expv2": "<VOLATILE>",
46+
"id": "3925006",
47+
"if": "false",
48+
"it": "<IT>",
49+
"o": "156",
50+
"r": "stable",
51+
"rl": "",
52+
"rqm": "GET",
53+
"sh": "720",
54+
"sw": "1280",
55+
"ts": "<TS>",
56+
"v": "2.9.274",
57+
},
58+
},
59+
"passthroughBody": false,
60+
"path": "/_proxy/meta-tr/?id=3925006&ev=PageView&dl=http%3A%2F%2F127.0.0.1%3A<PORT>%2Fmeta&rl=&if=false&ts=<TS>&sw=1280&sh=720&v=2.9.274&r=stable&ec=0&o=156&it=<IT>&coo=false&expv2=<VOLATILE>&rqm=GET",
61+
"privacy": {
62+
"hardware": true,
63+
"ip": true,
64+
"language": true,
65+
"screen": true,
66+
"timezone": true,
67+
"userAgent": true,
68+
},
69+
"stripped": {
70+
"body": null,
71+
"query": {
72+
"coo": "false",
73+
"dl": "http://127.0.0.1:<PORT>/meta",
74+
"ec": "0",
75+
"ev": "PageView",
76+
"expv2": "<VOLATILE>",
77+
"id": "3925006",
78+
"if": "false",
79+
"it": "<IT>",
80+
"o": "156",
81+
"r": "stable",
82+
"rl": "",
83+
"rqm": "GET",
84+
"sh": "1080",
85+
"sw": "1920",
86+
"ts": "<TS>",
87+
"v": "2.9.274",
88+
},
89+
},
90+
"targetUrl": "https://www.facebook.com/tr/?id=3925006&ev=PageView&dl=http%3A%2F%2F127.0.0.1%3A<PORT>%2Fmeta&rl=&if=false&ts=<TS>&sw=1920&sh=1080&v=2.9.274&r=stable&ec=0&o=156&it=<IT>&coo=false&expv2=<VOLATILE>&rqm=GET",
91+
},
92+
{
93+
"method": "GET",
94+
"original": {
95+
"body": null,
96+
"query": {
97+
"cd[content_category]": "Testing",
98+
"cd[content_name]": "Test Product",
99+
"coo": "false",
100+
"dl": "http://127.0.0.1:<PORT>/meta",
101+
"ec": "1",
102+
"ev": "ViewContent",
103+
"expv2": "<VOLATILE>",
104+
"id": "3925006",
105+
"if": "false",
106+
"it": "<IT>",
107+
"o": "156",
108+
"r": "stable",
109+
"rl": "",
110+
"rqm": "GET",
111+
"sh": "720",
112+
"sw": "1280",
113+
"ts": "<TS>",
114+
"v": "2.9.274",
115+
},
116+
},
117+
"passthroughBody": false,
118+
"path": "/_proxy/meta-tr/?id=3925006&ev=ViewContent&dl=http%3A%2F%2F127.0.0.1%3A<PORT>%2Fmeta&rl=&if=false&ts=<TS>&cd[content_name]=Test%20Product&cd[content_category]=Testing&sw=1280&sh=720&v=2.9.274&r=stable&ec=1&o=156&it=<IT>&coo=false&expv2=<VOLATILE>&rqm=GET",
119+
"privacy": {
120+
"hardware": true,
121+
"ip": true,
122+
"language": true,
123+
"screen": true,
124+
"timezone": true,
125+
"userAgent": true,
126+
},
127+
"stripped": {
128+
"body": null,
129+
"query": {
130+
"cd[content_category]": "Testing",
131+
"cd[content_name]": "Test Product",
132+
"coo": "false",
133+
"dl": "http://127.0.0.1:<PORT>/meta",
134+
"ec": "1",
135+
"ev": "ViewContent",
136+
"expv2": "<VOLATILE>",
137+
"id": "3925006",
138+
"if": "false",
139+
"it": "<IT>",
140+
"o": "156",
141+
"r": "stable",
142+
"rl": "",
143+
"rqm": "GET",
144+
"sh": "1080",
145+
"sw": "1920",
146+
"ts": "<TS>",
147+
"v": "2.9.274",
148+
},
149+
},
150+
"targetUrl": "https://www.facebook.com/tr/?id=3925006&ev=ViewContent&dl=http%3A%2F%2F127.0.0.1%3A<PORT>%2Fmeta&rl=&if=false&ts=<TS>&cd%5Bcontent_name%5D=Test+Product&cd%5Bcontent_category%5D=Testing&sw=1920&sh=1080&v=2.9.274&r=stable&ec=1&o=156&it=<IT>&coo=false&expv2=<VOLATILE>&rqm=GET",
151+
},
152+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"headers": {
3+
"user-agent": {
4+
"anonymized": "Mozilla/5.0 (compatible; Chrome/145.0)",
5+
"original": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/145.0.7632.6 Safari/537.36",
6+
},
7+
"x-forwarded-for": {
8+
"anonymized": "127.0.0.0",
9+
"original": "<absent>",
10+
},
11+
},
12+
"method": "GET",
13+
"target": "connect.facebook.net/signals/config/3925006",
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"headers": {
3+
"user-agent": {
4+
"anonymized": "Mozilla/5.0 (compatible; Chrome/145.0)",
5+
"original": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/145.0.7632.6 Safari/537.36",
6+
},
7+
"x-forwarded-for": {
8+
"anonymized": "127.0.0.0",
9+
"original": "<absent>",
10+
},
11+
},
12+
"method": "GET",
13+
"query": {
14+
"sh": {
15+
"anonymized": "1080",
16+
"original": "720",
17+
},
18+
"sw": {
19+
"anonymized": "1920",
20+
"original": "1280",
21+
},
22+
},
23+
"target": "www.facebook.com/tr/",
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"headers": {
3+
"user-agent": {
4+
"anonymized": "Mozilla/5.0 (compatible; Chrome/145.0)",
5+
"original": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/145.0.7632.6 Safari/537.36",
6+
},
7+
"x-forwarded-for": {
8+
"anonymized": "127.0.0.0",
9+
"original": "<absent>",
10+
},
11+
},
12+
"method": "GET",
13+
"query": {
14+
"sh": {
15+
"anonymized": "1080",
16+
"original": "720",
17+
},
18+
"sw": {
19+
"anonymized": "1920",
20+
"original": "1280",
21+
},
22+
},
23+
"target": "www.facebook.com/tr/",
24+
}

0 commit comments

Comments
 (0)