marko 6.0.51 → 6.0.53

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,26 @@ var compat = {
3259
3261
  writeScript,
3260
3262
  nextScopeId,
3261
3263
  peekNextScopeId,
3264
+ isInResumedBranch,
3265
+ ensureState($global2) {
3266
+ let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3267
+ if (!state) {
3268
+ $global2.runtimeId ||= DEFAULT_RUNTIME_ID;
3269
+ $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || DEFAULT_RENDER_ID;
3270
+ $global2[K_TAGS_API_STATE] = state = new State2($global2);
3271
+ }
3272
+ return state;
3273
+ },
3262
3274
  isTagsAPI(fn) {
3263
3275
  return !!fn.___id;
3264
3276
  },
3277
+ onFlush(fn) {
3278
+ const { flushHTML } = Chunk.prototype;
3279
+ Chunk.prototype.flushHTML = function() {
3280
+ fn(this);
3281
+ return flushHTML.call(this);
3282
+ };
3283
+ },
3265
3284
  patchDynamicTag,
3266
3285
  writeSetScopeForComponent(branchId, m5c) {
3267
3286
  writeScope(branchId, { m5c });
@@ -3284,16 +3303,9 @@ var compat = {
3284
3303
  }
3285
3304
  return compatRegistered;
3286
3305
  },
3287
- render(renderer, willRerender, classAPIOut, component, input) {
3288
- const $global2 = classAPIOut.global;
3289
- let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3290
- if (!state) {
3291
- $global2.runtimeId ||= DEFAULT_RUNTIME_ID;
3292
- $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || DEFAULT_RENDER_ID;
3293
- $global2[K_TAGS_API_STATE] = state = new State2($global2);
3294
- }
3295
- const boundary = new Boundary(state);
3296
- const head = new Chunk(
3306
+ render(renderer, willRerender, classAPIOut, component, input, completeChunks) {
3307
+ const boundary = new Boundary(this.ensureState(classAPIOut.global));
3308
+ let head = new Chunk(
3297
3309
  boundary,
3298
3310
  null,
3299
3311
  null
@@ -3316,22 +3328,20 @@ var compat = {
3316
3328
  } else {
3317
3329
  renderer(normalizedInput);
3318
3330
  }
3319
- });
3320
- const asyncOut = classAPIOut.beginAsync();
3321
- queueMicrotask(
3322
- boundary.onNext = () => {
3331
+ const asyncOut = classAPIOut.beginAsync();
3332
+ (boundary.onNext = () => {
3323
3333
  if (boundary.signal.aborted) {
3324
3334
  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
- }
3335
+ boundary.onNext = NOOP3;
3336
+ } else if (!boundary.count) {
3337
+ completeChunks.push(head = head.consume());
3338
+ asyncOut.write(head.html);
3339
+ asyncOut.script(head.scripts);
3340
+ asyncOut.end();
3341
+ head.html = head.scripts = "";
3332
3342
  }
3333
- }
3334
- );
3343
+ })();
3344
+ });
3335
3345
  },
