marko 6.0.0-next.3.69 → 6.0.0-next.3.70

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.
@@ -2149,7 +2149,7 @@ function tryCatch(content, catchContent) {
2149
2149
  catchChunk.render(catchContent, catchBoundary.signal.reason);
2150
2150
  state.reorder(catchChunk);
2151
2151
  boundary.endAsync();
2152
- } else if (catchBoundary.done) {
2152
+ } else if (!catchBoundary.count) {
2153
2153
  boundary.endAsync();
2154
2154
  } else {
2155
2155
  boundary.onNext();
@@ -2174,6 +2174,7 @@ var State2 = class {
2174
2174
  hasReorderRuntime = false;
2175
2175
  hasWrittenResume = false;
2176
2176
  trailerHTML = "";
2177
+ resumes = "";
2177
2178
  nonceAttr = "";
2178
2179
  serializer = new Serializer();
2179
2180
  writeReorders = null;
@@ -2237,7 +2238,8 @@ var Boundary = class extends AbortController {
2237
2238
  onNext = NOOP;
2238
2239
  count = 0;
2239
2240
  get done() {
2240
- return this.count === 0;
2241
+ flushSerializer(this);
2242
+ return !this.count;
2241
2243
  }
2242
2244
  startAsync() {
2243
2245
  if (!this.signal.aborted) {
@@ -2343,145 +2345,152 @@ var Chunk = class {
2343
2345
  $chunk = prev;
2344
2346
  }
2345
2347
  }
2346
- };
2347
- function prepareChunk(chunk) {
2348
- const head = chunk.consume();
2349
- const { boundary, effects } = head;
2350
- const { state } = boundary;
2351
- const { $global: $global2, runtimePrefix, serializer, nonceAttr } = state;
2352
- let { html, scripts } = head;
2353
- let hasWalk = false;
2354
- head.effects = "";
2355
- if (state.needsMainRuntime && !state.hasMainRuntime) {
2356
- state.hasMainRuntime = true;
2357
- scripts = concatScripts(
2358
- scripts,
2359
- WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2360
- );
2361
- }
2362
- let resumes = "";
2363
- if (state.writeScopes || serializer.flushed) {
2364
- let { lastSerializedScopeId } = state;
2365
- const serializeData = [];
2366
- if (!state.hasGlobals) {
2367
- state.hasGlobals = true;
2368
- serializeData.push(getFilteredGlobals(state.$global));
2369
- }
2370
- for (const key in state.writeScopes) {
2371
- const scope = state.writeScopes[key];
2372
- const scopeId = getScopeId(scope);
2373
- const scopeIdDelta = scopeId - lastSerializedScopeId;
2374
- lastSerializedScopeId = scopeId + 1;
2375
- if (scopeIdDelta) serializeData.push(scopeIdDelta);
2376
- serializeData.push(scope);
2377
- }
2378
- resumes = state.serializer.stringify(serializeData, boundary);
2379
- state.writeScopes = null;
2380
- state.lastSerializedScopeId = lastSerializedScopeId;
2381
- }
2382
- if (effects) {
2383
- hasWalk = true;
2384
- resumes = resumes ? resumes + "," + effects : effects;
2385
- }
2386
- if (resumes) {
2387
- if (state.hasWrittenResume) {
2348
+ flushScript() {
2349
+ flushSerializer(this.boundary);
2350
+ const { boundary, effects } = this;
2351
+ const { state } = boundary;
2352
+ const { $global: $global2, runtimePrefix, nonceAttr } = state;
2353
+ let { resumes } = state;
2354
+ let { html, scripts } = this;
2355
+ let hasWalk = false;
2356
+ if (state.needsMainRuntime && !state.hasMainRuntime) {
2357
+ state.hasMainRuntime = true;
2388
2358
  scripts = concatScripts(
2389
2359
  scripts,
2390
- runtimePrefix + ".r.push(" + resumes + ")"
2391
- );
2392
- } else {
2393
- state.hasWrittenResume = true;
2394
- scripts = concatScripts(
2395
- scripts,
2396
- runtimePrefix + ".r=[" + resumes + "]"
2360
+ WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2397
2361
  );
2398
2362
  }
2399
- }
2400
- if (state.writeReorders) {
2401
- hasWalk = true;
2402
- if (!state.hasReorderRuntime) {
2403
- state.hasReorderRuntime = true;
2404
- html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2405
- scripts = concatScripts(
2406
- scripts,
2407
- REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
2408
- );
2363
+ if (effects) {
2364
+ hasWalk = true;
2365
+ resumes = resumes ? resumes + "," + effects : effects;
2409
2366
  }
2410
- for (const reorderedChunk of state.writeReorders) {
2411
- const { reorderId } = reorderedChunk;
2412
- let reorderHTML = "";
2413
- let reorderEffects = "";
2414
- let reorderScripts = "";
2415
- let cur = reorderedChunk;
2416
- reorderedChunk.reorderId = null;
2417
- for (; ; ) {
2418
- cur.flushPlaceholder();
2419
- const { next } = cur;
2420
- cur.consumed = true;
2421
- reorderHTML += cur.html;
2422
- reorderEffects = concatEffects(reorderEffects, cur.effects);
2423
- reorderScripts = concatScripts(reorderScripts, cur.scripts);
2424
- if (cur.async) {
2425
- reorderHTML += state.mark(
2426
- "#" /* ReorderMarker */,
2427
- cur.reorderId = state.nextReorderId()
2428
- );
2429
- cur.html = cur.effects = cur.scripts = "";
2430
- cur.next = null;
2431
- }
2432
- if (next) {
2433
- cur = next;
2434
- } else {
2435
- break;
2436
- }
2367
+ if (resumes) {
2368
+ if (state.hasWrittenResume) {
2369
+ scripts = concatScripts(
2370
+ scripts,
2371
+ runtimePrefix + ".r.push(" + resumes + ")"
2372
+ );
2373
+ } else {
2374
+ state.hasWrittenResume = true;
2375
+ scripts = concatScripts(
2376
+ scripts,
2377
+ runtimePrefix + ".r=[" + resumes + "]"
2378
+ );
2437
2379
  }
2438
- if (reorderEffects) {
2439
- if (!state.hasWrittenResume) {
2440
- state.hasWrittenResume = true;
2441
- scripts = concatScripts(
2442
- scripts,
2443
- runtimePrefix + ".r=[]"
2380
+ }
2381
+ if (state.writeReorders) {
2382
+ hasWalk = true;
2383
+ if (!state.hasReorderRuntime) {
2384
+ state.hasReorderRuntime = true;
2385
+ html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2386
+ scripts = concatScripts(
2387
+ scripts,
2388
+ REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
2389
+ );
2390
+ }
2391
+ for (const reorderedChunk of state.writeReorders) {
2392
+ const { reorderId } = reorderedChunk;
2393
+ let reorderHTML = "";
2394
+ let reorderEffects = "";
2395
+ let reorderScripts = "";
2396
+ let cur = reorderedChunk;
2397
+ reorderedChunk.reorderId = null;
2398
+ for (; ; ) {
2399
+ cur.flushPlaceholder();
2400
+ const { next } = cur;
2401
+ cur.consumed = true;
2402
+ reorderHTML += cur.html;
2403
+ reorderEffects = concatEffects(reorderEffects, cur.effects);
2404
+ reorderScripts = concatScripts(reorderScripts, cur.scripts);
2405
+ if (cur.async) {
2406
+ reorderHTML += state.mark(
2407
+ "#" /* ReorderMarker */,
2408
+ cur.reorderId = state.nextReorderId()
2409
+ );
2410
+ cur.html = cur.effects = cur.scripts = "";
2411
+ cur.next = null;
2412
+ }
2413
+ if (next) {
2414
+ cur = next;
2415
+ } else {
2416
+ break;
2417
+ }
2418
+ }
2419
+ if (reorderEffects) {
2420
+ if (!state.hasWrittenResume) {
2421
+ state.hasWrittenResume = true;
2422
+ scripts = concatScripts(
2423
+ scripts,
2424
+ runtimePrefix + ".r=[]"
2425
+ );
2426
+ }
2427
+ reorderScripts = concatScripts(
2428
+ reorderScripts,
2429
+ "_.push(" + reorderEffects + ")"
2444
2430
  );
2445
2431
  }
2446
- reorderScripts = concatScripts(
2447
- reorderScripts,
2448
- "_.push(" + reorderEffects + ")"
2432
+ scripts = concatScripts(
2433
+ scripts,
2434
+ reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2449
2435
  );
2436
+ html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2450
2437
  }
2451
- scripts = concatScripts(
2452
- scripts,
2453
- reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2454
- );
2455
- html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2438
+ state.writeReorders = null;
2456
2439
  }
2457
- state.writeReorders = null;
2440
+ if (hasWalk) {
2441
+ scripts = concatScripts(scripts, runtimePrefix + ".w()");
2442
+ }
2443
+ this.effects = state.resumes = "";
2444
+ this.html = html;
2445
+ this.scripts = scripts;
2446
+ return this;
2458
2447
  }
2459
- if (hasWalk) {
2460
- scripts = concatScripts(scripts, runtimePrefix + ".w()");
2448
+ flushHTML() {
2449
+ this.flushScript();
2450
+ const { boundary, scripts } = this;
2451
+ const { state } = boundary;
2452
+ const { $global: $global2, nonceAttr } = state;
2453
+ const { __flush__ } = $global2;
2454
+ let { html } = this;
2455
+ this.html = this.scripts = "";
2456
+ if (scripts) {
2457
+ html += "<script" + nonceAttr + ">" + scripts + "</script>";
2458
+ }
2459
+ if (__flush__) {
2460
+ $global2.__flush__ = void 0;
2461
+ html = __flush__($global2, html);
2462
+ }
2463
+ if (!boundary.count) {
2464
+ html += state.trailerHTML;
2465
+ }
2466
+ return html;
2461
2467
  }
2462
- head.html = html;
2463
- head.scripts = scripts;
2464
- return head;
2465
- }
2466
- function flushChunk(head, last) {
2467
- const { boundary } = head;
2468
+ };
2469
+ function flushSerializer(boundary) {
2468
2470
  const { state } = boundary;
2469
- const { html, scripts } = head;
2470
- const { $global: $global2 } = state;
2471
- const { __flush__ } = $global2;
2472
- let result = html;
2473
- head.html = head.scripts = "";
2474
- if (scripts) {
2475
- result += "<script" + state.nonceAttr + ">" + scripts + "</script>";
2476
- }
2477
- if (__flush__) {
2478
- $global2.__flush__ = void 0;
2479
- result = __flush__($global2, result);
2480
- }
2481
- if (last && state.trailerHTML) {
2482
- result += state.trailerHTML;
2471
+ const { writeScopes, serializer } = state;
2472
+ if (writeScopes || serializer.flushed) {
2473
+ const serializeData = [];
2474
+ let { lastSerializedScopeId } = state;
2475
+ if (!state.hasGlobals) {
2476
+ state.hasGlobals = true;
2477
+ serializeData.push(getFilteredGlobals(state.$global));
2478
+ }
2479
+ for (const key in writeScopes) {
2480
+ const scope = writeScopes[key];
2481
+ const scopeId = getScopeId(scope);
2482
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2483
+ lastSerializedScopeId = scopeId + 1;
2484
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2485
+ serializeData.push(scope);
2486
+ }
2487
+ state.resumes = concatEffects(
2488
+ state.resumes,
2489
+ serializer.stringify(serializeData, boundary)
2490
+ );
2491
+ state.lastSerializedScopeId = lastSerializedScopeId;
2492
+ state.writeScopes = null;
2483
2493
  }
2484
- return result;
2485
2494
  }
2486
2495
  function writeTrailers(html) {
2487
2496
  $chunk.boundary.state.trailerHTML += html;
@@ -2961,7 +2970,7 @@ var compat = {
2961
2970
  $global2[K_TAGS_API_STATE] = state = new State2($global2);
2962
2971
  }
2963
2972
  const boundary = new Boundary(state);
2964
- let head = new Chunk(
2973
+ const head = new Chunk(
2965
2974
  boundary,
2966
2975
  null,
2967
2976
  null
@@ -2982,24 +2991,18 @@ var compat = {
2982
2991
  renderer(normalizedInput);
2983
2992
  });
2984
2993
  const asyncOut = classAPIOut.beginAsync();
2985
- (boundary.onNext = () => {
2986
- if (boundary.done) {
2994
+ queueMicrotask(
2995
+ boundary.onNext = () => {
2987
2996
  if (boundary.signal.aborted) {
2988
2997
  asyncOut.error(boundary.signal.reason);
2989
- } else {
2990
- queueMicrotask(() => {
2991
- head = prepareChunk(head);
2992
- if (boundary.done) {
2993
- const { scripts, html } = head;
2994
- asyncOut.script(scripts);
2995
- asyncOut.write(html);
2996
- asyncOut.end();
2997
- head.html = head.scripts = "";
2998
- }
2999
- });
2998
+ } else if (boundary.done) {
2999
+ const { scripts, html } = head.consume().flushScript();
3000
+ asyncOut.script(scripts);
3001
+ asyncOut.write(html);
3002
+ asyncOut.end();
3000
3003
  }
3001
3004
  }
3002
- })();
3005
+ );
3003
3006
  },
3004
3007
  registerRenderer(renderer, id) {
3005
3008
  return register(
@@ -3060,10 +3063,7 @@ function render(input = {}) {
3060
3063
  ...$global2
3061
3064
  };
3062
3065
  } else {
3063
- $global2 = {
3064
- runtimeId: DEFAULT_RUNTIME_ID,
3065
- renderId: DEFAULT_RENDER_ID
3066
- };
3066
+ $global2 = { runtimeId: DEFAULT_RUNTIME_ID, renderId: DEFAULT_RENDER_ID };
3067
3067
  }
3068
3068
  const head = new Chunk(
3069
3069
  new Boundary(new State2($global2), $global2.signal),
@@ -3127,19 +3127,13 @@ var ServerRenderResult = class {
3127
3127
  if (!(done || aborted)) {
3128
3128
  boundary?.abort(error);
3129
3129
  }
3130
- return Promise.resolve({
3131
- value: "",
3132
- done: true
3133
- });
3130
+ return Promise.resolve({ value: "", done: true });
3134
3131
  },
3135
3132
  return(value2) {
3136
3133
  if (!(done || aborted)) {
3137
3134
  boundary?.abort(new Error("Iterator returned before consumed."));
3138
3135
  }
3139
- return Promise.resolve({
3140
- value: value2,
3141
- done: true
3142
- });
3136
+ return Promise.resolve({ value: value2, done: true });
3143
3137
  }
3144
3138
  };
3145
3139
  function exec(_resolve, _reject) {
@@ -3194,7 +3188,7 @@ var ServerRenderResult = class {
3194
3188
  }
3195
3189
  #promise() {
3196
3190
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
3197
- let head = this.#head;
3191
+ const head = this.#head;
3198
3192
  this.#head = null;
3199
3193
  if (!head) {
3200
3194
  return reject(new Error("Cannot read from a consumed render result"));
@@ -3205,10 +3199,7 @@ var ServerRenderResult = class {
3205
3199
  boundary.onNext = NOOP2;
3206
3200
  reject(boundary.signal.reason);
3207
3201
  } else if (boundary.done) {
3208
- head = prepareChunk(head);
3209
- if (boundary.done) {
3210
- resolve(flushChunk(head, true));
3211
- }
3202
+ resolve(head.consume().flushHTML());
3212
3203
  }
3213
3204
  })();
3214
3205
  });
@@ -3228,13 +3219,11 @@ var ServerRenderResult = class {
3228
3219
  boundary.onNext = NOOP2;
3229
3220
  onAbort(boundary.signal.reason);
3230
3221
  } else {
3231
- if (write2 || boundary.done) {
3232
- head = prepareChunk(head);
3233
- }
3234
- if (write2 || boundary.done) {
3235
- const html = flushChunk(head, boundary.done);
3222
+ const { done } = boundary;
3223
+ if (done || write2) {
3224
+ const html = (head = head.consume()).flushHTML();
3236
3225
  if (html) onWrite(html);
3237
- if (boundary.done) {
3226
+ if (done) {
3238
3227
  if (!tick2) offTick(onNext);
3239
3228
  onClose();
3240
3229
  } else {
@@ -3251,10 +3240,10 @@ var ServerRenderResult = class {
3251
3240
  }
3252
3241
  toString() {
3253
3242
  const head = this.#head;
3254
- if (!head) throw new Error("Cannot read from a consumed render result");
3255
- if (head.next) throw new Error("Cannot fork in sync mode");
3256
3243
  this.#head = null;
3257
- return flushChunk(prepareChunk(head), true);
3244
+ if (!head) throw new Error("Cannot read from a consumed render result");
3245
+ if (!head.boundary.done) throw new Error("Cannot fork in sync mode");
3246
+ return head.consume().flushHTML();
3258
3247
  }
3259
3248
  };
3260
3249
  function NOOP2() {