@constela/runtime 2.0.3 → 2.0.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.
Files changed (2) hide show
  1. package/dist/index.js +22 -16
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -16167,20 +16167,22 @@ function hydrateElement(node, el, ctx) {
16167
16167
  hydrateChildren(node.children, el, ctx);
16168
16168
  }
16169
16169
  }
16170
- function findSsrIfBranchMarker(parent, beforeNode) {
16171
- let current = beforeNode ? beforeNode.previousSibling : parent.lastChild;
16172
- while (current) {
16173
- if (current.nodeType === Node.COMMENT_NODE) {
16174
- const comment2 = current;
16175
- const text3 = comment2.textContent;
16176
- if (text3 === "if:then") return { branch: "then", marker: comment2 };
16177
- if (text3 === "if:else") return { branch: "else", marker: comment2 };
16178
- if (text3 === "if:none") return { branch: "none", marker: comment2 };
16179
- }
16180
- if (current.nodeType === Node.ELEMENT_NODE) break;
16181
- current = current.previousSibling;
16170
+ function collectIfMarkers(parent) {
16171
+ const markers = [];
16172
+ for (let i = 0; i < parent.childNodes.length; i++) {
16173
+ const child = parent.childNodes[i];
16174
+ if (child.nodeType === Node.COMMENT_NODE) {
16175
+ const text3 = child.textContent;
16176
+ if (text3 === "if:then") {
16177
+ markers.push({ branch: "then", marker: child });
16178
+ } else if (text3 === "if:else") {
16179
+ markers.push({ branch: "else", marker: child });
16180
+ } else if (text3 === "if:none") {
16181
+ markers.push({ branch: "none", marker: child });
16182
+ }
16183
+ }
16182
16184
  }
16183
- return null;
16185
+ return markers;
16184
16186
  }
16185
16187
  function hydrateChildren(children, parent, ctx) {
16186
16188
  const domChildren = [];
@@ -16190,6 +16192,8 @@ function hydrateChildren(children, parent, ctx) {
16190
16192
  domChildren.push(child);
16191
16193
  }
16192
16194
  }
16195
+ const ifMarkers = collectIfMarkers(parent);
16196
+ let ifMarkerIndex = 0;
16193
16197
  let domIndex = 0;
16194
16198
  for (let i = 0; i < children.length; i++) {
16195
16199
  const childNode = children[i];
@@ -16224,14 +16228,15 @@ function hydrateChildren(children, parent, ctx) {
16224
16228
  ...ctx.route && { route: ctx.route }
16225
16229
  });
16226
16230
  const clientBranch = Boolean(clientCondition) ? "then" : ifNode.else ? "else" : "none";
16227
- const domChild = domChildren[domIndex];
16228
- const ssrInfo = findSsrIfBranchMarker(parent, domChild || null);
16231
+ const ssrInfo = ifMarkerIndex < ifMarkers.length ? ifMarkers[ifMarkerIndex] : null;
16232
+ ifMarkerIndex++;
16229
16233
  const ssrBranch = ssrInfo?.branch ?? null;
16230
16234
  const ssrHasDom = ssrBranch === "then" || ssrBranch === "else";
16231
16235
  if (ssrInfo?.marker) {
16232
16236
  ssrInfo.marker.remove();
16233
16237
  }
16234
- if (ssrHasDom && domChild) {
16238
+ if (ssrHasDom && domChildren[domIndex]) {
16239
+ const domChild = domChildren[domIndex];
16235
16240
  hydrateIf(ifNode, domChild, ctx, { ssrBranch, clientBranch });
16236
16241
  domIndex++;
16237
16242
  } else if (ssrBranch === "none") {
@@ -16240,6 +16245,7 @@ function hydrateChildren(children, parent, ctx) {
16240
16245
  });
16241
16246
  } else {
16242
16247
  const hasDomForIf = Boolean(clientCondition) || Boolean(ifNode.else);
16248
+ const domChild = domChildren[domIndex];
16243
16249
  if (hasDomForIf && domChild) {
16244
16250
  hydrate(childNode, domChild, ctx);
16245
16251
  domIndex++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/runtime",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Runtime DOM renderer for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,8 +18,8 @@
18
18
  "dompurify": "^3.3.1",
19
19
  "marked": "^17.0.1",
20
20
  "shiki": "^3.20.0",
21
- "@constela/core": "0.18.2",
22
- "@constela/compiler": "0.15.8"
21
+ "@constela/compiler": "0.15.8",
22
+ "@constela/core": "0.18.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/dompurify": "^3.2.0",