3336
3346
  registerRenderer(renderer, id) {
3337
3347
  return register(
@@ -3345,6 +3355,8 @@ var compat = {
3345
3355
  register(RENDER_BODY_ID, fn);
3346
3356
  }
3347
3357
  };
3358
+ function NOOP3() {
3359
+ }
3348
3360
  // Annotate the CommonJS export names for ESM import in node:
3349
3361
  0 && (module.exports = {
3350
3362
  $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,26 @@ var compat = {
3175
3177
  writeScript,
3176
3178
  nextScopeId,
3177
3179
  peekNextScopeId,
3180
+ isInResumedBranch,
3181
+ ensureState($global2) {
3182
+ let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3183
+ if (!state) {
3184
+ $global2.runtimeId ||= DEFAULT_RUNTIME_ID;
3185
+ $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || DEFAULT_RENDER_ID;
3186
+ $global2[K_TAGS_API_STATE] = state = new State2($global2);
3187
+ }
3188
+ return state;
3189
+ },
3178
3190
  isTagsAPI(fn) {
3179
3191
  return !!fn.___id;
3180
3192
  },
3193
+ onFlush(fn) {
3194
+ const { flushHTML } = Chunk.prototype;
3195
+ Chunk.prototype.flushHTML = function() {
3196
+ fn(this);
3197
+ return flushHTML.call(this);
3198
+ };
3199
+ },
3181
3200
  patchDynamicTag,
3182
3201
  writeSetScopeForComponent(branchId, m5c) {
3183
3202
  writeScope(branchId, { m5c });
@@ -3200,16 +3219,9 @@ var compat = {
3200
3219
  }
3201
3220
  return compatRegistered;
3202
3221
  },
3203
- render(renderer, willRerender, classAPIOut, component, input) {
3204
- const $global2 = classAPIOut.global;
3205
- let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3206
- if (!state) {
3207
- $global2.runtimeId ||= DEFAULT_RUNTIME_ID;
3208
- $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || DEFAULT_RENDER_ID;
3209
- $global2[K_TAGS_API_STATE] = state = new State2($global2);
3210
- }
3211
- const boundary = new Boundary(state);
3212
- const head = new Chunk(
3222
+ render(renderer, willRerender, classAPIOut, component, input, completeChunks) {
3223
+ const boundary = new Boundary(this.ensureState(classAPIOut.global));
3224
+ let head = new Chunk(
3213
3225
  boundary,
3214
3226
  null,
3215
3227
  null
@@ -3232,22 +3244,20 @@ var compat = {
3232
3244
  } else {
3233
3245
  renderer(normalizedInput);
3234
3246
  }
3235
- });
3236
- const asyncOut = classAPIOut.beginAsync();
3237
- queueMicrotask(
3238
- boundary.onNext = () => {
3247
+ const asyncOut = classAPIOut.beginAsync();
3248
+ (boundary.onNext = () => {
3239
3249
  if (boundary.signal.aborted) {
3240
3250
  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
- }
3251
+ boundary.onNext = NOOP3;
3252
+ } else if (!boundary.count) {
3253
+ completeChunks.push(head = head.consume());
3254
+ asyncOut.write(head.html);
3255
+ asyncOut.script(head.scripts);
3256
+ asyncOut.end();
3257
+ head.html = head.scripts = "";
3248
3258
  }
3249
- }
3250
- );
3259
+ })();
3260
+ });
3251
3261
  },
3252
3262
  registerRenderer(renderer, id) {
3253
3263
  return register(
@@ -3261,6 +3271,8 @@ var compat = {
3261
3271
  register(RENDER_BODY_ID, fn);
3262
3272
  }
3263
3273
  };
3274
+ function NOOP3() {
3275
+ }
3264
3276
  export {
3265
3277
  $global,
3266
3278
  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, State, write, writeScript } from "./writer";
4
4
  export declare const compat: {
5
5
  $global: typeof $global;
6
6
  fork: typeof fork;
@@ -8,11 +8,14 @@ export declare const compat: {
8
8
  writeScript: typeof writeScript;
9
9
  nextScopeId: typeof nextScopeId;
10
10
  peekNextScopeId: typeof peekNextScopeId;
11
+ isInResumedBranch: typeof isInResumedBranch;
12
+ ensureState($global: any): State;
11
13
  isTagsAPI(fn: any): boolean;
14
+ onFlush(fn: (chunk: Chunk) => void): void;
12
15
  patchDynamicTag: typeof patchDynamicTag;
13
16
  writeSetScopeForComponent(branchId: number, m5c: string): void;
14
17
  toJSON(this: WeakKey): [registryId: string, scopeId: unknown] | undefined;
15
- render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any): void;
18
+ render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any, completeChunks: Chunk[]): void;
16
19
  registerRenderer(renderer: any, id: string): any;
17
20
  registerRenderBody(fn: any): void;
18
21
  };
@@ -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,20 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2094
2096
  writeScript,
2095
2097
  nextScopeId,
2096
2098
  peekNextScopeId,
2099
+ isInResumedBranch,
2100
+ ensureState($global2) {
2101
+ let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2102
+ return state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2)), state;
2103
+ },
2097
2104
  isTagsAPI(fn) {
2098
2105
  return !!fn.h;
2099
2106
  },
2107
+ onFlush(fn) {
2108
+ let { flushHTML } = Chunk.prototype;
2109
+ Chunk.prototype.flushHTML = function() {
2110
+ return fn(this), flushHTML.call(this);
2111
+ };
2112
+ },
2100
2113
  patchDynamicTag,
2101
2114
  writeSetScopeForComponent(branchId, m5c) {
2102
2115
  writeScope(branchId, { m5c }), writeEffect(branchId, SET_SCOPE_REGISTER_ID);
@@ -2115,10 +2128,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2115
2128
  }
2116
2129
  return compatRegistered;
2117
2130
  },
