@torpor/view 1.2.2 → 1.2.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/compile.cjs CHANGED
@@ -392,6 +392,16 @@ function addPushDevBoundary(type, name, status, b) {
392
392
  const HYDRATION_START_COMMENT = "<![>";
393
393
  const HYDRATION_END_COMMENT = "<!]>";
394
394
  const HYDRATION_BREAK_COMMENT = "<!^>";
395
+ /**
396
+ * The branch-break comment for a control statement's branch, with the branch
397
+ * index baked in (`<!^2>`). The server renderer knows which branch it
398
+ * rendered; hydration reads the index back from the marker to detect a
399
+ * branch the client picks differently (see render/hydrationMarkers and
400
+ * render/branchIndex).
401
+ */
402
+ function hydrationBranchComment(index) {
403
+ return `<!^${index}>`;
404
+ }
395
405
  //#endregion
396
406
  //#region src/compile/utils/isControlNode.ts
397
407
  function isControlNode(node) {
@@ -3229,13 +3239,14 @@ function buildServerHtmlNode(node, status) {
3229
3239
  function buildServerIfNode(node, status, b) {
3230
3240
  status.output += HYDRATION_START_COMMENT;
3231
3241
  flushOutput(status, b);
3232
- for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b);
3242
+ let index = 0;
3243
+ for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b, index++);
3233
3244
  status.output += HYDRATION_END_COMMENT;
3234
3245
  status.output += "<!>";
3235
3246
  }
3236
- function buildServerIfBranch(node, status, b) {
3247
+ function buildServerIfBranch(node, status, b, index) {
3237
3248
  b.append(`${node.statement} {`);
3238
- status.output += HYDRATION_BREAK_COMMENT;
3249
+ status.output += hydrationBranchComment(index);
3239
3250
  for (let child of node.children) buildServerNode(child, status, b);
3240
3251
  flushOutput(status, b);
3241
3252
  b.append("}");
@@ -3269,14 +3280,15 @@ function buildServerSwitchNode(node, status, b) {
3269
3280
  status.output += HYDRATION_START_COMMENT;
3270
3281
  flushOutput(status, b);
3271
3282
  b.append(`${node.statement} {`);
3272
- for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b);
3283
+ let index = 0;
3284
+ for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b, index++);
3273
3285
  b.append("}");
3274
3286
  status.output += HYDRATION_END_COMMENT;
3275
3287
  status.output += "<!>";
3276
3288
  }
3277
- function buildServerSwitchBranch(node, status, b) {
3289
+ function buildServerSwitchBranch(node, status, b, index) {
3278
3290
  b.append(`${node.statement} {`);
3279
- status.output += HYDRATION_BREAK_COMMENT;
3291
+ status.output += hydrationBranchComment(index);
3280
3292
  for (let child of node.children) buildServerNode(child, status, b);
3281
3293
  flushOutput(status, b);
3282
3294
  b.append("break;");
package/dist/compile.mjs CHANGED
@@ -391,6 +391,16 @@ function addPushDevBoundary(type, name, status, b) {
391
391
  const HYDRATION_START_COMMENT = "<![>";
392
392
  const HYDRATION_END_COMMENT = "<!]>";
393
393
  const HYDRATION_BREAK_COMMENT = "<!^>";
394
+ /**
395
+ * The branch-break comment for a control statement's branch, with the branch
396
+ * index baked in (`<!^2>`). The server renderer knows which branch it
397
+ * rendered; hydration reads the index back from the marker to detect a
398
+ * branch the client picks differently (see render/hydrationMarkers and
399
+ * render/branchIndex).
400
+ */
401
+ function hydrationBranchComment(index) {
402
+ return `<!^${index}>`;
403
+ }
394
404
  //#endregion
395
405
  //#region src/compile/utils/isControlNode.ts
396
406
  function isControlNode(node) {
@@ -3228,13 +3238,14 @@ function buildServerHtmlNode(node, status) {
3228
3238
  function buildServerIfNode(node, status, b) {
3229
3239
  status.output += HYDRATION_START_COMMENT;
3230
3240
  flushOutput(status, b);
3231
- for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b);
3241
+ let index = 0;
3242
+ for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b, index++);
3232
3243
  status.output += HYDRATION_END_COMMENT;
3233
3244
  status.output += "<!>";
3234
3245
  }
3235
- function buildServerIfBranch(node, status, b) {
3246
+ function buildServerIfBranch(node, status, b, index) {
3236
3247
  b.append(`${node.statement} {`);
3237
- status.output += HYDRATION_BREAK_COMMENT;
3248
+ status.output += hydrationBranchComment(index);
3238
3249
  for (let child of node.children) buildServerNode(child, status, b);
3239
3250
  flushOutput(status, b);
3240
3251
  b.append("}");
@@ -3268,14 +3279,15 @@ function buildServerSwitchNode(node, status, b) {
3268
3279
  status.output += HYDRATION_START_COMMENT;
3269
3280
  flushOutput(status, b);
3270
3281
  b.append(`${node.statement} {`);
3271
- for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b);
3282
+ let index = 0;
3283
+ for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b, index++);
3272
3284
  b.append("}");
3273
3285
  status.output += HYDRATION_END_COMMENT;
3274
3286
  status.output += "<!>";
3275
3287
  }
3276
- function buildServerSwitchBranch(node, status, b) {
3288
+ function buildServerSwitchBranch(node, status, b, index) {
3277
3289
  b.append(`${node.statement} {`);
3278
- status.output += HYDRATION_BREAK_COMMENT;
3290
+ status.output += hydrationBranchComment(index);
3279
3291
  for (let child of node.children) buildServerNode(child, status, b);
3280
3292
  flushOutput(status, b);
3281
3293
  b.append("break;");