@unhead/vue 1.10.2 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -122,37 +122,22 @@ function registerVueScopeHandlers(script, scope) {
122
122
  }
123
123
  function useScript(_input, _options) {
124
124
  const input = typeof _input === "string" ? { src: _input } : _input;
125
- const head = injectHead.injectHead();
126
125
  const options = _options || {};
126
+ const head = options?.head || injectHead.injectHead();
127
127
  options.head = head;
128
128
  const scope = vue.getCurrentInstance();
129
129
  options.eventContext = scope;
130
130
  if (scope && typeof options.trigger === "undefined")
131
131
  options.trigger = vue.onMounted;
132
- const id = unhead.resolveScriptKey(input);
133
- const prevScript = head._scripts?.[id];
134
- if (prevScript) {
135
- prevScript.updateTrigger(options.trigger);
136
- registerVueScopeHandlers(prevScript, scope);
137
- return prevScript;
138
- }
139
- let script;
140
- const status = vue.ref("awaitingLoad");
141
- const _ = head.hooks.hook("script:updated", ({ script: s }) => {
142
- if (script && s.id === script.id) {
143
- status.value = s.status;
144
- if (s.status === "removed") {
145
- _();
146
- }
147
- }
132
+ head._scriptStatusWatcher = head._scriptStatusWatcher || head.hooks.hook("script:updated", ({ script: s }) => {
133
+ s._statusRef.value = s.status;
148
134
  });
149
- script = unhead.useScript(input, options);
135
+ const script = unhead.useScript(input, options);
136
+ script._statusRef = script._statusRef || vue.ref(script.status);
150
137
  registerVueScopeHandlers(script, scope);
151
138
  return new Proxy(script, {
152
- get(_2, key, a) {
153
- if (key === "status")
154
- return status;
155
- return Reflect.get(_2, key, a);
139
+ get(_, key, a) {
140
+ return Reflect.get(_, key === "status" ? "_statusRef" : key, a);
156
141
  }
157
142
  });
158
143
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { resolveScriptKey, useScript as useScript$1 } from 'unhead';
1
+ import { useScript as useScript$1 } from 'unhead';
2
2
  export { CapoPlugin, HashHydrationPlugin, createHeadCore } from 'unhead';
3
3
  import { V as Vue3, h as headSymbol, i as injectHead } from './shared/vue.40986ab9.mjs';
4
4
  export { c as createHead, a as createServerHead, r as resolveUnrefHeadInput, s as setHeadInjectionHandler } from './shared/vue.40986ab9.mjs';
@@ -122,37 +122,22 @@ function registerVueScopeHandlers(script, scope) {
122
122
  }
123
123
  function useScript(_input, _options) {
124
124
  const input = typeof _input === "string" ? { src: _input } : _input;
125
- const head = injectHead();
126
125
  const options = _options || {};
126
+ const head = options?.head || injectHead();
127
127
  options.head = head;
128
128
  const scope = getCurrentInstance();
129
129
  options.eventContext = scope;
130
130
  if (scope && typeof options.trigger === "undefined")
131
131
  options.trigger = onMounted;
132
- const id = resolveScriptKey(input);
133
- const prevScript = head._scripts?.[id];
134
- if (prevScript) {
135
- prevScript.updateTrigger(options.trigger);
136
- registerVueScopeHandlers(prevScript, scope);
137
- return prevScript;
138
- }
139
- let script;
140
- const status = ref("awaitingLoad");
141
- const _ = head.hooks.hook("script:updated", ({ script: s }) => {
142
- if (script && s.id === script.id) {
143
- status.value = s.status;
144
- if (s.status === "removed") {
145
- _();
146
- }
147
- }
132
+ head._scriptStatusWatcher = head._scriptStatusWatcher || head.hooks.hook("script:updated", ({ script: s }) => {
133
+ s._statusRef.value = s.status;
148
134
  });
149
- script = useScript$1(input, options);
135
+ const script = useScript$1(input, options);
136
+ script._statusRef = script._statusRef || ref(script.status);
150
137
  registerVueScopeHandlers(script, scope);
151
138
  return new Proxy(script, {
152
- get(_2, key, a) {
153
- if (key === "status")
154
- return status;
155
- return Reflect.get(_2, key, a);
139
+ get(_, key, a) {
140
+ return Reflect.get(_, key === "status" ? "_statusRef" : key, a);
156
141
  }
157
142
  });
158
143
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/vue",
3
3
  "type": "module",
4
- "version": "1.10.2",
4
+ "version": "1.10.4",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -66,9 +66,9 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "hookable": "^5.5.3",
69
- "@unhead/schema": "1.10.2",
70
- "@unhead/shared": "1.10.2",
71
- "unhead": "1.10.2"
69
+ "@unhead/schema": "1.10.4",
70
+ "unhead": "1.10.4",
71
+ "@unhead/shared": "1.10.4"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "unbuild .",