2118
- render(renderer, willRerender, classAPIOut, component, input) {
2119
- let $global2 = classAPIOut.global, state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2120
- state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2));
2121
- let boundary = new Boundary(state), head = new Chunk(
2131
+ render(renderer, willRerender, classAPIOut, component, input, completeChunks) {
2132
+ let boundary = new Boundary(this.ensureState(classAPIOut.global)), head = new Chunk(
2122
2133
  boundary,
2123
2134
  null,
2124
2135
  null
@@ -2134,18 +2145,11 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2134
2145
  writeScope(scopeId, { m5c: component.id }), writeEffect(scopeId, SET_SCOPE_REGISTER_ID);
2135
2146
  }
2136
2147
  isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2148
+ let asyncOut = classAPIOut.beginAsync();
2149
+ (boundary.onNext = () => {
2150
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (completeChunks.push(head = head.consume()), asyncOut.write(head.html), asyncOut.script(head.scripts), asyncOut.end(), head.html = head.scripts = "");
2151
+ })();
2137
2152
  });
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
2153
  },
2150
2154
  registerRenderer(renderer, id) {
2151
2155
  return register(
@@ -2159,6 +2163,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2159
2163
  register(RENDER_BODY_ID, fn);
2160
2164
  }
2161
2165
  };
2166
+ function NOOP3() {
2167
+ }
2162
2168
  // Annotate the CommonJS export names for ESM import in node:
2163
2169
  0 && (module.exports = {
2164
2170
  $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,20 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2013
2015
  writeScript,
2014
2016
  nextScopeId,
2015
2017
  peekNextScopeId,
2018
+ isInResumedBranch,
2019
+ ensureState($global2) {
2020
+ let state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2021
+ return state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2)), state;
2022
+ },
2016
2023
  isTagsAPI(fn) {
2017
2024
  return !!fn.h;
2018
2025
  },
2026
+ onFlush(fn) {
2027
+ let { flushHTML } = Chunk.prototype;
2028
+ Chunk.prototype.flushHTML = function() {
2029
+ return fn(this), flushHTML.call(this);
2030
+ };
2031
+ },
2019
2032
  patchDynamicTag,
2020
2033
  writeSetScopeForComponent(branchId, m5c) {
2021
2034
  writeScope(branchId, { m5c }), writeEffect(branchId, SET_SCOPE_REGISTER_ID);
@@ -2034,10 +2047,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2034
2047
  }
2035
2048
  return compatRegistered;
2036
2049
  },
2037
- render(renderer, willRerender, classAPIOut, component, input) {
2038
- let $global2 = classAPIOut.global, state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2039
- state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2));
2040
- let boundary = new Boundary(state), head = new Chunk(
2050
+ render(renderer, willRerender, classAPIOut, component, input, completeChunks) {
2051
+ let boundary = new Boundary(this.ensureState(classAPIOut.global)), head = new Chunk(
2041
2052
  boundary,
2042
2053
  null,
2043
2054
  null
@@ -2053,18 +2064,11 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2053
2064
  writeScope(scopeId, { m5c: component.id }), writeEffect(scopeId, SET_SCOPE_REGISTER_ID);
2054
2065
  }
2055
2066
  isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2067
+ let asyncOut = classAPIOut.beginAsync();
2068
+ (boundary.onNext = () => {
2069
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (completeChunks.push(head = head.consume()), asyncOut.write(head.html), asyncOut.script(head.scripts), asyncOut.end(), head.html = head.scripts = "");
2070
+ })();
2056
2071
  });
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
2072
  },
2069
2073
  registerRenderer(renderer, id) {
2070
2074
  return register(
@@ -2078,6 +2082,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2078
2082
  register(RENDER_BODY_ID, fn);
2079
2083
  }
2080
2084
  };
