dom-expressions 0.31.4 → 0.31.8
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/package.json +3 -3
- package/src/client.d.ts +1 -1
- package/src/client.js +2 -1
- package/src/jsx.d.ts +1 -0
- package/src/server.js +17 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dom-expressions",
|
|
3
3
|
"description": "A Fine-Grained Runtime for Performant DOM Rendering",
|
|
4
|
-
"version": "0.31.
|
|
4
|
+
"version": "0.31.8",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"devalue": "^2.0.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"babel-plugin-jsx-dom-expressions": "^0.31.
|
|
23
|
+
"babel-plugin-jsx-dom-expressions": "^0.31.5"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "be28e4c19f312d727ad5f165b5c8e19c301dedde"
|
|
26
26
|
}
|
package/src/client.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function dynamicProperty(props: unknown, key: string): unknown;
|
|
|
53
53
|
export function hydrate(
|
|
54
54
|
fn: () => JSX.Element,
|
|
55
55
|
node: MountableElement,
|
|
56
|
-
options
|
|
56
|
+
options?: { renderId?: string }
|
|
57
57
|
): () => void;
|
|
58
58
|
export function getHydrationKey(): string;
|
|
59
59
|
export function getNextElement(template?: HTMLTemplateElement): Element;
|
package/src/client.js
CHANGED
|
@@ -442,7 +442,8 @@ function cleanChildren(parent, current, marker, replacement) {
|
|
|
442
442
|
else isParent && parent.removeChild(el);
|
|
443
443
|
} else inserted = true;
|
|
444
444
|
}
|
|
445
|
-
} else parent.
|
|
445
|
+
} else if (current instanceof Node) parent.replaceChild(node, current);
|
|
446
|
+
else parent.insertBefore(node, marker);
|
|
446
447
|
return [node];
|
|
447
448
|
}
|
|
448
449
|
|
package/src/jsx.d.ts
CHANGED
package/src/server.js
CHANGED
|
@@ -27,6 +27,7 @@ export function renderToString(code, options = {}) {
|
|
|
27
27
|
export function renderToStringAsync(code, options = {}) {
|
|
28
28
|
let scripts = "";
|
|
29
29
|
const { nonce, renderId, timeoutMs = 30000 } = options;
|
|
30
|
+
const dedupe = new WeakMap();
|
|
30
31
|
const context = (sharedConfig.context = {
|
|
31
32
|
id: renderId || "",
|
|
32
33
|
count: 0,
|
|
@@ -38,8 +39,8 @@ export function renderToStringAsync(code, options = {}) {
|
|
|
38
39
|
writeResource(id, p, error) {
|
|
39
40
|
if (error) return (scripts += `_$HY.set("${id}", ${serializeError(p)});`);
|
|
40
41
|
if (!p || typeof p !== "object" || !("then" in p))
|
|
41
|
-
return (scripts +=
|
|
42
|
-
p.then(d => (scripts +=
|
|
42
|
+
return (scripts += serializeSet(dedupe, id, p));
|
|
43
|
+
p.then(d => (scripts += serializeSet(dedupe, id, d))).catch(
|
|
43
44
|
() => (scripts += `_$HY.set("${id}", {});`)
|
|
44
45
|
);
|
|
45
46
|
}
|
|
@@ -91,6 +92,7 @@ export function renderToStream(code, options = {}) {
|
|
|
91
92
|
const tmp = [];
|
|
92
93
|
const tasks = [];
|
|
93
94
|
const registry = new Map();
|
|
95
|
+
const dedupe = new WeakMap();
|
|
94
96
|
const checkEnd = () => {
|
|
95
97
|
if (!registry.size && !completed) {
|
|
96
98
|
onCompleteAll && onCompleteAll(result);
|
|
@@ -131,18 +133,16 @@ export function renderToStream(code, options = {}) {
|
|
|
131
133
|
}
|
|
132
134
|
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
133
135
|
if (!p || typeof p !== "object" || !("then" in p))
|
|
134
|
-
return tasks.push(
|
|
136
|
+
return tasks.push(serializeSet(dedupe, id, p));
|
|
135
137
|
tasks.push(`_$HY.init("${id}")`);
|
|
136
138
|
p.then(d => {
|
|
137
139
|
!completed &&
|
|
138
140
|
buffer.write(
|
|
139
|
-
`<script${nonce ? ` nonce="${nonce}"` : ""}
|
|
141
|
+
`<script${nonce ? ` nonce="${nonce}"` : ""}>${serializeSet(dedupe, id, d)}</script>`
|
|
140
142
|
);
|
|
141
|
-
}).catch(
|
|
143
|
+
}).catch(() => {
|
|
142
144
|
!completed &&
|
|
143
|
-
buffer.write(
|
|
144
|
-
`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", {})</script>`
|
|
145
|
-
);
|
|
145
|
+
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", {})</script>`);
|
|
146
146
|
});
|
|
147
147
|
},
|
|
148
148
|
registerFragment(key) {
|
|
@@ -393,9 +393,9 @@ export function getHydrationKey() {
|
|
|
393
393
|
export function generateHydrationScript({ eventNames = ["click", "input"], nonce }) {
|
|
394
394
|
return `<script${
|
|
395
395
|
nonce ? ` nonce="${nonce}"` : ""
|
|
396
|
-
}>
|
|
396
|
+
}>var e,t;e=window._$HY||(_$HY={events:[],completed:new WeakSet,r:{}}),t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),["${eventNames.join(
|
|
397
397
|
'","'
|
|
398
|
-
)}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,
|
|
398
|
+
)}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,a=t(s);a&&!e.completed.has(a)&&e.events.push([a,o])})))),e.init=(t,o)=>{e.r[t]=[new Promise(((e,t)=>o=e)),o]},e.set=(t,o,s)=>{(s=e.r[t])&&s[1](o),e.r[t]=[o]},e.unset=t=>{delete e.r[t]},e.load=(t,o)=>{if(o=e.r[t])return o[0]};</script><!xs>`;
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
function injectAssets(assets, html) {
|
|
@@ -428,6 +428,13 @@ function waitForFragments(registry, key) {
|
|
|
428
428
|
return false;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
+
function serializeSet(registry, key, value) {
|
|
432
|
+
const exist = registry.get(value);
|
|
433
|
+
if (exist) return `_$HY.set("${key}", _$HY.r["${exist}"][0]);`;
|
|
434
|
+
value !== null && typeof value === "object" && registry.set(value, key);
|
|
435
|
+
return `_$HY.set("${key}", ${devalue(value)});`;
|
|
436
|
+
}
|
|
437
|
+
|
|
431
438
|
/* istanbul ignore next */
|
|
432
439
|
/**
|
|
433
440
|
* @deprecated Replaced by renderToStream
|