@zenithbuild/runtime 0.5.0-beta.2.4 → 0.5.0-beta.2.6
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/HYDRATION_CONTRACT.md +14 -0
- package/dist/hydrate.js +50 -5
- package/package.json +3 -2
package/HYDRATION_CONTRACT.md
CHANGED
|
@@ -96,3 +96,17 @@ Forbidden in runtime/bundler output:
|
|
|
96
96
|
- `process.env`
|
|
97
97
|
|
|
98
98
|
Compile-time guarantees override runtime flexibility.
|
|
99
|
+
|
|
100
|
+
## 8. Freeze Boundary Contract
|
|
101
|
+
|
|
102
|
+
Runtime payload freezing is allowed only for deterministic internal tables and
|
|
103
|
+
plain JSON-like containers controlled by runtime (`Object` / `Array`).
|
|
104
|
+
|
|
105
|
+
Runtime MUST NOT freeze:
|
|
106
|
+
- `ref()` objects (objects with writable `.current`)
|
|
107
|
+
- function values (handlers/callbacks)
|
|
108
|
+
- host/platform objects (`Node`, `EventTarget`, `URL`, `Request`, `Response`, etc.)
|
|
109
|
+
|
|
110
|
+
Rationale:
|
|
111
|
+
- hydration and `zenMount` must be able to assign `ref.current` without throwing
|
|
112
|
+
- host objects preserve platform mutability semantics
|
package/dist/hydrate.js
CHANGED
|
@@ -484,7 +484,11 @@ function _validatePayload(payload) {
|
|
|
484
484
|
if (Array.isArray(c.props)) {
|
|
485
485
|
for (let j = 0; j < c.props.length; j++) {
|
|
486
486
|
const propDesc = c.props[j];
|
|
487
|
-
if (
|
|
487
|
+
if (
|
|
488
|
+
propDesc &&
|
|
489
|
+
typeof propDesc === 'object' &&
|
|
490
|
+
_isHydrationFreezableContainer(propDesc.value)
|
|
491
|
+
) {
|
|
488
492
|
Object.freeze(propDesc.value);
|
|
489
493
|
}
|
|
490
494
|
Object.freeze(propDesc);
|
|
@@ -1580,10 +1584,7 @@ function _applyAttribute(node, attrName, value) {
|
|
|
1580
1584
|
}
|
|
1581
1585
|
|
|
1582
1586
|
function _deepFreezePayload(obj) {
|
|
1583
|
-
if (!obj ||
|
|
1584
|
-
// Skip DOM nodes, signals (objects with get/subscribe), and functions
|
|
1585
|
-
if (typeof obj.nodeType === 'number') return;
|
|
1586
|
-
if (typeof obj.get === 'function' && typeof obj.subscribe === 'function') return;
|
|
1587
|
+
if (!_isHydrationFreezableContainer(obj) || Object.isFrozen(obj)) return;
|
|
1587
1588
|
|
|
1588
1589
|
Object.freeze(obj);
|
|
1589
1590
|
const keys = Object.keys(obj);
|
|
@@ -1594,3 +1595,47 @@ function _deepFreezePayload(obj) {
|
|
|
1594
1595
|
}
|
|
1595
1596
|
}
|
|
1596
1597
|
}
|
|
1598
|
+
|
|
1599
|
+
function _isHydrationRefObject(obj) {
|
|
1600
|
+
if (!obj || typeof obj !== 'object') {
|
|
1601
|
+
return false;
|
|
1602
|
+
}
|
|
1603
|
+
if (obj.__zenith_ref === true) {
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
if (!Object.prototype.hasOwnProperty.call(obj, 'current')) {
|
|
1607
|
+
return false;
|
|
1608
|
+
}
|
|
1609
|
+
if (typeof obj.get === 'function' && typeof obj.subscribe === 'function') {
|
|
1610
|
+
return false;
|
|
1611
|
+
}
|
|
1612
|
+
const keys = Object.keys(obj);
|
|
1613
|
+
if (keys.length === 1 && keys[0] === 'current') {
|
|
1614
|
+
return true;
|
|
1615
|
+
}
|
|
1616
|
+
if (keys.length === 2 && keys.includes('current') && keys.includes('__zenith_ref')) {
|
|
1617
|
+
return true;
|
|
1618
|
+
}
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
function _isPlainObject(value) {
|
|
1623
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1624
|
+
return false;
|
|
1625
|
+
}
|
|
1626
|
+
const proto = Object.getPrototypeOf(value);
|
|
1627
|
+
return proto === Object.prototype || proto === null;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
function _isHydrationFreezableContainer(value) {
|
|
1631
|
+
if (Array.isArray(value)) return true;
|
|
1632
|
+
if (!_isPlainObject(value)) return false;
|
|
1633
|
+
|
|
1634
|
+
if (_isHydrationRefObject(value)) {
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
if (typeof value.get === 'function' && typeof value.subscribe === 'function') {
|
|
1638
|
+
return false;
|
|
1639
|
+
}
|
|
1640
|
+
return true;
|
|
1641
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenithbuild/runtime",
|
|
3
|
-
"version": "0.5.0-beta.2.
|
|
3
|
+
"version": "0.5.0-beta.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./dist/index.js"
|
|
7
|
+
".": "./dist/index.js",
|
|
8
|
+
"./template": "./dist/template.js"
|
|
8
9
|
},
|
|
9
10
|
"publishConfig": {
|
|
10
11
|
"access": "public"
|