unhead 0.0.2 → 0.0.5

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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as HeadClient } from './types-011e5fbf.js';
1
+ import { a as HeadClient } from './types-b4318c02.js';
2
2
  import 'hookable';
3
3
  import '@unhead/schema';
4
4
 
package/dist/client.mjs CHANGED
@@ -1,16 +1,20 @@
1
1
  import { createElement, TagsWithInnerContent } from 'zhead';
2
2
 
3
- function setAttributesWithSideEffects($el, entry, tag) {
3
+ function setAttributesWithSideEffects(head, $el, entry, tag) {
4
4
  const attrs = tag.props || {};
5
5
  const sdeKey = `${tag._p}:attr`;
6
- Object.entries(entry._sde).filter(([key]) => key.startsWith(sdeKey)).forEach(([key, fn]) => delete entry._sde[key] && fn());
6
+ Object.entries(entry._sde).filter(([key]) => key.startsWith(sdeKey)).forEach(([key, fn]) => {
7
+ delete entry._sde[key] && fn();
8
+ });
7
9
  Object.entries(attrs).forEach(([k, value]) => {
8
10
  value = String(value);
9
11
  const attrSdeKey = `${sdeKey}:${k}`;
12
+ head._removeQueuedSideEffect(attrSdeKey);
10
13
  if (k === "class") {
11
14
  for (const c of value.split(" ")) {
12
15
  if (!$el.classList.contains(c)) {
13
16
  $el.classList.add(c);
17
+ head._removeQueuedSideEffect(`${attrSdeKey}:${c}`);
14
18
  entry._sde[`${attrSdeKey}:${c}`] = () => $el.classList.remove(c);
15
19
  }
16
20
  }
@@ -28,7 +32,6 @@ async function renderDOMHead(head, options = {}) {
28
32
  const dom = options.document || window.document;
29
33
  const tags = await head.resolveTags();
30
34
  await head.hooks.callHook("dom:beforeRender", { head, tags, document: dom });
31
- head._flushQueuedSideEffectFns();
32
35
  for (const tag of tags) {
33
36
  const entry = head.headEntries().find((e) => e._i === Number(tag._e));
34
37
  const sdeKey = `${tag._s || tag._p}:el`;
@@ -37,11 +40,14 @@ async function renderDOMHead(head, options = {}) {
37
40
  const renderCtx = { tag, document: dom, head };
38
41
  await head.hooks.callHook("dom:renderTag", renderCtx);
39
42
  if ($el) {
43
+ head._removeQueuedSideEffect(sdeKey);
44
+ if ($newEl.isEqualNode($el))
45
+ continue;
40
46
  if (Object.keys(tag.props).length === 0) {
41
47
  $el.remove();
42
48
  continue;
43
49
  }
44
- setAttributesWithSideEffects($el, entry, tag);
50
+ setAttributesWithSideEffects(head, $el, entry, tag);
45
51
  if (TagsWithInnerContent.includes(tag.tag))
46
52
  $el.innerHTML = tag.children || "";
47
53
  entry._sde[sdeKey] = () => $el?.remove();
@@ -52,7 +58,7 @@ async function renderDOMHead(head, options = {}) {
52
58
  continue;
53
59
  }
54
60
  if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
55
- setAttributesWithSideEffects(dom[tag.tag === "htmlAttrs" ? "documentElement" : "body"], entry, tag);
61
+ setAttributesWithSideEffects(head, dom[tag.tag === "htmlAttrs" ? "documentElement" : "body"], entry, tag);
56
62
  continue;
57
63
  }
58
64
  switch (tag.tagPosition) {
@@ -69,6 +75,7 @@ async function renderDOMHead(head, options = {}) {
69
75
  }
70
76
  entry._sde[sdeKey] = () => $newEl?.remove();
71
77
  }
78
+ head._flushQueuedSideEffects();
72
79
  }
73
80
  let domUpdatePromise = null;
74
81
  async function debouncedRenderDOMHead(delayedFn, head, options = {}) {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _unhead_schema from '@unhead/schema';
2
2
  import { Head, Meta, Link, Script, Style, Base, HtmlAttributes, BodyAttributes, Noscript } from '@unhead/schema';
3
- import { H as HeadPlugin, C as CreateHeadOptions, a as HeadClient, b as HeadEntryOptions } from './types-011e5fbf.js';
4
- export { A as ActiveHeadEntry, C as CreateHeadOptions, D as DomRenderTagContext, E as EntryResolveCtx, a as HeadClient, c as HeadEntry, b as HeadEntryOptions, f as HeadHooks, H as HeadPlugin, e as HookResult, R as RuntimeMode, S as SideEffectsRecord, d as defineHeadPlugin } from './types-011e5fbf.js';
3
+ import { H as HeadPlugin, C as CreateHeadOptions, a as HeadClient, b as HeadEntryOptions } from './types-b4318c02.js';
4
+ export { A as ActiveHeadEntry, C as CreateHeadOptions, D as DomRenderTagContext, E as EntryResolveCtx, a as HeadClient, c as HeadEntry, b as HeadEntryOptions, f as HeadHooks, H as HeadPlugin, e as HookResult, R as RuntimeMode, S as SideEffectsRecord, d as defineHeadPlugin } from './types-b4318c02.js';
5
5
  import 'hookable';
6
6
 
7
7
  declare const DedupesTagsPlugin: HeadPlugin<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>;
package/dist/index.mjs CHANGED
@@ -113,7 +113,8 @@ const HydratesStatePlugin = defineHeadPlugin({
113
113
  return;
114
114
  if (typeof tag._d === "undefined" && entry._m === "server")
115
115
  return;
116
- tag._s = `data-h-${hashCode(tag._d || tag.tag + JSON.stringify(tag.props))}`;
116
+ const hasChildren = tag.children && tag.children.length > 0;
117
+ tag._s = `data-h-${hashCode(tag._d || tag.tag + (hasChildren ? tag.children : JSON.stringify(tag.props)))}`;
117
118
  tag.props[tag._s] = "";
118
119
  }
119
120
  }
@@ -165,7 +166,10 @@ function createHead(options = {}) {
165
166
  plugins.push(...options.plugins || []);
166
167
  plugins.forEach((plugin) => hooks.addHooks(plugin.hooks || {}));
167
168
  const head = {
168
- _flushQueuedSideEffectFns() {
169
+ _removeQueuedSideEffect(key) {
170
+ delete _sde[key];
171
+ },
172
+ _flushQueuedSideEffects() {
169
173
  Object.values(_sde).forEach((fn) => fn());
170
174
  _sde = {};
171
175
  },
@@ -195,9 +199,11 @@ function createHead(options = {}) {
195
199
  },
196
200
  patch(input2) {
197
201
  entries = entries.map((e) => {
198
- _sde = { ..._sde, ...e._sde || {} };
199
- e._sde = {};
200
- e.input = e._i === _i ? input2 : e.input;
202
+ if (e._i === _i) {
203
+ _sde = { ..._sde, ...e._sde || {} };
204
+ e._sde = {};
205
+ e.input = e._i === _i ? input2 : e.input;
206
+ }
201
207
  return e;
202
208
  });
203
209
  }
package/dist/server.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { g as SSRHeadPayload, r as renderSSRHead } from './types-011e5fbf.js';
1
+ export { g as SSRHeadPayload, r as renderSSRHead } from './types-b4318c02.js';
2
2
  import 'hookable';
3
3
  import '@unhead/schema';
@@ -80,12 +80,12 @@ interface HeadHooks<T> {
80
80
  'tags:resolve': (ctx: {
81
81
  tags: HeadTag[];
82
82
  }) => HookResult;
83
- 'dom:renderTag': (ctx: DomRenderTagContext) => HookResult;
84
83
  'dom:beforeRender': (ctx: {
85
84
  head: HeadClient;
86
85
  tags: HeadTag[];
87
86
  document: Document;
88
87
  }) => HookResult;
88
+ 'dom:renderTag': (ctx: DomRenderTagContext) => HookResult;
89
89
  'ssr:beforeRender': (ctx: {
90
90
  tags: HeadTag[];
91
91
  }) => HookResult;
@@ -121,7 +121,11 @@ interface HeadClient<T = Head> {
121
121
  /**
122
122
  * @internal
123
123
  */
124
- _flushQueuedSideEffectFns: () => void;
124
+ _removeQueuedSideEffect: (key: string) => void;
125
+ /**
126
+ * @internal
127
+ */
128
+ _flushQueuedSideEffects: () => void;
125
129
  }
126
130
 
127
131
  export { ActiveHeadEntry as A, CreateHeadOptions as C, DomRenderTagContext as D, EntryResolveCtx as E, HeadPlugin as H, RuntimeMode as R, SideEffectsRecord as S, HeadClient as a, HeadEntryOptions as b, HeadEntry as c, defineHeadPlugin as d, HookResult as e, HeadHooks as f, SSRHeadPayload as g, renderSSRHead as r };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unhead",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.5",
5
5
  "packageManager": "pnpm@7.14.0",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@unhead/schema": "0.0.2",
39
+ "@unhead/schema": "0.0.5",
40
40
  "hookable": "^5.4.1",
41
41
  "zhead": "1.0.0-beta.4"
42
42
  },