marko 6.0.51 → 6.0.52

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/debug/dom.js CHANGED
@@ -2220,7 +2220,9 @@ var compat = {
2220
2220
  branch.___endNode = endNode;
2221
2221
  },
2222
2222
  runComponentEffects() {
2223
- runEffects(this.effects);
2223
+ if (this.effects) {
2224
+ runEffects(this.effects);
2225
+ }
2224
2226
  },
2225
2227
  runComponentDestroy() {
2226
2228
  if (this.scope) {
@@ -2247,14 +2249,11 @@ var compat = {
2247
2249
  },
2248
2250
  render(out, component, renderer, args) {
2249
2251
  let branch = component.scope;
2250
- if (!branch) {
2251
- branch = classIdToBranch.get(component.id);
2252
- if (branch) {
2253
- component.scope = branch;
2254
- classIdToBranch.delete(component.id);
2255
- }
2252
+ let created = 0;
2253
+ if (!branch && (branch = classIdToBranch.get(component.id))) {
2254
+ component.scope = branch;
2255
+ classIdToBranch.delete(component.id);
2256
2256
  }
2257
- let existing;
2258
2257
  if (typeof args[0] === "object" && "renderBody" in args[0]) {
2259
2258
  const input = args[0];
2260
2259
  const normalizedInput = args[0] = {};
@@ -2264,6 +2263,7 @@ var compat = {
2264
2263
  }
2265
2264
  component.effects = prepareEffects(() => {
2266
2265
  if (!branch) {
2266
+ created = 1;
2267
2267
  out.global.___nextScopeId ||= 0;
2268
2268
  branch = component.scope = createAndSetupBranch(
2269
2269
  out.global,
@@ -2271,12 +2271,10 @@ var compat = {
2271
2271
  renderer.___owner,
2272
2272
  document.body
2273
2273
  );
2274
- } else {
2275
- existing = 1;
2276
2274
  }
2277
2275
  renderer.___params?.(branch, renderer._ ? args[0] : args);
2278
2276
  });
2279
- if (!existing) {
2277
+ if (created) {
2280
2278
  return toInsertNode(branch.___startNode, branch.___endNode);
2281
2279
  }
2282
2280
  }
@@ -2124,7 +2124,9 @@ var compat = {
2124
2124
  branch.___endNode = endNode;
2125
2125
  },
2126
2126
  runComponentEffects() {
2127
- runEffects(this.effects);
2127
+ if (this.effects) {
2128
+ runEffects(this.effects);
2129
+ }
2128
2130
  },
2129
2131
  runComponentDestroy() {
2130
2132
  if (this.scope) {
@@ -2151,14 +2153,11 @@ var compat = {
2151
2153
  },
2152
2154
  render(out, component, renderer, args) {
2153
2155
  let branch = component.scope;
2154
- if (!branch) {
2155
- branch = classIdToBranch.get(component.id);
2156
- if (branch) {
2157
- component.scope = branch;
2158
- classIdToBranch.delete(component.id);
2159
- }
2156
+ let created = 0;
2157
+ if (!branch && (branch = classIdToBranch.get(component.id))) {
2158
+ component.scope = branch;
2159
+ classIdToBranch.delete(component.id);
2160
2160
  }
2161
- let existing;
2162
2161
  if (typeof args[0] === "object" && "renderBody" in args[0]) {
2163
2162
  const input = args[0];
2164
2163
  const normalizedInput = args[0] = {};
@@ -2168,6 +2167,7 @@ var compat = {
2168
2167
  }
2169
2168
  component.effects = prepareEffects(() => {
2170
2169
  if (!branch) {
2170
+ created = 1;
2171
2171
  out.global.___nextScopeId ||= 0;
2172
2172
  branch = component.scope = createAndSetupBranch(
2173
2173
  out.global,
@@ -2175,12 +2175,10 @@ var compat = {
2175
2175
  renderer.___owner,
2176
2176
  document.body
2177
2177
  );
2178
- } else {
2179
- existing = 1;
2180
2178
  }
2181
2179
  renderer.___params?.(branch, renderer._ ? args[0] : args);
2182
2180
  });
2183
- if (!existing) {
2181
+ if (created) {
2184
2182
  return toInsertNode(branch.___startNode, branch.___endNode);
2185
2183
  }
2186
2184
  }
@@ -1821,6 +1821,9 @@ function resumeClosestBranch(scopeId) {
1821
1821
  }
1822
1822
  }
1823
1823
  var branchIdKey = Symbol();
1824
+ function isInResumedBranch() {
1825
+ return $chunk?.context?.[branchIdKey] !== void 0;
1826
+ }
1824
1827
  function withBranchId(branchId, cb) {
1825
1828
  return withContext(branchIdKey, branchId, cb);
1826
1829
  }
@@ -2402,7 +2405,6 @@ var Chunk = class {
2402
2405
  }
2403
2406
  }
2404
2407
  flushScript() {
2405
- flushSerializer(this.boundary);
2406
2408
  const { boundary, effects } = this;
2407
2409
  const { state } = boundary;
2408
2410
  const { $global: $global2, runtimePrefix, nonceAttr } = state;
@@ -3058,7 +3060,7 @@ var ServerRendered = class {
3058
3060
  if (boundary.signal.aborted) {
3059
3061
  boundary.onNext = NOOP2;
3060
3062
  reject(boundary.signal.reason);
3061
- } else if (boundary.done) {
3063
+ } else if (!boundary.count && boundary.done) {
3062
3064
  resolve(head.consume().flushHTML());
3063
3065
  }
3064
3066
  })();
@@ -3236,7 +3238,7 @@ function registerContent(id, fn, scopeId) {
3236
3238
  function patchDynamicTag(patch) {
3237
3239
  dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
3238
3240
  const patched = patch(scopeId, accessor, tag);
3239
- patched.___id = tag;
3241
+ if (patched !== tag) patched.___id = tag;
3240
3242
  return originalDynamicTag(
3241
3243
  scopeId,
3242
3244
  accessor,
@@ -3259,9 +3261,17 @@ var compat = {
3259
3261
  writeScript,
3260
3262
  nextScopeId,
3261
3263
  peekNextScopeId,
3264
+ isInResumedBranch,
3262
3265
  isTagsAPI(fn) {
3263
3266
  return !!fn.___id;
3264
3267
  },
3268
+ onFlush(fn) {
3269
+ const { flushHTML } = Chunk.prototype;
3270
+ Chunk.prototype.flushHTML = function() {
3271
+ fn(this);
3272
+ return flushHTML.call(this);
3273
+ };
3274
+ },
3265
3275
  patchDynamicTag,
3266
3276
  writeSetScopeForComponent(branchId, m5c) {
3267
3277
  writeScope(branchId, { m5c });
@@ -3284,7 +3294,7 @@ var compat = {
3284
3294
  }
3285
3295
  return compatRegistered;
3286
3296
  },
3287
- render(renderer, willRerender, classAPIOut, component, input) {
3297
+ render(renderer, willRerender, classAPIOut, component, input, toStringEvent) {
3288
3298
  const $global2 = classAPIOut.global;
3289
3299
  let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3290
3300
  if (!state) {
@@ -3293,7 +3303,7 @@ var compat = {
3293
3303
  $global2[K_TAGS_API_STATE] = state = new State2($global2);
3294
3304
  }
3295
3305
  const boundary = new Boundary(state);
3296
- const head = new Chunk(
3306
+ let head = new Chunk(
3297
3307
  boundary,
3298
3308
  null,
3299
3309
  null
@@ -3316,22 +3326,30 @@ var compat = {
3316
3326
  } else {
3317
3327
  renderer(normalizedInput);
3318
3328
  }
3319
- });
3320
- const asyncOut = classAPIOut.beginAsync();
3321
- queueMicrotask(
3322
- boundary.onNext = () => {
3329
+ const asyncOut = classAPIOut.beginAsync();
3330
+ (boundary.onNext = () => {
3323
3331
  if (boundary.signal.aborted) {
3324
3332
  asyncOut.error(boundary.signal.reason);
3325
- } else if (boundary.done) {
3326
- const { scripts, html } = head.consume().flushScript();
3327
- asyncOut.script(scripts);
3328
- asyncOut.write(html);
3329
- if (boundary.done) {
3330
- asyncOut.end();
3331
- }
3333
+ boundary.onNext = NOOP3;
3334
+ } else if (!boundary.count) {
3335
+ asyncOut.once(toStringEvent, (writer) => {
3336
+ if (boundary.done) {
3337
+ const { html, scripts } = head.flushScript();
3338
+ writer.script(scripts);
3339
+ writer.write(html);
3340
+ } else {
3341
+ asyncOut.error(
3342
+ new Error("Cannot serialize promises with class/tags interop.")
3343
+ );
3344
+ }
3345
+ });
3346
+ head = head.consume();
3347
+ asyncOut.write(head.html);
3348
+ asyncOut.end();
3349
+ head.html = "";
3332
3350
  }
3333
- }
3334
- );
3351
+ })();
3352
+ });
3335
3353
  },
3336
3354
  registerRenderer(renderer, id) {
3337
3355
  return register(
@@ -3345,6 +3363,8 @@ var compat = {
3345
3363
  register(RENDER_BODY_ID, fn);
3346
3364
  }
3347
3365
  };
3366
+ function NOOP3() {
3367
+ }
3348
3368
  // Annotate the CommonJS export names for ESM import in node:
3349
3369
  0 && (module.exports = {
3350
3370
  $global,
@@ -1737,6 +1737,9 @@ function resumeClosestBranch(scopeId) {
1737
1737
  }
1738
1738
  }
1739
1739
  var branchIdKey = Symbol();
1740
+ function isInResumedBranch() {
1741
+ return $chunk?.context?.[branchIdKey] !== void 0;
1742
+ }
1740
1743
  function withBranchId(branchId, cb) {
1741
1744
  return withContext(branchIdKey, branchId, cb);
1742
1745
  }
@@ -2318,7 +2321,6 @@ var Chunk = class {
2318
2321
  }
2319
2322
  }
2320
2323
  flushScript() {
2321
- flushSerializer(this.boundary);
2322
2324
  const { boundary, effects } = this;
2323
2325
  const { state } = boundary;
2324
2326
  const { $global: $global2, runtimePrefix, nonceAttr } = state;
@@ -2974,7 +2976,7 @@ var ServerRendered = class {
2974
2976
  if (boundary.signal.aborted) {
2975
2977
  boundary.onNext = NOOP2;
2976
2978
  reject(boundary.signal.reason);
2977
- } else if (boundary.done) {
2979
+ } else if (!boundary.count && boundary.done) {
2978
2980
  resolve(head.consume().flushHTML());
2979
2981
  }
2980
2982
  })();
@@ -3152,7 +3154,7 @@ function registerContent(id, fn, scopeId) {
3152
3154
  function patchDynamicTag(patch) {
3153
3155
  dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
3154
3156
  const patched = patch(scopeId, accessor, tag);
3155
- patched.___id = tag;
3157
+ if (patched !== tag) patched.___id = tag;
3156
3158
  return originalDynamicTag(
3157
3159
  scopeId,
3158
3160
  accessor,
@@ -3175,9 +3177,17 @@ var compat = {
3175
3177
  writeScript,
3176
3178
  nextScopeId,
3177
3179
  peekNextScopeId,
3180
+ isInResumedBranch,
3178
3181
  isTagsAPI(fn) {
3179
3182
  return !!fn.___id;
3180
3183
  },
3184
+ onFlush(fn) {
3185
+ const { flushHTML } = Chunk.prototype;
3186
+ Chunk.prototype.flushHTML = function() {
3187
+ fn(this);
3188
+ return flushHTML.call(this);
3189
+ };
3190
+ },
3181
3191
  patchDynamicTag,
3182
3192
  writeSetScopeForComponent(branchId, m5c) {
3183
3193
  writeScope(branchId, { m5c });
@@ -3200,7 +3210,7 @@ var compat = {
3200
3210
  }
3201
3211
  return compatRegistered;
3202
3212
  },
3203
- render(renderer, willRerender, classAPIOut, component, input) {
3213
+ render(renderer, willRerender, classAPIOut, component, input, toStringEvent) {
3204
3214
  const $global2 = classAPIOut.global;
3205
3215
  let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3206
3216
  if (!state) {
@@ -3209,7 +3219,7 @@ var compat = {
3209
3219
  $global2[K_TAGS_API_STATE] = state = new State2($global2);
3210
3220
  }
3211
3221
  const boundary = new Boundary(state);
3212
- const head = new Chunk(
3222
+ let head = new Chunk(
3213
3223
  boundary,
3214
3224
  null,
3215
3225
  null
@@ -3232,22 +3242,30 @@ var compat = {
3232
3242
  } else {
3233
3243
  renderer(normalizedInput);
3234
3244
  }
3235
- });
3236
- const asyncOut = classAPIOut.beginAsync();
3237
- queueMicrotask(
3238
- boundary.onNext = () => {
3245
+ const asyncOut = classAPIOut.beginAsync();
3246
+ (boundary.onNext = () => {
3239
3247
  if (boundary.signal.aborted) {
3240
3248
  asyncOut.error(boundary.signal.reason);
3241
- } else if (boundary.done) {
3242
- const { scripts, html } = head.consume().flushScript();
3243
- asyncOut.script(scripts);
3244
- asyncOut.write(html);
3245
- if (boundary.done) {
3246
- asyncOut.end();
3247
- }
3249
+ boundary.onNext = NOOP3;
3250
+ } else if (!boundary.count) {
3251
+ asyncOut.once(toStringEvent, (writer) => {
3252
+ if (boundary.done) {
3253
+ const { html, scripts } = head.flushScript();
3254
+ writer.script(scripts);
3255
+ writer.write(html);
3256
+ } else {
3257
+ asyncOut.error(
3258
+ new Error("Cannot serialize promises with class/tags interop.")
3259
+ );
3260
+ }
3261
+ });
3262
+ head = head.consume();
3263
+ asyncOut.write(head.html);
3264
+ asyncOut.end();
3265
+ head.html = "";
3248
3266
  }
3249
- }
3250
- );
3267
+ })();
3268
+ });
3251
3269
  },
3252
3270
  registerRenderer(renderer, id) {
3253
3271
  return register(
@@ -3261,6 +3279,8 @@ var compat = {
3261
3279
  register(RENDER_BODY_ID, fn);
3262
3280
  }
3263
3281
  };
3282
+ function NOOP3() {
3283
+ }
3264
3284
  export {
3265
3285
  $global,
3266
3286
  attr,
package/dist/dom.js CHANGED
@@ -1456,7 +1456,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1456
1456
  branch.h = startNode, branch.j = endNode;
1457
1457
  },
1458
1458
  runComponentEffects() {
1459
- runEffects(this.effects);
1459
+ this.effects && runEffects(this.effects);
1460
1460
  },
1461
1461
  runComponentDestroy() {
1462
1462
  this.scope && destroyBranch(this.scope);
@@ -1475,22 +1475,20 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1475
1475
  }, renderer;
1476
1476
  },
1477
1477
  render(out, component, renderer, args) {
1478
- let branch = component.scope;
1479
- branch || (branch = classIdToBranch.get(component.id), branch && (component.scope = branch, classIdToBranch.delete(component.id)));
1480
- let existing;
1481
- if (typeof args[0] == "object" && "renderBody" in args[0]) {
1478
+ let branch = component.scope, created = 0;
1479
+ if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), typeof args[0] == "object" && "renderBody" in args[0]) {
1482
1480
  let input = args[0], normalizedInput = args[0] = {};
1483
1481
  for (let key in input)
1484
1482
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1485
1483
  }
1486
1484
  if (component.effects = prepareEffects(() => {
1487
- branch ? existing = 1 : (out.global.p ||= 0, branch = component.scope = createAndSetupBranch(
1485
+ branch || (created = 1, out.global.p ||= 0, branch = component.scope = createAndSetupBranch(
1488
1486
  out.global,
1489
1487
  renderer,
1490
1488
  renderer.u,
1491
1489
  document.body
1492
1490
  )), renderer.m?.(branch, renderer._ ? args[0] : args);
1493
- }), !existing)
1491
+ }), created)
1494
1492
  return toInsertNode(branch.h, branch.j);
1495
1493
  }
1496
1494
  };
package/dist/dom.mjs CHANGED
@@ -1363,7 +1363,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1363
1363
  branch.h = startNode, branch.j = endNode;
1364
1364
  },
1365
1365
  runComponentEffects() {
1366
- runEffects(this.effects);
1366
+ this.effects && runEffects(this.effects);
1367
1367
  },
1368
1368
  runComponentDestroy() {
1369
1369
  this.scope && destroyBranch(this.scope);
@@ -1382,22 +1382,20 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1382
1382
  }, renderer;
1383
1383
  },
1384
1384
  render(out, component, renderer, args) {
1385
- let branch = component.scope;
1386
- branch || (branch = classIdToBranch.get(component.id), branch && (component.scope = branch, classIdToBranch.delete(component.id)));
1387
- let existing;
1388
- if (typeof args[0] == "object" && "renderBody" in args[0]) {
1385
+ let branch = component.scope, created = 0;
1386
+ if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), typeof args[0] == "object" && "renderBody" in args[0]) {
1389
1387
  let input = args[0], normalizedInput = args[0] = {};
1390
1388
  for (let key in input)
1391
1389
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1392
1390
  }
1393
1391
  if (component.effects = prepareEffects(() => {
1394
- branch ? existing = 1 : (out.global.p ||= 0, branch = component.scope = createAndSetupBranch(
1392
+ branch || (created = 1, out.global.p ||= 0, branch = component.scope = createAndSetupBranch(
1395
1393
  out.global,
1396
1394
  renderer,
1397
1395
  renderer.u,
1398
1396
  document.body
1399
1397
  )), renderer.m?.(branch, renderer._ ? args[0] : args);
1400
- }), !existing)
1398
+ }), created)
1401
1399
  return toInsertNode(branch.h, branch.j);
1402
1400
  }
1403
1401
  };
@@ -1,6 +1,6 @@
1
1
  import { patchDynamicTag } from "./dynamic-tag";
2
2
  import { type ServerRenderer } from "./template";
3
- import { $global, fork, nextScopeId, peekNextScopeId, write, writeScript } from "./writer";
3
+ import { $global, Chunk, fork, isInResumedBranch, nextScopeId, peekNextScopeId, write, writeScript } from "./writer";
4
4
  export declare const compat: {
5
5
  $global: typeof $global;
6
6
  fork: typeof fork;
@@ -8,11 +8,13 @@ export declare const compat: {
8
8
  writeScript: typeof writeScript;
9
9
  nextScopeId: typeof nextScopeId;
10
10
  peekNextScopeId: typeof peekNextScopeId;
11
+ isInResumedBranch: typeof isInResumedBranch;
11
12
  isTagsAPI(fn: any): boolean;
13
+ onFlush(fn: (chunk: Chunk) => void): void;
12
14
  patchDynamicTag: typeof patchDynamicTag;
13
15
  writeSetScopeForComponent(branchId: number, m5c: string): void;
14
16
  toJSON(this: WeakKey): [registryId: string, scopeId: unknown] | undefined;
15
- render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any): void;
17
+ render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any, toStringEvent: string): void;
16
18
  registerRenderer(renderer: any, id: string): any;
17
19
  registerRenderBody(fn: any): void;
18
20
  };
@@ -37,6 +37,7 @@ export declare function hoist(scopeId: number, id?: string): {
37
37
  [Symbol.iterator]: /*elided*/ any;
38
38
  };
39
39
  export declare function resumeClosestBranch(scopeId: number): void;
40
+ export declare function isInResumedBranch(): boolean;
40
41
  export declare function withBranchId<T>(branchId: number, cb: () => T): T;
41
42
  export declare function resumeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, by: Falsy | ((item: unknown, index: number) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
42
43
  export declare function resumeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, by: Falsy | ((key: string, v: unknown) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
package/dist/html.js CHANGED
@@ -1182,6 +1182,9 @@ function resumeClosestBranch(scopeId) {
1182
1182
  branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { g: branchId });
1183
1183
  }
1184
1184
  var branchIdKey = Symbol();
1185
+ function isInResumedBranch() {
1186
+ return $chunk?.context?.[branchIdKey] !== void 0;
1187
+ }
1185
1188
  function withBranchId(branchId, cb) {
1186
1189
  return withContext(branchIdKey, branchId, cb);
1187
1190
  }
@@ -1539,7 +1542,6 @@ var State2 = class {
1539
1542
  }
1540
1543
  }
1541
1544
  flushScript() {
1542
- flushSerializer(this.boundary);
1543
1545
  let { boundary, effects } = this, { state } = boundary, { $global: $global2, runtimePrefix, nonceAttr } = state, { html, scripts } = this, hasWalk = state.walkOnNextFlush;
1544
1546
  if (hasWalk && (state.walkOnNextFlush = !1), state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1545
1547
  scripts,
@@ -1958,7 +1960,7 @@ var ServerRendered = class {
1958
1960
  return reject(new Error("Cannot read from a consumed render result"));
1959
1961
  let { boundary } = head;
1960
1962
  (boundary.onNext = () => {
1961
- boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && resolve(head.consume().flushHTML());
1963
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : !boundary.count && boundary.done && resolve(head.consume().flushHTML());
1962
1964
  })();
1963
1965
  });
1964
1966
  }
@@ -2074,7 +2076,7 @@ function registerContent(id, fn, scopeId) {
2074
2076
  function patchDynamicTag(patch) {
2075
2077
  dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
2076
2078
  let patched = patch(scopeId, accessor, tag);
2077
- return patched.h = tag, originalDynamicTag(
2079
+ return patched !== tag && (patched.h = tag), originalDynamicTag(
2078
2080
  scopeId,
2079
2081
  accessor,
2080
2082
  patched,
@@ -2094,9 +2096,16 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2094
2096
  writeScript,
2095
2097
  nextScopeId,
2096
2098
  peekNextScopeId,
2099
+ isInResumedBranch,
2097
2100
  isTagsAPI(fn) {
2098
2101
  return !!fn.h;
2099
2102
  },
2103
+ onFlush(fn) {
2104
+ let { flushHTML } = Chunk.prototype;
2105
+ Chunk.prototype.flushHTML = function() {
2106
+ return fn(this), flushHTML.call(this);
2107
+ };
2108
+ },
2100
2109
  patchDynamicTag,
2101
2110
  writeSetScopeForComponent(branchId, m5c) {
2102
2111
  writeScope(branchId, { m5c }), writeEffect(branchId, SET_SCOPE_REGISTER_ID);
@@ -2115,7 +2124,7 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2115
2124
  }
2116
2125
  return compatRegistered;
2117
2126
  },
2118
- render(renderer, willRerender, classAPIOut, component, input) {
2127
+ render(renderer, willRerender, classAPIOut, component, input, toStringEvent) {
2119
2128
  let $global2 = classAPIOut.global, state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2120
2129
  state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2));
2121
2130
  let boundary = new Boundary(state), head = new Chunk(
@@ -2134,18 +2143,19 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2134
2143
  writeScope(scopeId, { m5c: component.id }), writeEffect(scopeId, SET_SCOPE_REGISTER_ID);
2135
2144
  }
2136
2145
  isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2146
+ let asyncOut = classAPIOut.beginAsync();
2147
+ (boundary.onNext = () => {
2148
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (asyncOut.once(toStringEvent, (writer) => {
2149
+ if (boundary.done) {
2150
+ let { html, scripts } = head.flushScript();
2151
+ writer.script(scripts), writer.write(html);
2152
+ } else
2153
+ asyncOut.error(
2154
+ new Error("Cannot serialize promises with class/tags interop.")
2155
+ );
2156
+ }), head = head.consume(), asyncOut.write(head.html), asyncOut.end(), head.html = "");
2157
+ })();
2137
2158
  });
2138
- let asyncOut = classAPIOut.beginAsync();
2139
- queueMicrotask(
2140
- boundary.onNext = () => {
2141
- if (boundary.signal.aborted)
2142
- asyncOut.error(boundary.signal.reason);
2143
- else if (boundary.done) {
2144
- let { scripts, html } = head.consume().flushScript();
2145
- asyncOut.script(scripts), asyncOut.write(html), boundary.done && asyncOut.end();
2146
- }
2147
- }
2148
- );
2149
2159
  },
2150
2160
  registerRenderer(renderer, id) {
2151
2161
  return register(
@@ -2159,6 +2169,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2159
2169
  register(RENDER_BODY_ID, fn);
2160
2170
  }
2161
2171
  };
2172
+ function NOOP3() {
2173
+ }
2162
2174
  // Annotate the CommonJS export names for ESM import in node:
2163
2175
  0 && (module.exports = {
2164
2176
  $global,
package/dist/html.mjs CHANGED
@@ -1101,6 +1101,9 @@ function resumeClosestBranch(scopeId) {
1101
1101
  branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { g: branchId });
1102
1102
  }
1103
1103
  var branchIdKey = Symbol();
1104
+ function isInResumedBranch() {
1105
+ return $chunk?.context?.[branchIdKey] !== void 0;
1106
+ }
1104
1107
  function withBranchId(branchId, cb) {
1105
1108
  return withContext(branchIdKey, branchId, cb);
1106
1109
  }
@@ -1458,7 +1461,6 @@ var State2 = class {
1458
1461
  }
1459
1462
  }
1460
1463
  flushScript() {
1461
- flushSerializer(this.boundary);
1462
1464
  let { boundary, effects } = this, { state } = boundary, { $global: $global2, runtimePrefix, nonceAttr } = state, { html, scripts } = this, hasWalk = state.walkOnNextFlush;
1463
1465
  if (hasWalk && (state.walkOnNextFlush = !1), state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1464
1466
  scripts,
@@ -1877,7 +1879,7 @@ var ServerRendered = class {
1877
1879
  return reject(new Error("Cannot read from a consumed render result"));
1878
1880
  let { boundary } = head;
1879
1881
  (boundary.onNext = () => {
1880
- boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && resolve(head.consume().flushHTML());
1882
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : !boundary.count && boundary.done && resolve(head.consume().flushHTML());
1881
1883
  })();
1882
1884
  });
1883
1885
  }
@@ -1993,7 +1995,7 @@ function registerContent(id, fn, scopeId) {
1993
1995
  function patchDynamicTag(patch) {
1994
1996
  dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
1995
1997
  let patched = patch(scopeId, accessor, tag);
1996
- return patched.h = tag, originalDynamicTag(
1998
+ return patched !== tag && (patched.h = tag), originalDynamicTag(
1997
1999
  scopeId,
1998
2000
  accessor,
1999
2001
  patched,
@@ -2013,9 +2015,16 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2013
2015
  writeScript,
2014
2016
  nextScopeId,
2015
2017
  peekNextScopeId,
2018
+ isInResumedBranch,
2016
2019
  isTagsAPI(fn) {
2017
2020
  return !!fn.h;
2018
2021
  },
2022
+ onFlush(fn) {
2023
+ let { flushHTML } = Chunk.prototype;
2024
+ Chunk.prototype.flushHTML = function() {
2025
+ return fn(this), flushHTML.call(this);
2026
+ };
2027
+ },
2019
2028
  patchDynamicTag,
2020
2029
  writeSetScopeForComponent(branchId, m5c) {
2021
2030
  writeScope(branchId, { m5c }), writeEffect(branchId, SET_SCOPE_REGISTER_ID);
@@ -2034,7 +2043,7 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2034
2043
  }
2035
2044
  return compatRegistered;
2036
2045
  },
2037
- render(renderer, willRerender, classAPIOut, component, input) {
2046
+ render(renderer, willRerender, classAPIOut, component, input, toStringEvent) {
2038
2047
  let $global2 = classAPIOut.global, state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2039
2048
  state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2));
2040
2049
  let boundary = new Boundary(state), head = new Chunk(
@@ -2053,18 +2062,19 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2053
2062
  writeScope(scopeId, { m5c: component.id }), writeEffect(scopeId, SET_SCOPE_REGISTER_ID);
2054
2063
  }
2055
2064
  isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2065
+ let asyncOut = classAPIOut.beginAsync();
2066
+ (boundary.onNext = () => {
2067
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (asyncOut.once(toStringEvent, (writer) => {
2068
+ if (boundary.done) {
2069
+ let { html, scripts } = head.flushScript();
2070
+ writer.script(scripts), writer.write(html);
2071
+ } else
2072
+ asyncOut.error(
2073
+ new Error("Cannot serialize promises with class/tags interop.")
2074
+ );
2075
+ }), head = head.consume(), asyncOut.write(head.html), asyncOut.end(), head.html = "");
2076
+ })();
2056
2077
  });
2057
- let asyncOut = classAPIOut.beginAsync();
2058
- queueMicrotask(
2059
- boundary.onNext = () => {
2060
- if (boundary.signal.aborted)
2061
- asyncOut.error(boundary.signal.reason);
2062
- else if (boundary.done) {
2063
- let { scripts, html } = head.consume().flushScript();
2064
- asyncOut.script(scripts), asyncOut.write(html), boundary.done && asyncOut.end();
2065
- }
2066
- }
2067
- );
2068
2078
  },
2069
2079
  registerRenderer(renderer, id) {
2070
2080
  return register(
@@ -2078,6 +2088,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2078
2088
  register(RENDER_BODY_ID, fn);
2079
2089
  }
2080
2090
  };
2091
+ function NOOP3() {
2092
+ }
2081
2093
  export {
2082
2094
  $global,
2083
2095
  attr,
@@ -5072,7 +5072,7 @@ function finalizeReferences() {
5072
5072
  let serializeReason;
5073
5073
  let currentSection = section;
5074
5074
  while (currentSection !== sourceSection) {
5075
- const upstreamReason = !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5075
+ const upstreamReason = currentSection.downstreamBinding ? isSerializedSection(currentSection) || void 0 : !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5076
5076
  if (upstreamReason === true) {
5077
5077
  serializeReason = true;
5078
5078
  break;
@@ -5098,7 +5098,7 @@ function finalizeReferences() {
5098
5098
  let serializeReason;
5099
5099
  let currentSection = section;
5100
5100
  while (currentSection !== sourceSection) {
5101
- const upstreamReason = !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5101
+ const upstreamReason = currentSection.downstreamBinding ? isSerializedSection(currentSection) || void 0 : !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5102
5102
  if (upstreamReason === true) {
5103
5103
  serializeReason = true;
5104
5104
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.51",
3
+ "version": "6.0.52",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",