@openelement/protocol 1.0.0-alpha.14 → 1.0.0-alpha.16

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.
@@ -3,10 +3,10 @@ import { forbiddenSinkReason, isSafeAttributeName } from "./forbidden-sinks.js";
3
3
  import { VOID_TAGS } from "./void-tags.js";
4
4
  //#region src/part-program.ts
5
5
  /**
6
- * @openelement/element — serializable Part Program v1 protocol.
6
+ * @openelement/element — serializable Part Program v2 protocol.
7
7
  *
8
8
  * The canonical exchange artifact shared by the compiler semantic core, the
9
- * server serializer, fresh DOM creation, and existing-DOM claim. Its only
9
+ * server serializer, fresh DOM creation, and existing-DOM hydration. Its only
10
10
  * imports are the import-free, host-free canonical owners — VOID_TAGS,
11
11
  * forbidden sinks, and the error contract (#1386 item 3); all three are
12
12
  * import-free, so the artifact keeps its freedom from runtime/host edges. The
@@ -15,24 +15,10 @@ import { VOID_TAGS } from "./void-tags.js";
15
15
  * receives a compiler-owned identity. Runtime code does not discover bindings
16
16
  * by walking a VNode or a generic DOM tree.
17
17
  */
18
- /** The Part Program IR version this package defines (currently v1). */
19
- const PART_PROGRAM_VERSION = 1;
18
+ /** The Part Program IR version this package defines (currently v2). */
19
+ const PART_PROGRAM_VERSION = 2;
20
20
  /**
21
- * Version of the compiled-module ABI: the statics a generated module carries
22
- * (`__partProgram`, `__compiledProperties`, `__elementMetadata`,
23
- * `__observedAttributes`, `__computedFields`) and the runtime facade binds.
24
- * Bump when the generated-module contract changes shape; generated artifacts
25
- * stamp both this and PART_PROGRAM_VERSION so consumers can tell format drift
26
- * from release drift.
27
- *
28
- * v2: platform lifecycle callback bodies are emitted inside a
29
- * boundary-capture wrapper calling the base class's `_captureError` — a
30
- * generated module now requires a runtime facade carrying that protected
31
- * method (the v1 shape emitted the bodies verbatim).
32
- */
33
- const COMPILED_MODULE_ABI_VERSION = 2;
34
- /**
35
- * Operator/literal compatibility for when-Region tests (issue #1372). Both
21
+ * Operator/literal compatibility for when-Block tests (issue #1372). Both
36
22
  * wire validators (this module and the server serializer's shared validator)
37
23
  * close the space through this one predicate:
38
24
  * - ordering operators require a finite numeric literal;
@@ -63,7 +49,7 @@ function partAnchorEndMarker(index) {
63
49
  }
64
50
  /**
65
51
  * The one `<style>` element the server serializer emits as the first DSD
66
- * template child when the class carries static styles (renderDsd
52
+ * template child when the class carries static styles (renderToString
67
53
  * parity — pages never upgrade, so their styles must ship in the payload).
68
54
  * The claim path skips exactly this marked node; a marked node on a
69
55
  * style-less class is claim drift and fails closed.
@@ -85,14 +71,14 @@ const DATA_OE_LIGHT = "data-oe-light";
85
71
  * one catchable error type with one stable code.
86
72
  */
87
73
  function fail(reason) {
88
- raiseFrameworkError("validation", ProgramErrorCode.INVALID_PROGRAM, `[compiled-program] invalid Part Program v1: ${reason}`);
74
+ raiseFrameworkError("validation", ProgramErrorCode.INVALID_PROGRAM, `[compiled-program] invalid Part Program v2: ${reason}`);
89
75
  }
90
76
  function isRecord(value) {
91
77
  return typeof value === "object" && value !== null && !Array.isArray(value);
92
78
  }
93
79
  function validateKeys(value, allowed, where) {
94
80
  const keys = new Set(allowed);
95
- for (const key of Object.keys(value)) if (!keys.has(key)) fail(`${where}.${key} is not part of Part Program v1`);
81
+ for (const key of Object.keys(value)) if (!keys.has(key)) fail(`${where}.${key} is not part of Part Program v2`);
96
82
  }
97
83
  function isIntegerArray(value) {
98
84
  return Array.isArray(value) && value.every((entry) => Number.isInteger(entry) && entry >= 0);
@@ -257,18 +243,62 @@ function validateItemValueFields(nodes, field, where) {
257
243
  if (node.k === "el") validateItemValueFields(node.children, field, `${where}[${position}].children`);
258
244
  });
259
245
  }