2085
+ function NOOP3() {
2086
+ }
2081
2087
  export {
2082
2088
  $global,
2083
2089
  attr,
@@ -2673,7 +2673,12 @@ var [getWalkComment] = createSectionState(
2673
2673
  "walkComment",
2674
2674
  () => []
2675
2675
  );
2676
- var [getSteps] = createSectionState("steps", () => []);
2676
+ var [getSteps] = createSectionState("steps", (section) => {
2677
+ if (section.content?.startType === 1 /* Dynamic */) {
2678
+ return [0 /* Enter */, 1 /* Exit */];
2679
+ }
2680
+ return [];
2681
+ });
2677
2682
  var walkCodeToName = {
2678
2683
  [32 /* Get */]: "get",
2679
2684
  [36 /* Inside */]: "inside",
@@ -2692,17 +2697,23 @@ var walkCodeToName = {
2692
2697
  [126 /* MultiplierEnd */]: "multiplierEnd"
2693
2698
  };
2694
2699
  function enter2(path5) {
2695
- getSteps(getSection(path5)).push(0 /* Enter */);
2700
+ const steps = getSteps(getSection(path5));
2701
+ steps.push(0 /* Enter */);
2696
2702
  }
2697
2703
  function exit2(path5) {
2698
- getSteps(getSection(path5)).push(1 /* Exit */);
2704
+ const steps = getSteps(getSection(path5));
2705
+ steps.push(1 /* Exit */);
2699
2706
  }
2700
2707
  function enterShallow(path5) {
2701
- getSteps(getSection(path5)).push(0 /* Enter */, 1 /* Exit */);
2708
+ const section = getSection(path5);
2709
+ const steps = getSteps(section);
2710
+ steps.push(0 /* Enter */, 1 /* Exit */);
2702
2711
  }
2703
2712
  function injectWalks(tag, expr) {
2704
- const walks = getWalks(getSection(tag));
2705
- const walkComment = getWalkComment(getSection(tag));
2713
+ const section = getSection(tag);
2714
+ const walks = getWalks(section);
2715
+ const walkComment = getWalkComment(section);
2716
+ visitInternal(section);
2706
2717
  walkComment.push(
2707
2718
  `${walkCodeToName[tag.node.var ? 48 /* BeginChildWithVar */ : 47 /* BeginChild */]}`,
2708
2719
  expr.name,
@@ -2721,52 +2732,54 @@ function visit(path5, code) {
2721
2732
  return;
2722
2733
  }
2723
2734
  const section = getSection(path5);
2735
+ const walks = getWalks(section);
2736
+ const walkComment = getWalkComment(section);
2737
+ visitInternal(section);
2738
+ if (code !== 32 /* Get */) {
2739
+ writeTo(path5)`<!>`;
2740
+ }
2741
+ walkComment.push(`${walkCodeToName[code]}`);
2742
+ appendLiteral(walks, String.fromCharCode(code));
2743
+ }
2744
+ function visitInternal(section) {
2724
2745
  const steps = getSteps(section);
2746
+ if (!steps.length) return;
2725
2747
  const walks = getWalks(section);
2726
2748
  const walkComment = getWalkComment(section);
2749
+ const walkCodes = [];
2727
2750
  let walkString = "";
2728
- if (steps.length) {
2729
- const walkCodes = [];
2730
- let depth = 0;
2731
- for (const step of steps) {
2732
- if (step === 0 /* Enter */) {
2733
- depth++;
2734
- walkCodes.push(67 /* Next */);
2735
- } else {
2736
- depth--;
2737
- if (depth >= 0) {
2738
- walkCodes.length = walkCodes.lastIndexOf(67 /* Next */);
2739
- walkCodes.push(97 /* Over */);
2740
- } else {
2741
- walkCodes.length = walkCodes.lastIndexOf(107 /* Out */) + 1;
2742
- walkCodes.push(107 /* Out */);
2743
- depth = 0;
2744
- }
2745
- }
2746
- }
2747
- let current = walkCodes[0];
2748
- let count = 0;
2749
- for (const walk of walkCodes) {
2750
- if (walk !== current) {
2751
- walkComment.push(`${walkCodeToName[current]}(${count})`);
2752
- walkString += nCodeString(current, count);
2753
- current = walk;
2754
- count = 1;
2751
+ let depth = 0;
2752
+ for (const step of steps) {
2753
+ if (step === 0 /* Enter */) {
2754
+ depth++;
2755
+ walkCodes.push(67 /* Next */);
2756
+ } else {
2757
+ depth--;
2758
+ if (depth >= 0) {
2759
+ walkCodes.length = walkCodes.lastIndexOf(67 /* Next */);
2760
+ walkCodes.push(97 /* Over */);
2755
2761
  } else {
2756
- count++;
2762
+ walkCodes.length = walkCodes.lastIndexOf(107 /* Out */) + 1;
2763
+ walkCodes.push(107 /* Out */);
2764
+ depth = 0;
2757
2765
  }
2758
2766
  }
2759
- walkComment.push(`${walkCodeToName[current]}(${count})`);
2760
- walkString += nCodeString(current, count);
2761
- steps.length = 0;
2762
2767
  }
2763
- if (code !== void 0) {
2764
- if (code !== 32 /* Get */) {
2765
- writeTo(path5)`<!>`;
2768
+ let current = walkCodes[0];
2769
+ let count = 0;
2770
+ for (const walk of walkCodes) {
2771
+ if (walk !== current) {
2772
+ walkComment.push(`${walkCodeToName[current]}(${count})`);
2773
+ walkString += nCodeString(current, count);
2774
+ current = walk;
2775
+ count = 1;
2776
+ } else {
2777
+ count++;
2766
2778
  }
2767
- walkComment.push(`${walkCodeToName[code]}`);
2768
- walkString += String.fromCharCode(code);
2769
2779
  }
2780
+ walkComment.push(`${walkCodeToName[current]}(${count})`);
2781
+ walkString += nCodeString(current, count);
2782
+ steps.length = 0;
2770
2783
  appendLiteral(walks, walkString);
2771
2784
  }
2772
2785
  function nCodeString(code, number) {
@@ -2796,10 +2809,12 @@ function toCharString(number, startCode, rangeSize) {
2796
2809
  return result;
2797
2810
  }
2798
2811
  function getWalkString(section) {
2799
- const prefix2 = section.content?.startType === 1 /* Dynamic */ ? String.fromCharCode(67 /* Next */ + 1) : "";
2800
- const postfix = section.content?.endType === 1 /* Dynamic */ ? String.fromCharCode(67 /* Next */ + 1) : "";
2812
+ if (section.content?.endType === 1 /* Dynamic */) {
2813
+ getSteps(section).push(0 /* Enter */, 1 /* Exit */);
2814
+ }
2815
+ visitInternal(section);
2801
2816
  const walks = getWalks(section);
2802
- const walkLiteral = normalizeStringExpression([prefix2, ...walks, postfix]);
2817
+ const walkLiteral = normalizeStringExpression(walks);
2803
2818
  if (walkLiteral && walkLiteral.value !== "") {
2804
2819
  withLeadingComment(walkLiteral, getWalkComment(section).join(", "));
2805
2820
  }
@@ -4142,7 +4157,6 @@ function getRegisteredFnExpression2(node) {
4142
4157
  var dom_default = {
4143
4158
  translate: {
4144
4159
  exit(program) {
4145
- visit(program);
4146
4160
  const section = getSectionForBody(program);
4147
4161
  const { walks, writes, setup } = getSectionMeta(section);
4148
4162
  const domExports = program.node.extra.domExports;
@@ -5072,7 +5086,7 @@ function finalizeReferences() {
5072
5086
  let serializeReason;
5073
5087
  let currentSection = section;
5074
5088
  while (currentSection !== sourceSection) {
5075
- const upstreamReason = !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5089
+ const upstreamReason = currentSection.downstreamBinding ? isSerializedSection(currentSection) || void 0 : !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5076
5090
  if (upstreamReason === true) {
5077
5091
  serializeReason = true;
5078
5092
  break;
@@ -5098,7 +5112,7 @@ function finalizeReferences() {
5098
5112
  let serializeReason;
5099
5113
  let currentSection = section;
5100
5114
  while (currentSection !== sourceSection) {
5101
- const upstreamReason = !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5115
+ const upstreamReason = currentSection.downstreamBinding ? isSerializedSection(currentSection) || void 0 : !currentSection.upstreamExpression || getSerializeSourcesForExpr(currentSection.upstreamExpression);
5102
5116
  if (upstreamReason === true) {
5103
5117
  serializeReason = true;
5104
5118
  break;
@@ -10499,7 +10513,6 @@ var custom_tag_default = {
10499
10513
  },
10500
10514
  translate: {
10501
10515
  enter(tag) {
10502
- visit(tag);
10503
10516
  if (isOutputHTML()) {
10504
10517
  flushBefore(tag);
10505
10518
  }
@@ -10,6 +10,6 @@ export declare function enter(path: t.NodePath<any>): void;
10
10
  export declare function exit(path: t.NodePath<any>): void;
11
11
  export declare function enterShallow(path: t.NodePath<any>): void;
12
12
  export declare function injectWalks(tag: t.NodePath<t.MarkoTag>, expr: t.Expression): void;
13
- export declare function visit(path: t.NodePath<t.MarkoTag | t.MarkoPlaceholder | t.Program>, code?: VisitCodes): void;
13
+ export declare function visit(path: t.NodePath<t.MarkoTag | t.MarkoPlaceholder | t.Program>, code: VisitCodes): void;
14
14
  export declare function getWalkString(section: Section): t.Expression | undefined;
15
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.51",
3
+ "version": "6.0.53",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",