260
- function validatePartPath(template, path, where, elementIds) {
261
- if (!isIntegerArray(path) || path.length === 0) fail(`${where}.path must target an element`);
262
- let nodes = template;
246
+ /** Non-throwing walk of one node list: the node a fixed-Part path lands on. */
247
+ function probePath(nodes, path) {
248
+ let list = nodes;
263
249
  let node;
264
250
  for (const index of path) {
265
- node = nodes[index];
266
- if (!node) fail(`${where}.path [${path.join(",")}] is unresolved`);
267
- nodes = node.k === "el" ? node.children : [];
251
+ node = list[index];
252
+ if (!node) return void 0;
253
+ list = node.k === "el" ? node.children : [];
254
+ }
255
+ return node;
256
+ }
257
+ /**
258
+ * True when `path` resolves within some when-Block branch tree to the element
259
+ * `nodeId` names — the branch-sink attribution test. Element ids are globally
260
+ * unique across the template and every branch tree, so the id match is exact:
261
+ * the same branch-relative suffix can exist in both branches, but only the
262
+ * owning branch's element carries the sink's location node id.
263
+ */
264
+ function branchTreeOwnsPath(parts, path, nodeId) {
265
+ for (const part of parts) {
266
+ if (part.k !== "when") continue;
267
+ for (const tree of [part.on, part.off]) {
268
+ const node = probePath(tree, path);
269
+ if (node && node.k === "el" && node.id === nodeId) return node;
270
+ }
271
+ }
272
+ }
273
+ /**
274
+ * Where one fixed Part's path lives: on the main template (anchor-precedence
275
+ * rules apply) or inside a when-Block branch (branch-relative; the branch
276
+ * tree holds no anchors by construction, so precedence is structural).
277
+ * Fail-closed on every shape that resolves to neither. `nodeId` is validated
278
+ * present for sink locations by {@linkcode validateLocation} before this runs;
279
+ * the guard keeps the optional wire shape honest.
280
+ */
281
+ function validateFixedPartTarget(template, parts, path, where, nodeId, allowBranch) {
282
+ if (nodeId === void 0) fail(`${where} location node is invalid`);
283
+ if (!isIntegerArray(path) || path.length === 0) fail(`${where}.path must target an element`);
284
+ const templateNode = probePath(template, path);
285
+ if (templateNode && templateNode.k === "el" && templateNode.id === nodeId) {
286
+ validateFixedPartPath(template, path, where);
287
+ return {
288
+ site: "template",
289
+ node: templateNode
290
+ };
268
291
  }
269
- if (!node || node.k !== "el") fail(`${where}.path must target an element`);
270
- if (!elementIds.has(node.id)) fail(`${where}.path targets an unknown element`);
271
- return node.id;
292
+ if (allowBranch) {
293
+ const branchNode = branchTreeOwnsPath(parts, path, nodeId);
294
+ if (branchNode) return {
295
+ site: "branch",
296
+ node: branchNode
297
+ };
298
+ } else if (branchTreeOwnsPath(parts, path, nodeId)) fail(`${where} targets a Block-branch element; events and refs stay outside blocks`);
299
+ if (!templateNode) fail(`${where}.path [${path.join(",")}] is unresolved`);
300
+ if (templateNode.k !== "el") fail(`${where}.path must target an element`);
301
+ fail(`${where} location node does not match path`);
272
302
  }
273
303
  function validateAnchorPath(template, path, partIndex, where) {
274
304
  if (!isIntegerArray(path) || path.length === 0) fail(`${where}.path must target a template anchor`);
@@ -295,7 +325,7 @@ function validateFixedPartPath(template, path, where) {
295
325
  function hasSignal(part) {
296
326
  return part.k === "text" || part.k === "prop" || part.k === "attr" || part.k === "bool" || part.k === "class" || part.k === "style" || part.k === "html" || part.k === "when" || part.k === "each";
297
327
  }
298
- function isRegion(part) {
328
+ function isBlock(part) {
299
329
  return part.k === "when" || part.k === "each";
300
330
  }
301
331
  function validateEventAction(value, where) {
@@ -331,7 +361,7 @@ function validateEventAction(value, where) {
331
361
  fail(`${where} has unknown action kind ${value.kind}`);
332
362
  }
333
363
  /**
334
- * Validate an unknown value as a Part Program v1. The validator is intentionally
364
+ * Validate an unknown value as a Part Program v2. The validator is intentionally
335
365
  * strict: unknown instruction kinds, missing ownership records and unsafe paths
336
366
  * fail before a runtime can guess at their meaning.
337
367
  */
@@ -343,13 +373,13 @@ function validatePartProgram(raw) {
343
373
  "root",
344
374
  "template",
345
375
  "parts",
346
- "regions",
376
+ "blocks",
347
377
  "dependencies",
348
378
  "locations",
349
379
  "sourceMap",
350
380
  "metadata"
351
381
  ], "program");
352
- if (raw.version !== 1) fail("version must be 1");
382
+ if (raw.version !== 2) fail(`version must be 2 (got ${JSON.stringify(raw.version)}): regenerate the program with the current compiler; v1 artifacts are refused, never coerced`);
353
383
  if (typeof raw.tag !== "string" || !/^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(raw.tag)) fail("tag must be a custom-element tag name");
354
384
  if (!isRecord(raw.root) || raw.root.id !== "root") fail("root must be a root record");
355
385
  validateKeys(raw.root, [
@@ -368,6 +398,7 @@ function validatePartProgram(raw) {
368
398
  if (!Array.isArray(raw.parts)) fail("parts must be an array");
369
399
  const parts = raw.parts;
370
400
  const anchorPartCounts = /* @__PURE__ */ new Map();
401
+ const branchOwnedParts = /* @__PURE__ */ new Set();
371
402
  parts.forEach((part, position) => {
372
403
  if (!isRecord(part)) fail(`parts[${position}] must be an object`);
373
404
  if (part.index !== position) fail(`parts[${position}].index must equal its position`);
@@ -405,7 +436,7 @@ function validatePartProgram(raw) {
405
436
  }
406
437
  if ((part.k === "attr" || part.k === "bool") && !isAttributeName(part.name)) fail(`parts[${position}] ${part.k} name is unsafe`);
407
438
  if (part.location.kind !== "sink") fail(`parts[${position}] ${part.k} must own a sink`);
408
- if (validatePartPath(raw.template, part.path, `parts[${position}]`, elementIds) !== part.location.node) fail(`parts[${position}] location node does not match path`);
439
+ if (validateFixedPartTarget(raw.template, parts, part.path, `parts[${position}]`, part.location.node, true).site === "branch") branchOwnedParts.add(part.index);
409
440
  if (!samePath(part.location.path, part.path)) fail(`parts[${position}] location path does not match path`);
410
441
  break;
411
442
  case "class":
@@ -418,7 +449,7 @@ function validatePartProgram(raw) {
418
449
  "location"
419
450
  ], `parts[${position}]`);
420
451
  if (!isIdentifier(part.signal) || part.location.kind !== "sink") fail(`parts[${position}] ${part.k} is invalid`);
421
- if (validatePartPath(raw.template, part.path, `parts[${position}]`, elementIds) !== part.location.node) fail(`parts[${position}] location node does not match path`);
452
+ if (validateFixedPartTarget(raw.template, parts, part.path, `parts[${position}]`, part.location.node, true).site === "branch") branchOwnedParts.add(part.index);
422
453
  if (!samePath(part.location.path, part.path)) fail(`parts[${position}] location path does not match path`);
423
454
  break;
424
455
  case "html": {
@@ -430,15 +461,9 @@ function validatePartProgram(raw) {
430
461
  "location"
431
462
  ], `parts[${position}]`);
432
463
  if (!isIdentifier(part.signal) || part.location.kind !== "sink") fail(`parts[${position}] html is invalid`);
433
- if (validatePartPath(raw.template, part.path, `parts[${position}]`, elementIds) !== part.location.node) fail(`parts[${position}] location node does not match path`);
434
- if (!samePath(part.location.path, part.path)) fail(`parts[${position}] location path does not match path`);
435
- let htmlTarget;
436
- let htmlNodes = raw.template;
437
- for (const pathIndex of part.path) {
438
- htmlTarget = htmlNodes[pathIndex];
439
- htmlNodes = htmlTarget?.k === "el" ? htmlTarget.children : [];
440
- }
441
- if (htmlTarget?.k !== "el" || htmlTarget.children.length > 0) fail(`parts[${position}] html sink target must be a childless element`);
464
+ const htmlTarget = validateFixedPartTarget(raw.template, parts, part.path, `parts[${position}]`, part.location.node, true);
465
+ if (htmlTarget.site === "branch") branchOwnedParts.add(part.index);
466
+ if (htmlTarget.node.children.length > 0) fail(`parts[${position}] html sink target must be a childless element`);
442
467
  break;
443
468
  }
444
469
  case "ref":
@@ -450,7 +475,7 @@ function validatePartProgram(raw) {
450
475
  "location"
451
476
  ], `parts[${position}]`);
452
477
  if (!isIdentifier(part.ref) || part.location.kind !== "sink") fail(`parts[${position}] ref is invalid`);
453
- if (validatePartPath(raw.template, part.path, `parts[${position}]`, elementIds) !== part.location.node) fail(`parts[${position}] location node does not match path`);
478
+ validateFixedPartTarget(raw.template, parts, part.path, `parts[${position}]`, part.location.node, false);
454
479
  if (!samePath(part.location.path, part.path)) fail(`parts[${position}] location path does not match path`);
455
480
  break;
456
481
  case "event":
@@ -467,7 +492,7 @@ function validatePartProgram(raw) {
467
492
  if (!/^[a-z][a-z0-9:-]*$/.test(part.event)) fail(`parts[${position}] event name is unsafe`);
468
493
  validateEventAction(part.action, `parts[${position}].action`);
469
494
  if (part.location.kind !== "sink") fail(`parts[${position}] event must own a sink`);
470
- if (validatePartPath(raw.template, part.path, `parts[${position}]`, elementIds) !== part.location.node) fail(`parts[${position}] event location node does not match path`);
495
+ validateFixedPartTarget(raw.template, parts, part.path, `parts[${position}]`, part.location.node, false);
471
496
  if (!samePath(part.location.path, part.path)) fail(`parts[${position}] location path does not match path`);
472
497
  break;
473
498
  case "when":
@@ -484,8 +509,8 @@ function validatePartProgram(raw) {
484
509
  if (part.location.kind !== "anchor") fail(`parts[${position}] when must own an anchor`);
485
510
  validateCondition(part.test, `parts[${position}].test`);
486
511
  if (part.test.signal !== part.signal) fail(`parts[${position}] test signal mismatch`);
487
- validateTreeNodes(part.on, `parts[${position}].on`, false, false, elementIds, /* @__PURE__ */ new Map(), elementLocations, [], []);
488
- validateTreeNodes(part.off, `parts[${position}].off`, false, false, elementIds, /* @__PURE__ */ new Map(), elementLocations, [], []);
512
+ validateTreeNodes(part.on, `parts[${position}].on`, false, false, elementIds, /* @__PURE__ */ new Map(), elementLocations, [], [0]);
513
+ validateTreeNodes(part.off, `parts[${position}].off`, false, false, elementIds, /* @__PURE__ */ new Map(), elementLocations, [], [0]);
489
514
  validateAnchorPath(raw.template, part.location.path, position, `parts[${position}]`);
490
515
  anchorPartCounts.set(position, (anchorPartCounts.get(position) ?? 0) + 1);
491
516
  break;
@@ -528,36 +553,37 @@ function validatePartProgram(raw) {
528
553
  });
529
554
  for (const part of parts) {
530
555
  if (part.k === "text" || part.k === "when" || part.k === "each") continue;
556
+ if (branchOwnedParts.has(part.index)) continue;
531
557
  validateFixedPartPath(raw.template, part.path, `parts[${part.index}]`);
532
558
  }
533
559
  for (const [index, id] of anchorIds) {
534
560
  const part = parts[index];
535
- if (!part || !isRegion(part) && part.k !== "text") fail(`anchor ${id} must reference a text or Region part`);
561
+ if (!part || !isBlock(part) && part.k !== "text") fail(`anchor ${id} must reference a text or Block part`);
536
562
  if ((anchorPartCounts.get(index) ?? 0) !== 1) fail(`part ${index} must have exactly one anchor`);
537
563
  }
538
- for (const part of parts) if (isRegion(part) || part.k === "text") {
564
+ for (const part of parts) if (isBlock(part) || part.k === "text") {
539
565
  if (!anchorIds.has(part.index)) fail(`part ${part.index} is missing its template anchor`);
540
566
  } else if (anchorIds.has(part.index)) fail(`fixed part ${part.index} may not have a template anchor`);
541
- if (!Array.isArray(raw.regions)) fail("regions must be an array");
542
- const regions = raw.regions;
543
- const regionParts = parts.filter(isRegion);
544
- if (regions.length !== regionParts.length) fail("regions must describe every Region part exactly once");
545
- regions.forEach((region, position) => {
546
- if (isRecord(region)) validateKeys(region, [
567
+ if (!Array.isArray(raw.blocks)) fail("blocks must be an array");
568
+ const blocks = raw.blocks;
569
+ const blockParts = parts.filter(isBlock);
570
+ if (blocks.length !== blockParts.length) fail("blocks must describe every Block part exactly once");
571
+ blocks.forEach((block, position) => {
572
+ if (isRecord(block)) validateKeys(block, [
547
573
  "id",
548
574
  "index",
549
575
  "kind",
550
576
  "anchor",
551
577
  "end",
552
578
  "source"
553
- ], `regions[${position}]`);
554
- if (!isRecord(region) || region.id !== `r${region.index}` || region.index !== regionParts[position].index || region.kind !== "when" && region.kind !== "each" || region.anchor !== `p${region.index}` || region.end !== `p${region.index}:end` || region.source !== `p${region.index}`) fail(`regions[${position}] has an invalid Region record`);
555
- if (region.kind !== regionParts[position].k) fail(`regions[${position}] kind mismatches its part`);
579
+ ], `blocks[${position}]`);
580
+ if (!isRecord(block) || block.id !== `r${block.index}` || block.index !== blockParts[position].index || block.kind !== "when" && block.kind !== "each" || block.anchor !== `p${block.index}` || block.end !== `p${block.index}:end` || block.source !== `p${block.index}`) fail(`blocks[${position}] has an invalid Block record`);
581
+ if (block.kind !== blockParts[position].k) fail(`blocks[${position}] kind mismatches its part`);
556
582
  });
557
583
  if (!Array.isArray(raw.dependencies)) fail("dependencies must be an array");
558
584
  const dependencies = raw.dependencies;
559
585
  const dependencyOwners = /* @__PURE__ */ new Set();
560
- const expectedDependencyOwners = new Set(parts.filter(hasSignal).map((part) => `${isRegion(part) ? "region" : "part"}:${part.index}`));
586
+ const expectedDependencyOwners = new Set(parts.filter(hasSignal).map((part) => `${isBlock(part) ? "region" : "part"}:${part.index}`));
561
587
  for (const [position, dependency] of dependencies.entries()) {
562
588
  if (!isRecord(dependency) || !isIdentifier(dependency.signal) || !isRecord(dependency.owner)) fail(`dependencies[${position}] is invalid`);
563
589
  validateKeys(dependency, [
@@ -569,7 +595,7 @@ function validatePartProgram(raw) {
569
595
  if (dependency.owner.kind !== "part" && dependency.owner.kind !== "region") fail(`dependencies[${position}].owner.kind is invalid`);
570
596
  if (!Number.isInteger(dependency.owner.index) || dependency.owner.index < 0) fail(`dependencies[${position}].owner.index is invalid`);
571
597
  const owner = parts[dependency.owner.index];
572
- if (!owner || !hasSignal(owner) || (isRegion(owner) ? "region" : "part") !== dependency.owner.kind) fail(`dependencies[${position}] points at a non-signal owner`);
598
+ if (!owner || !hasSignal(owner) || (isBlock(owner) ? "region" : "part") !== dependency.owner.kind) fail(`dependencies[${position}] points at a non-signal owner`);
573
599
  if (owner.signal !== dependency.signal || dependency.location !== owner.location.id) fail(`dependencies[${position}] does not match its owning instruction`);
574
600
  const ownerKey = `${dependency.owner.kind}:${dependency.owner.index}`;
575
601
  if (dependencyOwners.has(ownerKey)) fail(`dependencies duplicate ${ownerKey}`);
@@ -612,10 +638,10 @@ function validatePartProgram(raw) {
612
638
  if (!element || location.tag !== element.tag || !samePath(location.path, element.path)) fail(`locations[${position}] element is invalid`);
613
639
  } else if (location.kind === "anchor") {
614
640
  const part = Number.isInteger(location.part) ? parts[location.part] : void 0;
615
- if (!part || !isRegion(part) && part.k !== "text" || location.id !== `p${location.part}` || !samePath(location.path, part.location.path)) fail(`locations[${position}] anchor is invalid`);
641
+ if (!part || !isBlock(part) && part.k !== "text" || location.id !== `p${location.part}` || !samePath(location.path, part.location.path)) fail(`locations[${position}] anchor is invalid`);
616
642
  } else if (location.kind === "sink") {
617
643
  const part = Number.isInteger(location.part) ? parts[location.part] : void 0;
618
- if (!part || isRegion(part) || part.k === "text" || location.id !== `p${location.part}` || !elementIds.has(location.node) || !samePath(location.path, part.location.path) || part.location.node !== location.node) fail(`locations[${position}] sink is invalid`);
644
+ if (!part || isBlock(part) || part.k === "text" || location.id !== `p${location.part}` || !elementIds.has(location.node) || !samePath(location.path, part.location.path) || part.location.node !== location.node) fail(`locations[${position}] sink is invalid`);
619
645
  } else fail(`locations[${position}] has an unknown kind`);
620
646
  }
621
647
  for (const elementId of elementIds) if (!locationIds.has(elementId)) fail(`missing location for ${elementId}`);
@@ -754,10 +780,10 @@ function validatePartProgram(raw) {
754
780
  "root",
755
781
  ...metadataProperties.map((property) => `property:${property.name}`),
756
782
  ...locations.map((location) => location.id),
757
- ...regions.map((region) => region.id)
783
+ ...blocks.map((block) => block.id)
758
784
  ]);
759
785
  for (const sourceId of expectedSourceIds) if (!sourceIds.has(sourceId)) fail(`sourceMap is missing record ${sourceId}`);
760
786
  }
761
787
  }
762
788
  //#endregion
763
- export { COMPILED_MODULE_ABI_VERSION, DATA_OE_LIGHT, PART_PROGRAM_VERSION, STATIC_STYLES_MARKER, VOID_TAGS, conditionLiteralAllowed, isAttributeName, partAnchorEndMarker, partAnchorMarker, validatePartProgram };
789
+ export { DATA_OE_LIGHT, PART_PROGRAM_VERSION, STATIC_STYLES_MARKER, VOID_TAGS, conditionLiteralAllowed, isAttributeName, partAnchorEndMarker, partAnchorMarker, validatePartProgram };
package/src/policy.d.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
  export declare const STREAM_MAX_FIELDS = 32;
25
25
  /**
26
- * Part/Region owners one stream route's manifest may address in total across
26
+ * Part/Block owners one stream route's manifest may address in total across
27
27
  * all deferred fields.
28
28
  */
29
29
  export declare const STREAM_MAX_OWNERS = 64;
@@ -41,7 +41,7 @@ export declare const STREAM_MAX_SEED_PROPERTIES = 64;
41
41
  */
42
42
  export declare const STREAM_MAX_PAYLOAD_LENGTH: number;
43
43
  /**
44
- * Nested element expansion depth bound for `renderDsd`: cyclic component
44
+ * Nested element expansion depth bound for `renderToString`: cyclic component
45
45
  * composition fails closed instead of recursing without end.
46
46
  */
47
47
  export declare const MAX_COMPOSITION_DEPTH = 8;
package/src/policy.js CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
  const STREAM_MAX_FIELDS = 32;
25
25
  /**
26
- * Part/Region owners one stream route's manifest may address in total across
26
+ * Part/Block owners one stream route's manifest may address in total across
27
27
  * all deferred fields.
28
28
  */
29
29
  const STREAM_MAX_OWNERS = 64;
@@ -41,7 +41,7 @@ const STREAM_MAX_SEED_PROPERTIES = 64;
41
41
  */
42
42
  const STREAM_MAX_PAYLOAD_LENGTH = 262144;
43
43
  /**
44
- * Nested element expansion depth bound for `renderDsd`: cyclic component
44
+ * Nested element expansion depth bound for `renderToString`: cyclic component
45
45
  * composition fails closed instead of recursing without end.
46
46
  */
47
47
  const MAX_COMPOSITION_DEPTH = 8;
@@ -33,7 +33,20 @@ export declare const ENTRY_REGISTRATION_OWNERS = "__openEntryDefined";
33
33
  * registry outlives vite dev SSR module re-evaluations, so without this the
34
34
  * second evaluation would capture the already-wrapped `define` as its
35
35
  * "original" and every forced re-registration would silently early-return
36
- * through the previous wrapper (#1339 lit dev feedback).
36
+ * through the previous wrapper (#952 dev re-evaluation).
37
37
  */
38
38
  export declare const SSR_REGISTRY_ORIGINAL_DEFINE = "__openElementOrigDefine";
39
+ /**
40
+ * Property on the SSR registry holding the generated-entry host pairing table
41
+ * (tag -> the compiler-emitted generated host renderer): written atomically by
42
+ * the registry guard together with the class registration (M11) and read by
43
+ * `@openelement/element`'s server serializer nested-composition seam.
44
+ *
45
+ * It lives on the registry (not on the class and not on the module namespace)
46
+ * for the same reasons the ownership markers do: one writer (the generated
47
+ * entry's guard), one reader (Element's serializer), no class static / suffix
48
+ * scan / runtime module-shape read, and the pairing survives vite dev SSR
49
+ * module re-evaluations together with the class it belongs to.
50
+ */
51
+ export declare const SSR_REGISTRY_GENERATED_HOSTS = "__openElementGeneratedHosts";
39
52
  //#endregion
@@ -33,8 +33,21 @@ const ENTRY_REGISTRATION_OWNERS = "__openEntryDefined";
33
33
  * registry outlives vite dev SSR module re-evaluations, so without this the
34
34
  * second evaluation would capture the already-wrapped `define` as its
35
35
  * "original" and every forced re-registration would silently early-return
36
- * through the previous wrapper (#1339 lit dev feedback).
36
+ * through the previous wrapper (#952 dev re-evaluation).
37
37
  */
38
38
  const SSR_REGISTRY_ORIGINAL_DEFINE = "__openElementOrigDefine";
39
+ /**
40
+ * Property on the SSR registry holding the generated-entry host pairing table
41
+ * (tag -> the compiler-emitted generated host renderer): written atomically by
42
+ * the registry guard together with the class registration (M11) and read by
43
+ * `@openelement/element`'s server serializer nested-composition seam.
44
+ *
45
+ * It lives on the registry (not on the class and not on the module namespace)
46
+ * for the same reasons the ownership markers do: one writer (the generated
47
+ * entry's guard), one reader (Element's serializer), no class static / suffix
48
+ * scan / runtime module-shape read, and the pairing survives vite dev SSR
49
+ * module re-evaluations together with the class it belongs to.
50
+ */
51
+ const SSR_REGISTRY_GENERATED_HOSTS = "__openElementGeneratedHosts";
39
52
  //#endregion
40
- export { ENTRY_REGISTRATION_OWNERS, SSR_REGISTRY_ORIGINAL_DEFINE, SSR_REGISTRY_STUB_MARKER };
53
+ export { ENTRY_REGISTRATION_OWNERS, SSR_REGISTRY_GENERATED_HOSTS, SSR_REGISTRY_ORIGINAL_DEFINE, SSR_REGISTRY_STUB_MARKER };
package/src/render.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ComponentLayer, HydrationStrategy } from "./framework.js";
2
+ import { ErrorPhase } from "./errors.js";
2
3
  //#region src/render.d.ts
3
4
  /** One render failure record the SSR pipeline reports. */
4
5
  export interface RenderError {
5
6
  code: string;
6
7
  severity: 'error' | 'warning';
7
- phase: string;
8
+ phase: ErrorPhase;
8
9
  tagName: string;
9
10
  message: string;
10
11
  recoverable: boolean;
@@ -15,27 +16,6 @@ export interface HydrationHint {
15
16
  layer: ComponentLayer;
16
17
  hydrate?: HydrationStrategy;
17
18
  }
18
- /**
19
- * The public result of one `renderDsd()` call: the serialized DSD `html`, the
20
- * render errors collected while composing it (empty on success), the render
21
- * metrics for the root component, and the hydration hints the client
22
- * scheduler reads to upgrade islands.
23
- */
24
- export interface RenderOutput {
25
- html: string;
26
- errors: RenderError[];
27
- metrics: DsdRenderMetrics;
28
- hydrationHints: HydrationHint[];
29
- }
30
- /** Per-render declarative-shadow-dom metrics the server records. */
31
- export interface DsdRenderMetrics {
32
- tagName: string;
33
- renderTimeMs: number;
34
- templateSize: number;
35
- layer: ComponentLayer;
36
- hasError: boolean;
37
- nestingDepth: number;
38
- }
39
19
  /**
40
20
  * The build's admission verdict for one discovered tag: where the declaration
41
21
  * lives (`modulePath`), how it was discovered (`source`), which render path it
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1 @@
1
+ export {};
package/src/ssg.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CompatibilityClassification, FrameworkOptions, HydrationStrategy } from "./framework.js";
2
2
  import { RenderError, SsrAdmissionDecision } from "./render.js";
3
- import { PartProgramV1 } from "./part-program.js";
3
+ import { PartProgramV2 } from "./part-program.js";
4
4
  //#region src/ssg.d.ts
5
5
  /** Build-only route projection bound to a specific compiled page program. */
6
6
  export interface StreamRouteManifest {
@@ -16,7 +16,7 @@ export interface StreamRouteManifest {
16
16
  kind: 'part' | 'region';
17
17
  index: number;
18
18
  location: string;
19
- source: PartProgramV1['sourceMap']['records'][number]['source'];
19
+ source: PartProgramV2['sourceMap']['records'][number]['source'];
20
20
  }>;
21
21
  }>;
22
22
  }
@@ -39,7 +39,7 @@ export interface SsgRenderOptions {
39
39
  nonce?: boolean;
40
40
  };
41
41
  };
42
- upgradeStrategy?: string;
42
+ upgradeStrategy?: HydrationStrategy;
43
43
  viewTransition?: boolean;
44
44
  speculation?: boolean | Record<string, unknown>;
45
45
  islandTagNames?: string[];
@@ -81,11 +81,22 @@ export interface SsgRenderSummary {
81
81
  */
82
82
  warnings: string[];
83
83
  }
84
- /** Client island entry shape passed to entry generator. */
85
- export interface ClientIslandEntry {
84
+ /**
85
+ * Shared island module identity (CL-3 convergence: one base, three shapes). Every island record names the same module the same way — the tag
86
+ * it registers as, the module path that owns it, and whether that module is
87
+ * a package (CEM-derived named export) rather than a local file (default
88
+ * export) — so a rename of the identity touches one declaration, not three.
89
+ * The delivery-strategy fields intentionally stay per-shape (`strategy` on
90
+ * the client entry vs `hydrate` on the build decls): they are different
91
+ * stages' vocabularies, not one field spelled two ways.
92
+ */
93
+ export interface IslandModuleIdentity {
86
94
  tagName: string;
87
95
  modulePath: string;
88
96
  isPackage?: boolean;
97
+ }
98
+ /** Client island entry shape passed to entry generator. */
99
+ export interface ClientIslandEntry extends IslandModuleIdentity {
89
100
  /**
90
101
  * Optional named export to register as the custom element constructor.
91
102
  * When set (package islands whose chunk dropped `export default` per #638),
@@ -155,12 +166,18 @@ export interface PageRouteDecl {
155
166
  isDynamic?: boolean;
156
167
  paramNames?: string[];
157
168
  streamManifest?: StreamRouteManifest;
169
+ /**
170
+ * The server function page fact (alpha15 server lane): the exported server
171
+ * function component the route's `export default definePage(Component)`
172
+ * named — compiled into the module by the server component lane. No element
173
+ * class exists to register; both render channels render through the
174
+ * descriptor's render function (the compiled constructor) and feed the same
175
+ * renderer/layout/document wraps.
176
+ */
177
+ functionPage?: string;
158
178
  }
159
179
  /** One island the build admits: tag, module path, and delivery facts. */
160
- export interface IslandDecl {
161
- tagName: string;
162
- modulePath: string;
163
- isPackage?: boolean;
180
+ export interface IslandDecl extends IslandModuleIdentity {
164
181
  /**
165
182
  * Optional named export to register as the custom element constructor.
166
183
  * Set for package islands from the manifest declaration's `className`
@@ -186,6 +203,34 @@ export interface StaticComponentDecl {
186
203
  modulePath: string;
187
204
  /** Compiler-owned interaction events; empty means no inferred browser entry. */
188
205
  compilerInteractionEvents: string[];
206
+ /**
207
+ * The compiler-emitted SSR host producer export (`<Name>__ssrHost`) when this
208
+ * static component belongs to the GENERATED lane, or absent for a class.
209
+ *
210
+ * Same fact, same rule as {@linkcode LayoutDecl.generatedHostExport}: a
211
+ * generated component carries no Part Program, so a class-only registration
212
+ * fails every render with PROGRAM_MISSING. The entry therefore registers the
213
+ * generated host PAIR. The name is the compiler's return value, never a
214
+ * `${X}__ssrHost` convention (ADR-0182 forbids re-deriving it).
215
+ */
216
+ generatedHostExport?: string;
217
+ /**
218
+ * The descriptor root a page-local GENERATED component declares (P-2,
219
+ * 2026-11-21). A shadow root's class candidates need the shared COMPONENT
220
+ * stylesheet linked inside the DSD template; a light root's belong to the
221
+ * document sheet. Absent for a class component (its `static styles` scope
222
+ * carries the same fact).
223
+ */
224
+ root?: 'light' | 'shadow' | 'closed';
225
+ /**
226
+ * True when this record is a PAGE COMPONENT (the module a route passes to
227
+ * `definePage`), not a nested component. A page root is rendered by the route
228
+ * handler, so the entry must register its host pair even though no JSX
229
+ * reference to the tag exists anywhere.
230
+ */
231
+ pageComponent?: boolean;
232
+ /** A generated host reached through a page component’s side-effect imports. */
233
+ pageComponentDependency?: boolean;
189
234
  }
190
235
  /** The build-time SSR admission decisions per component tag. */
191
236
  export interface SsrAdmissionPlan {
@@ -224,29 +269,39 @@ export interface DocumentConfig {
224
269
  headExtras: string;
225
270
  allowHeadExtrasScripts: boolean;
226
271
  }
227
- /** The app shell module a build resolves: tag, import path, and serialized props. */
228
- export interface AppShellDecl {
272
+ /** The layout module a build resolves: tag, import path, and serialized props. */
273
+ export interface LayoutDecl {
229
274
  tagName: string;
230
275
  importPath: string;
231
276
  props: Record<string, unknown>;
277
+ /**
278
+ * The compiler-emitted SSR host producer export (`<Name>__ssrHost`) when the
279
+ * layout module is a GENERATED element, or absent when it is a class.
280
+ *
281
+ * A generated layout cannot be registered class-only: a generated element
282
+ * carries no Part Program, so `renderToString` fails with PROGRAM_MISSING on
283
+ * every render. The entry therefore registers the generated host PAIR — the
284
+ * same channel an island uses. The name is the compiler's return value, never
285
+ * a `${X}__ssrHost` convention (ADR-0182 forbids re-deriving it).
286
+ */
287
+ generatedHostExport?: string;
232
288
  }
233
- /** The resolved shell for one plan slot: disabled (false) or a full declaration. */
234
- export type ResolvedAppShell = false | AppShellDecl;
235
- /** The resolved app shells a build ships: the default shell plus named layouts. */
236
- export interface AppShellPlan {
237
- default: ResolvedAppShell;
238
- layouts: Record<string, ResolvedAppShell>;
289
+ /** The resolved layout for one plan slot: disabled (false) or a full declaration. */
290
+ export type ResolvedLayout = false | LayoutDecl;
291
+ /** The resolved layouts a build ships: the default layout plus named layouts. */
292
+ export interface LayoutPlan {
293
+ default: ResolvedLayout;
294
+ layouts: Record<string, ResolvedLayout>;
239
295
  }
240
- /** The full build-time description of one generated entry: routes, islands, renderers, middleware, document, and app-shell plans. */
296
+ /** The full build-time description of one generated entry: routes, islands, renderers, middleware, document, and layout plans. */
241
297
  export interface EntryDescriptor {
242
298
  isSSG: boolean;
243
299
  /**
244
- * Page renderer selection (#1339). Absent/'native' keeps the
245
- * compiled renderDsd page path byte-identical; 'lit' forks page tag
246
- * resolution, page SSR and the client entry onto @lit-labs/ssr.
247
- * Loader/action/protocol codegen never forks.
300
+ * Page renderer selection. Only the compiled native renderer exists; absent
301
+ * or 'native' keeps the renderToString page path byte-identical. Loader,
302
+ * action and protocol codegen never fork on a renderer.
248
303
  */
249
- renderer?: 'native' | 'lit';
304
+ renderer?: 'native';
250
305
  imports: ImportDecl[];
251
306
  middleware: MiddlewareDecl[];
252
307
  /**
@@ -273,7 +328,7 @@ export interface EntryDescriptor {
273
328
  renderers: RendererDecl[];
274
329
  middlewareScopes: MiddlewareScopeDecl[];
275
330
  document: DocumentConfig;
276
- appShell: AppShellPlan;
331
+ layout: LayoutPlan;
277
332
  upgradeStrategy?: HydrationStrategy;
278
333
  /**
279
334
  * Declared project locales. Absent for a single-locale site: the generated
@@ -329,7 +384,7 @@ export interface RouteInfoEntry {
329
384
  isDynamic: boolean;
330
385
  paramNames: string[];
331
386
  /** Rendering mode declared via renderIntent.mode ("static" when unset; the "auto" alias is rejected, #609). */
332
- rendering?: string;
387
+ rendering?: 'static' | 'dynamic';
333
388
  /** True when the route module exports an action (request-time form POST). */
334
389
  hasAction?: boolean;
335
390
  streamManifest?: StreamRouteManifest;
@@ -408,10 +463,7 @@ export interface BuildRouteInput {
408
463
  staticParams?: Array<Record<string, string>>;
409
464
  }
410
465
  /** A single island input to the build pipeline. */
411
- export interface BuildIslandInput {
412
- tagName: string;
413
- modulePath: string;
414
- isPackage?: boolean;
466
+ export interface BuildIslandInput extends IslandModuleIdentity {
415
467
  hydrate?: IslandDeliveryStrategy;
416
468
  ssr?: boolean;
417
469
  dsd?: boolean;