@pithyjs/core 0.1.0-beta.19 → 0.1.0-beta.20

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.
Files changed (65) hide show
  1. package/README.md +13 -1
  2. package/dist/compile/binds/bindAfterProjection.d.ts.map +1 -1
  3. package/dist/compile/binds/bindAfterProjection.js +2 -0
  4. package/dist/compile/binds/bindAfterProjection.js.map +1 -1
  5. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
  6. package/dist/compile/binds/bindClassDirectives.js +2 -1
  7. package/dist/compile/binds/bindClassDirectives.js.map +1 -1
  8. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  9. package/dist/compile/binds/bindComponentsTags.js +36 -21
  10. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  11. package/dist/compile/binds/bindErrorBoundary.d.ts +31 -0
  12. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  13. package/dist/compile/binds/bindErrorBoundary.js +110 -13
  14. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  15. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
  16. package/dist/compile/binds/bindTextInterpolations.js +7 -5
  17. package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
  18. package/dist/compile/compileNodes.d.ts.map +1 -1
  19. package/dist/compile/compileNodes.js +8 -4
  20. package/dist/compile/compileNodes.js.map +1 -1
  21. package/dist/compile/compileTemplate.d.ts.map +1 -1
  22. package/dist/compile/compileTemplate.js +12 -8
  23. package/dist/compile/compileTemplate.js.map +1 -1
  24. package/dist/compile/contentProjection.d.ts +2 -2
  25. package/dist/compile/contentProjection.d.ts.map +1 -1
  26. package/dist/compile/contentProjection.js +22 -8
  27. package/dist/compile/contentProjection.js.map +1 -1
  28. package/dist/compile/evalDiagnostics.d.ts +7 -0
  29. package/dist/compile/evalDiagnostics.d.ts.map +1 -0
  30. package/dist/compile/evalDiagnostics.js +8 -0
  31. package/dist/compile/evalDiagnostics.js.map +1 -0
  32. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  33. package/dist/compile/forLoops/createLoopManager.js +5 -0
  34. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  35. package/dist/compile/nodeExpando.d.ts +2 -0
  36. package/dist/compile/nodeExpando.d.ts.map +1 -1
  37. package/dist/compile/nodeExpando.js.map +1 -1
  38. package/dist/compile/renderBranch.d.ts.map +1 -1
  39. package/dist/compile/renderBranch.js +7 -2
  40. package/dist/compile/renderBranch.js.map +1 -1
  41. package/dist/compile/ssrCrashes.d.ts +64 -36
  42. package/dist/compile/ssrCrashes.d.ts.map +1 -1
  43. package/dist/compile/ssrCrashes.js +342 -37
  44. package/dist/compile/ssrCrashes.js.map +1 -1
  45. package/dist/runtime/applyBindings.d.ts.map +1 -1
  46. package/dist/runtime/applyBindings.js +13 -3
  47. package/dist/runtime/applyBindings.js.map +1 -1
  48. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  49. package/dist/runtime/bindings/applyComponent.js +19 -17
  50. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  51. package/dist/runtime/bindings/applySimple.d.ts +7 -0
  52. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  53. package/dist/runtime/bindings/applySimple.js +22 -10
  54. package/dist/runtime/bindings/applySimple.js.map +1 -1
  55. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  56. package/dist/runtime/bindings/applyStructural.js +115 -105
  57. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  58. package/dist/runtime/bindings/index.d.ts +1 -1
  59. package/dist/runtime/bindings/index.d.ts.map +1 -1
  60. package/dist/runtime/bindings/index.js +1 -1
  61. package/dist/runtime/bindings/index.js.map +1 -1
  62. package/dist/types/globals.d.ts +6 -0
  63. package/dist/types/globals.d.ts.map +1 -1
  64. package/dist/types/globals.js.map +1 -1
  65. package/package.json +2 -2
@@ -17,6 +17,8 @@ import { safeInsertBefore, markElementsAsLoopGenerated, createItemRange, wrapInR
17
17
  import { findAllNestedLoopNodes } from './loopTraversal.js';
18
18
  import { nodeExpando } from '../nodeExpando.js';
19
19
  import { orderByDocument } from '../disposeOrder.js';
20
+ import { withBranchBoundary } from '../binds/bindErrorBoundary.js';
21
+ import { withinRender } from '../ssrCrashes.js';
20
22
  /** First real element between [start..end] to use as a flash target. */
21
23
  function firstElInRange(start, end) {
22
24
  let n = start.nextSibling;
@@ -121,6 +123,9 @@ export function createLoopManager({ anchor, trackByFn, parentCtx, itemVar, index
121
123
  * - Else: compute minimal moves (LIS - Longest Increasing Subsequence), update signals, and reorder DOM ranges.
122
124
  */
123
125
  function update(collection, node) {
126
+ withinRender(() => withBranchBoundary(anchor, () => updateNow(collection, node)));
127
+ }
128
+ function updateNow(collection, node) {
124
129
  const liveParent = anchor.parentNode;
125
130
  // Flashing Policy
126
131
  const FLASH_ON_INSERT = true;
@@ -1 +1 @@
1
- {"version":3,"file":"createLoopManager.js","sourceRoot":"","sources":["../../../src/compile/forLoops/createLoopManager.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAkBF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,WAAW,EACX,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAA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AE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACX,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.directive.loop-manager\",\n \"title\": \"Advanced Loop Manager\",\n \"category\": \"directive\"\n}\n*/\n\n/**\n * createLoopManager.ts\n *\n * A keyed, range-based list renderer optimized for deep nesting and high churn.\n *\n * Highlights:\n * - Uses [start..end] comment markers to represent each item range (stable DOM, easy move/remove).\n * - Minimal-move reordering using LIS (Longest Increasing Subsequence).\n * - Rebuild fast-path for heavy churn (bulk fragment insert for big updates).\n * - Caches nested loop nodes and tags their hosts to skip parent text-binding passes.\n * - Precise (configurable) visual flashing policy for inserts/moves/updates.\n * - Dev-time duplicate key detection.\n */\n\nimport type { PithyNode } from '@pithyjs/compiler';\nimport type { ChildFactory } from '../../runtime/bindings/types';\nimport { batch, createRoot, untrack } from '@pithyjs/signals';\nimport { pithyTreeToDom } from '../pithyTreeToDom';\nimport { bindForLoops } from './bindForLoops';\nimport { flashUpdate } from '../binds/bindTextInterpolations';\nimport { bindTemplateDirectives } from '..';\nimport { bindConditionals } from '../binds/bindConditionals';\nimport { bindSwitchCases } from '../bindSwitchCases';\nimport {\n LoopSignals,\n createLoopSignals,\n updateLoopSignals,\n createLoopContext,\n} from './loopSignals';\nimport {\n safeInsertBefore,\n markElementsAsLoopGenerated,\n createItemRange,\n wrapInRange,\n detachRange,\n} from './loopHelpers';\nimport { findAllNestedLoopNodes } from './loopTraversal';\nimport { nodeExpando } from '../nodeExpando';\nimport { orderByDocument } from '../disposeOrder';\n\n// ── Module-scope helpers (hoisted to avoid re-allocation per update() call) ──\n\ntype FlashUpdatePolicy = 'none' | 'identity' | 'shallow-nested-ignored';\n\n/** First real element between [start..end] to use as a flash target. */\nfunction firstElInRange(start: Comment, end: Comment): Element | null {\n let n: ChildNode | null = start.nextSibling;\n while (n && n !== end) {\n if (n.nodeType === Node.ELEMENT_NODE) return n as Element;\n n = n.nextSibling;\n }\n return null;\n}\n\n/** Extract inclusive [start..end] into a fragment (moving the range intact). */\nfunction collectRange(start: Comment, end: Comment): DocumentFragment {\n const frag = document.createDocumentFragment();\n let n: ChildNode | null = start;\n while (n) {\n const next: ChildNode | null = n.nextSibling;\n frag.appendChild(n);\n if (n === end) break;\n n = next;\n }\n return frag;\n}\n\n/** Compare only shallow, non-object fields to decide if update flash is meaningful. */\nfunction shallowChangedIgnoringObjects(a: unknown, b: unknown): boolean {\n if (a === b) return false;\n if (typeof a !== 'object' || a == null || typeof b !== 'object' || b == null)\n return true;\n\n const ar = a as Record<string, unknown>;\n const br = b as Record<string, unknown>;\n const keys = new Set([...Object.keys(ar), ...Object.keys(br)]);\n for (const k of keys) {\n const va = ar[k];\n const vb = br[k];\n const objA = va && typeof va === 'object';\n const objB = vb && typeof vb === 'object';\n if (objA || objB) continue; // ignore nested objects/arrays (child loops will flash)\n if (va !== vb) return true;\n }\n return false;\n}\n\nfunction shouldFlashUpdate(\n policy: FlashUpdatePolicy,\n prevItem: unknown,\n nextItem: unknown\n): boolean {\n switch (policy) {\n case 'none':\n return false;\n case 'identity':\n return prevItem !== nextItem;\n case 'shallow-nested-ignored':\n return shallowChangedIgnoringObjects(prevItem, nextItem);\n }\n}\n\n/** Clone a cached template fragment and restore JS metadata properties via parallel walk. */\nfunction cloneFragmentWithContext(\n template: DocumentFragment,\n ctx: Record<string, unknown>\n): DocumentFragment {\n const clone = template.cloneNode(true) as DocumentFragment;\n restoreNodeMetadata(template, clone, ctx);\n return clone;\n}\n\n/**\n * Walk source and target trees in parallel, copying metadata from source to target.\n * `__pithyCtx` is set to the new `ctx` (not copied from source).\n */\nfunction restoreNodeMetadata(\n source: Node,\n target: Node,\n ctx: Record<string, unknown>\n): void {\n const src = nodeExpando(source);\n const tgt = nodeExpando(target);\n\n if (src.__pithyCtx !== undefined) tgt.__pithyCtx = ctx;\n if (src.__pithyNode !== undefined) tgt.__pithyNode = src.__pithyNode;\n if (src.__nodeId !== undefined) tgt.__nodeId = src.__nodeId;\n if (src.__slotName !== undefined) tgt.__slotName = src.__slotName;\n\n // Slot fallback factory captures context — recreate with new ctx\n const srcNode = src.__pithyNode;\n if (\n src.__fallbackFactory !== undefined &&\n srcNode?.fallbackChildren?.length\n ) {\n tgt.__fallbackFactory = () =>\n pithyTreeToDom(srcNode.fallbackChildren!, ctx);\n }\n\n // Walk children in parallel (cloneNode preserves child count/order)\n const srcChildren = source.childNodes;\n const tgtChildren = target.childNodes;\n for (let i = 0; i < srcChildren.length; i++) {\n restoreNodeMetadata(srcChildren[i], tgtChildren[i], ctx);\n }\n}\n\n// ── Interfaces ──\n\nexport type { ChildFactory };\n\nexport interface LoopItem {\n key: string;\n fragment: DocumentFragment | Element; // contains [start, ...content..., end]\n signals: LoopSignals;\n start: Comment;\n end: Comment;\n node?: PithyNode; // original AST node (for caching, diagnostics); absent in templateNodes path\n destroy: () => void;\n}\n\nexport interface LoopManagerOptions<T> {\n anchor: Comment; // DOM anchor comment for the whole loop block\n trackByFn: (item: T, index: number) => string; // stable key selector\n parentCtx: Record<string, unknown>; // parent template context\n itemVar: string; // loop item var name (e.g., \"item\")\n indexVar?: string; // loop index var name (e.g., \"i\")\n countVar?: string; // count signal alias (default: \"count\")\n firstVar?: string; // first signal alias (default: \"first\")\n lastVar?: string; // last signal alias (default: \"last\")\n evenVar?: string; // even signal alias (default: \"even\")\n oddVar?: string; // odd signal alias (default: \"odd\")\n templateNodes?: PithyNode[]; // pre-parsed AST children for component-driven loops (e.g. <For>)\n itemFactory?: ChildFactory;\n}\n\nexport interface LoopManager<T = unknown> {\n update: (collection: T[], node?: PithyNode) => void;\n destroyAll: () => void;\n}\n\n/** @codexApi {\"parent\":\"pithy.directive.loop-manager\",\"name\":\"createLoopManager\",\"stability\":\"stable\",\"signature\":\"<T>(options: LoopManagerOptions<T>) => LoopManager<T>\"} */\nexport function createLoopManager<T>({\n anchor,\n trackByFn,\n parentCtx,\n itemVar,\n indexVar,\n countVar,\n firstVar,\n lastVar,\n evenVar,\n oddVar,\n templateNodes,\n itemFactory,\n}: LoopManagerOptions<T>): LoopManager<T> {\n // Map of key -> LoopItem (stable across updates as long as key is stable)\n const items = new Map<string, LoopItem>();\n // Row keys in on-screen order. `items` keeps insertion order, which a\n // reorder leaves behind, and the DOM may be detached by teardown time.\n let order: string[] = [];\n let cachedNestedLoopNodes: PithyNode[] | null = null;\n let cachedTemplateFrag: DocumentFragment | null = null;\n\n /**\n * Update the loop to reflect the given collection:\n * - Diff keys (remove missing, add new).\n * - If churn is heavy: rebuild in a single batch (fast path).\n * - Else: compute minimal moves (LIS - Longest Increasing Subsequence), update signals, and reorder DOM ranges.\n */\n function update(collection: T[], node?: PithyNode): void {\n const liveParent = anchor.parentNode;\n\n // Flashing Policy\n const FLASH_ON_INSERT = true as const;\n const FLASH_ON_MOVE = false as const; // moves typically aren't \"re-renders\"\n const FLASH_ON_UPDATE: FlashUpdatePolicy = 'shallow-nested-ignored';\n\n // NOTE: We intentionally do NOT wrap the entire update() in batch().\n // createLoopItem builds DOM via pithyTreeToDom which creates reactive\n // effects. If those effects are deferred by an outer batch, the flush\n // can re-trigger the parent effect (in For.ts) causing infinite recursion.\n // Per-item batch() around signal updates is safe and sufficient.\n\n // Key Diff\n const newKeys = collection.map((it, idx) => trackByFn(it, idx));\n const newKeySet = new Set(newKeys);\n\n // Dev-time guard for duplicate keys (can corrupt the map & DOM)\n if (import.meta.env?.DEV) {\n const seen = new Set<string>();\n for (const k of newKeys) {\n if (seen.has(k)) {\n console.warn('[loop] duplicate key detected:', k, {\n node,\n collection,\n });\n }\n seen.add(k);\n }\n }\n\n if (!liveParent) {\n for (const [key, loopItem] of items) {\n if (!newKeySet.has(key)) {\n loopItem.destroy();\n items.delete(key);\n }\n }\n collection.forEach((item, idx) => {\n const existing = items.get(newKeys[idx]);\n if (existing) syncSignals(existing, item, idx, collection.length);\n });\n order = order.filter(k => items.has(k));\n return;\n }\n\n // Remove items that no longer exist\n let removedCount = 0;\n items.forEach((loopItem, key) => {\n if (!newKeySet.has(key)) {\n loopItem.destroy(); // unsubscribes + removes its DOM range\n items.delete(key);\n removedCount++;\n }\n });\n\n // Count additions\n const addedCount = newKeys.reduce(\n (acc, k) => acc + (items.has(k) ? 0 : 1),\n 0\n );\n\n // Churn heuristic (how much of the list changed)\n const n = newKeys.length;\n const churn = (addedCount + removedCount) / Math.max(1, n);\n\n // Rebuild Fast-Path\n // For very heavy churn, a single rebuild is often faster than many moves.\n const REBUILD_THRESHOLD = 0.5;\n if (churn > REBUILD_THRESHOLD) {\n const batchFrag = document.createDocumentFragment();\n\n for (let idx = 0; idx < collection.length; idx++) {\n const key = newKeys[idx];\n const item = collection[idx];\n const existing = items.get(key);\n\n if (existing) {\n // Update item + positional signals in a single batch to avoid double effect firing\n const prev = syncSignals(existing, item, idx, collection.length);\n if (prev !== item && shouldFlashUpdate(FLASH_ON_UPDATE, prev, item)) {\n const el = firstElInRange(existing.start, existing.end);\n if (el) flashUpdate(el);\n }\n // Move entire range into the batchFrag fragment\n batchFrag.appendChild(collectRange(existing.start, existing.end));\n } else {\n // Create new item\n if (!node && !templateNodes && !itemFactory) continue;\n const created = createLoopItem(\n node,\n item,\n idx,\n collection.length,\n key\n );\n items.set(key, created);\n batchFrag.appendChild(created.fragment);\n if (FLASH_ON_INSERT) {\n const el = firstElInRange(created.start, created.end);\n if (el) flashUpdate(el);\n }\n }\n }\n\n // Insert everything at once before the anchor\n safeInsertBefore(liveParent, batchFrag, anchor);\n order = newKeys.filter(k => items.has(k));\n return;\n }\n\n // Minimal-Move Path (LIS)\n // Goal: only move items that are out of order (items in LIS keep their place).\n\n // Current DOM order of existing items (sort by document position)\n const existingItems = Array.from(items.values());\n existingItems.sort((a, b) => {\n const pos = a.start.compareDocumentPosition(b.start);\n // if a follows b, put b first (i.e., a after b => return 1)\n if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n return 1;\n });\n const oldOrder = existingItems.map(i => i.key);\n\n // Map key -> new position\n const newPos = new Map<string, number>();\n newKeys.forEach((k, i) => newPos.set(k, i));\n\n // Sequence of positions for old items that still exist\n const seq: number[] = [];\n const seqKeys: string[] = [];\n for (const k of oldOrder) {\n const p = newPos.get(k);\n if (p != null) {\n seq.push(p);\n seqKeys.push(k);\n }\n }\n\n // Compute LIS over positions and mark keys to keep (no move)\n const lisIdxs = lis(seq); // indices into seq[]\n const keep = new Set(lisIdxs.map(i => seqKeys[i]));\n\n // Reorder by iterating the new order backwards and inserting before a moving cursor\n let cursor: ChildNode = anchor;\n\n for (let idx = collection.length - 1; idx >= 0; idx--) {\n const item = collection[idx];\n const key = newKeys[idx];\n const existing = items.get(key);\n\n if (existing) {\n // Update item + positional signals in a single batch to avoid double effect firing\n const prev = syncSignals(existing, item, idx, collection.length);\n if (prev !== item && shouldFlashUpdate(FLASH_ON_UPDATE, prev, item)) {\n const el = firstElInRange(existing.start, existing.end);\n if (el) flashUpdate(el);\n }\n\n if (keep.has(key)) {\n // Already in good relative position, don't move; just advance cursor\n cursor = existing.start;\n } else {\n // Move the entire range right before the cursor\n const rangeFrag = collectRange(existing.start, existing.end);\n safeInsertBefore(liveParent, rangeFrag, cursor);\n if (FLASH_ON_MOVE) {\n const el = firstElInRange(existing.start, existing.end);\n if (el) flashUpdate(el);\n }\n cursor = existing.start;\n }\n } else {\n // New item: create and insert before cursor\n if (!node && !templateNodes && !itemFactory) continue;\n const created = createLoopItem(node, item, idx, collection.length, key);\n items.set(key, created);\n safeInsertBefore(liveParent, created.fragment, cursor);\n if (FLASH_ON_INSERT) {\n const el = firstElInRange(created.start, created.end);\n if (el) flashUpdate(el);\n }\n cursor = created.start;\n }\n }\n order = newKeys.filter(k => items.has(k));\n }\n\n function syncSignals(\n existing: LoopItem,\n item: T,\n idx: number,\n total: number\n ): T {\n const prev = untrack(existing.signals.itemSig) as T;\n batch(() => {\n if (prev !== item) existing.signals.itemSig.set(item);\n updateLoopSignals(existing.signals, idx, total);\n });\n return prev;\n }\n\n /**\n * Create a new LoopItem:\n * - Build the item's DOM from the AST node and local ctx.\n * - Tag top-level elements with __pithyCtx (so events resolve nearest context).\n * - Cache & tag nested loop hosts to skip parent text-binding.\n * - Bind template directives first; then bind nested loops inside this item.\n * - Wrap the item range with [start..end] markers (for move/remove).\n */\n function createLoopItem(\n node: PithyNode | undefined,\n item: T,\n idx: number,\n total: number,\n key: string\n ): LoopItem {\n return createRoot(disposeRoot => buildLoopItem(disposeRoot));\n\n function buildLoopItem(disposeRoot: () => void): LoopItem {\n const signals = createLoopSignals(item, idx, total);\n const ctx = createLoopContext(\n parentCtx,\n signals,\n itemVar,\n indexVar,\n countVar,\n firstVar,\n lastVar,\n evenVar,\n oddVar\n );\n\n if (itemFactory) {\n const built = itemFactory(ctx);\n for (const n of Array.from(built.el.childNodes)) {\n if (n.nodeType === Node.ELEMENT_NODE) nodeExpando(n).__pithyCtx = ctx;\n }\n const { start, end } = createItemRange(key);\n const destroy = () => {\n built.destroy();\n disposeRoot();\n detachRange(start, end);\n };\n return {\n key,\n fragment: wrapInRange(start, built.el, end),\n signals,\n start,\n end,\n destroy,\n };\n }\n\n // 1) Build static DOM for this item\n let fragmentFromNode: DocumentFragment;\n\n if (!cachedTemplateFrag) {\n // First item: build template from AST once and cache it.\n // Use parentCtx so the cached template does not retain per-item signals.\n // restoreNodeMetadata replaces __pithyCtx with the real per-item ctx on each clone.\n if (templateNodes) {\n cachedTemplateFrag = pithyTreeToDom(templateNodes, parentCtx);\n } else {\n const nodeForRender = {\n ...node!,\n directives: { ...node!.directives },\n };\n delete nodeForRender.directives.for;\n cachedTemplateFrag = pithyTreeToDom([nodeForRender], parentCtx);\n markElementsAsLoopGenerated(cachedTemplateFrag, node!);\n }\n // Clone for this item (cache stays pristine)\n fragmentFromNode = cloneFragmentWithContext(cachedTemplateFrag, ctx);\n } else {\n // Subsequent items: clone cached DOM + restore metadata\n fragmentFromNode = cloneFragmentWithContext(cachedTemplateFrag, ctx);\n }\n\n // 2) Tag local context on top-level elements for nearest-ctx event resolution\n for (const n of Array.from(fragmentFromNode.childNodes)) {\n if (n.nodeType === Node.ELEMENT_NODE) nodeExpando(n).__pithyCtx = ctx;\n }\n\n // 3) Find nested loop nodes ONCE per AST source (cache on the node or in closure)\n const astChildren =\n templateNodes ?? (node?.isComponent ? [] : node!.children || []);\n const allNestedLoopNodes: PithyNode[] = templateNodes\n ? (cachedNestedLoopNodes ??= templateNodes.flatMap(tn => {\n // Include root template nodes that themselves carry @for\n // (findAllNestedLoopNodes skips the root, which is correct for\n // the directive path but misses top-level loops in templateNodes)\n const nested = findAllNestedLoopNodes(tn);\n if (tn.directives?.for) nested.unshift(tn);\n return nested;\n }))\n : ((node as PithyNode & { __nested?: PithyNode[] }).__nested ??=\n findAllNestedLoopNodes(node!));\n\n // 4) Build a data-pid => element map for this fragment and tag hosts to skip text-binding\n const pidMap = new Map<string, Element>();\n (fragmentFromNode as Element | DocumentFragment)\n .querySelectorAll?.('[data-pid]')\n .forEach(el => pidMap.set(el.getAttribute('data-pid')!, el as Element));\n\n for (const n of allNestedLoopNodes) {\n if (!n.nodeId) continue;\n const host = pidMap.get(n.nodeId);\n if (host) nodeExpando(host).__pithySkipText = true; // parent text binder must skip this subtree\n }\n\n // 5) Bind structural directives in the same order as compileTemplate\n const disposers: (() => void)[] = [];\n\n // 5a) Switch/case, then conditionals outside switch cases\n const structuralProcessedIds = bindSwitchCases(\n astChildren,\n fragmentFromNode,\n ctx,\n new Set<string>(),\n disposers\n );\n bindConditionals(\n astChildren,\n fragmentFromNode,\n ctx,\n structuralProcessedIds,\n disposers\n );\n\n // 5c) Bind nested loops (pass processedNodeIds to skip loops inside conditionals)\n const nestedLoopDisposers: (() => void)[] = [];\n bindForLoops(\n allNestedLoopNodes,\n fragmentFromNode,\n ctx,\n nestedLoopDisposers,\n structuralProcessedIds\n );\n disposers.push(...nestedLoopDisposers);\n\n // 5d) Bind template directives (text interpolations, events, etc.)\n bindTemplateDirectives(fragmentFromNode, ctx, disposers);\n orderByDocument(disposers);\n\n // 5e) Mark top-level elements to prevent parent from re-binding their text content\n for (const n of Array.from(fragmentFromNode.childNodes)) {\n if (n.nodeType === Node.ELEMENT_NODE) {\n nodeExpando(n).__pithySkipText = true;\n }\n }\n\n // 7) Wrap the whole item in [start..end] comments so we can move/remove it as a unit\n const { start, end } = createItemRange(key);\n const grouped = wrapInRange(start, fragmentFromNode, end);\n\n // 8) Cleanup function: unsubscribe effects/listeners and detach DOM range\n const destroy = () => {\n for (let i = disposers.length - 1; i >= 0; i--) disposers[i]();\n disposeRoot();\n detachRange(start, end);\n };\n\n return { key, fragment: grouped, node, signals, start, end, destroy };\n }\n }\n\n // Last row first.\n function destroyAll(): void {\n for (let i = order.length - 1; i >= 0; i--) {\n const item = items.get(order[i]);\n if (!item) continue;\n items.delete(order[i]);\n item.destroy();\n }\n items.forEach(item => item.destroy());\n items.clear();\n order = [];\n }\n\n return { update, destroyAll };\n}\n\n/**\n * O(n log n) Longest Increasing Subsequence.\n * Given an array of numbers `a`, returns the indices into `a` that form\n * a strictly increasing subsequence with maximal length.\n *\n * We use LIS on the sequence of \"new positions\" for existing items to minimize DOM moves:\n * - Items in the LIS are already in correct relative order and don't need to move.\n * - Only the remaining items are moved to their new positions.\n */\nfunction lis(a: number[]): number[] {\n const res: number[] = []; // res[k] is the index i of the smallest tail of an increasing subsequence of length k+1\n const m: number[] = []; // m[i] points to predecessor index for i in the LIS\n\n for (let i = 0; i < a.length; i++) {\n // binary search in res to find the length of the LIS that a[i] can extend\n let lo = 0,\n hi = res.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (a[res[mid]] < a[i]) lo = mid + 1;\n else hi = mid;\n }\n\n // update res and predecessor\n if (lo === res.length) res.push(i);\n else res[lo] = i;\n\n m[i] = lo ? res[lo - 1] : -1;\n }\n\n // reconstruct LIS indices from res/m\n let k = res[res.length - 1];\n const out: number[] = [];\n for (let i = res.length - 1; i >= 0; i--) {\n out[i] = k;\n k = m[k];\n }\n return out;\n}\n"]}
1
+ {"version":3,"file":"createLoopManager.js","sourceRoot":"","sources":["../../../src/compile/forLoops/createLoopManager.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAkBF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,WAAW,EACX,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAM7C,wEAAwE;AACxE,SAAS,cAAc,CAAC,KAAc,EAAE,GAAY;IAClD,IAAI,CAAC,GAAqB,KAAK,CAAC,WAAW,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,C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OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.directive.loop-manager\",\n \"title\": \"Advanced Loop Manager\",\n \"category\": \"directive\"\n}\n*/\n\n/**\n * createLoopManager.ts\n *\n * A keyed, range-based list renderer optimized for deep nesting and high churn.\n *\n * Highlights:\n * - Uses [start..end] comment markers to represent each item range (stable DOM, easy move/remove).\n * - Minimal-move reordering using LIS (Longest Increasing Subsequence).\n * - Rebuild fast-path for heavy churn (bulk fragment insert for big updates).\n * - Caches nested loop nodes and tags their hosts to skip parent text-binding passes.\n * - Precise (configurable) visual flashing policy for inserts/moves/updates.\n * - Dev-time duplicate key detection.\n */\n\nimport type { PithyNode } from '@pithyjs/compiler';\nimport type { ChildFactory } from '../../runtime/bindings/types';\nimport { batch, createRoot, untrack } from '@pithyjs/signals';\nimport { pithyTreeToDom } from '../pithyTreeToDom';\nimport { bindForLoops } from './bindForLoops';\nimport { flashUpdate } from '../binds/bindTextInterpolations';\nimport { bindTemplateDirectives } from '..';\nimport { bindConditionals } from '../binds/bindConditionals';\nimport { bindSwitchCases } from '../bindSwitchCases';\nimport {\n LoopSignals,\n createLoopSignals,\n updateLoopSignals,\n createLoopContext,\n} from './loopSignals';\nimport {\n safeInsertBefore,\n markElementsAsLoopGenerated,\n createItemRange,\n wrapInRange,\n detachRange,\n} from './loopHelpers';\nimport { findAllNestedLoopNodes } from './loopTraversal';\nimport { nodeExpando } from '../nodeExpando';\nimport { orderByDocument } from '../disposeOrder';\nimport { withBranchBoundary } from '../binds/bindErrorBoundary';\nimport { withinRender } from '../ssrCrashes';\n\n// ── Module-scope helpers (hoisted to avoid re-allocation per update() call) ──\n\ntype FlashUpdatePolicy = 'none' | 'identity' | 'shallow-nested-ignored';\n\n/** First real element between [start..end] to use as a flash target. */\nfunction firstElInRange(start: Comment, end: Comment): Element | null {\n let n: ChildNode | null = start.nextSibling;\n while (n && n !== end) {\n if (n.nodeType === Node.ELEMENT_NODE) return n as Element;\n n = n.nextSibling;\n }\n return null;\n}\n\n/** Extract inclusive [start..end] into a fragment (moving the range intact). */\nfunction collectRange(start: Comment, end: Comment): DocumentFragment {\n const frag = document.createDocumentFragment();\n let n: ChildNode | null = start;\n while (n) {\n const next: ChildNode | null = n.nextSibling;\n frag.appendChild(n);\n if (n === end) break;\n n = next;\n }\n return frag;\n}\n\n/** Compare only shallow, non-object fields to decide if update flash is meaningful. */\nfunction shallowChangedIgnoringObjects(a: unknown, b: unknown): boolean {\n if (a === b) return false;\n if (typeof a !== 'object' || a == null || typeof b !== 'object' || b == null)\n return true;\n\n const ar = a as Record<string, unknown>;\n const br = b as Record<string, unknown>;\n const keys = new Set([...Object.keys(ar), ...Object.keys(br)]);\n for (const k of keys) {\n const va = ar[k];\n const vb = br[k];\n const objA = va && typeof va === 'object';\n const objB = vb && typeof vb === 'object';\n if (objA || objB) continue; // ignore nested objects/arrays (child loops will flash)\n if (va !== vb) return true;\n }\n return false;\n}\n\nfunction shouldFlashUpdate(\n policy: FlashUpdatePolicy,\n prevItem: unknown,\n nextItem: unknown\n): boolean {\n switch (policy) {\n case 'none':\n return false;\n case 'identity':\n return prevItem !== nextItem;\n case 'shallow-nested-ignored':\n return shallowChangedIgnoringObjects(prevItem, nextItem);\n }\n}\n\n/** Clone a cached template fragment and restore JS metadata properties via parallel walk. */\nfunction cloneFragmentWithContext(\n template: DocumentFragment,\n ctx: Record<string, unknown>\n): DocumentFragment {\n const clone = template.cloneNode(true) as DocumentFragment;\n restoreNodeMetadata(template, clone, ctx);\n return clone;\n}\n\n/**\n * Walk source and target trees in parallel, copying metadata from source to target.\n * `__pithyCtx` is set to the new `ctx` (not copied from source).\n */\nfunction restoreNodeMetadata(\n source: Node,\n target: Node,\n ctx: Record<string, unknown>\n): void {\n const src = nodeExpando(source);\n const tgt = nodeExpando(target);\n\n if (src.__pithyCtx !== undefined) tgt.__pithyCtx = ctx;\n if (src.__pithyNode !== undefined) tgt.__pithyNode = src.__pithyNode;\n if (src.__nodeId !== undefined) tgt.__nodeId = src.__nodeId;\n if (src.__slotName !== undefined) tgt.__slotName = src.__slotName;\n\n // Slot fallback factory captures context — recreate with new ctx\n const srcNode = src.__pithyNode;\n if (\n src.__fallbackFactory !== undefined &&\n srcNode?.fallbackChildren?.length\n ) {\n tgt.__fallbackFactory = () =>\n pithyTreeToDom(srcNode.fallbackChildren!, ctx);\n }\n\n // Walk children in parallel (cloneNode preserves child count/order)\n const srcChildren = source.childNodes;\n const tgtChildren = target.childNodes;\n for (let i = 0; i < srcChildren.length; i++) {\n restoreNodeMetadata(srcChildren[i], tgtChildren[i], ctx);\n }\n}\n\n// ── Interfaces ──\n\nexport type { ChildFactory };\n\nexport interface LoopItem {\n key: string;\n fragment: DocumentFragment | Element; // contains [start, ...content..., end]\n signals: LoopSignals;\n start: Comment;\n end: Comment;\n node?: PithyNode; // original AST node (for caching, diagnostics); absent in templateNodes path\n destroy: () => void;\n}\n\nexport interface LoopManagerOptions<T> {\n anchor: Comment; // DOM anchor comment for the whole loop block\n trackByFn: (item: T, index: number) => string; // stable key selector\n parentCtx: Record<string, unknown>; // parent template context\n itemVar: string; // loop item var name (e.g., \"item\")\n indexVar?: string; // loop index var name (e.g., \"i\")\n countVar?: string; // count signal alias (default: \"count\")\n firstVar?: string; // first signal alias (default: \"first\")\n lastVar?: string; // last signal alias (default: \"last\")\n evenVar?: string; // even signal alias (default: \"even\")\n oddVar?: string; // odd signal alias (default: \"odd\")\n templateNodes?: PithyNode[]; // pre-parsed AST children for component-driven loops (e.g. <For>)\n itemFactory?: ChildFactory;\n}\n\nexport interface LoopManager<T = unknown> {\n update: (collection: T[], node?: PithyNode) => void;\n destroyAll: () => void;\n}\n\n/** @codexApi {\"parent\":\"pithy.directive.loop-manager\",\"name\":\"createLoopManager\",\"stability\":\"stable\",\"signature\":\"<T>(options: LoopManagerOptions<T>) => LoopManager<T>\"} */\nexport function createLoopManager<T>({\n anchor,\n trackByFn,\n parentCtx,\n itemVar,\n indexVar,\n countVar,\n firstVar,\n lastVar,\n evenVar,\n oddVar,\n templateNodes,\n itemFactory,\n}: LoopManagerOptions<T>): LoopManager<T> {\n // Map of key -> LoopItem (stable across updates as long as key is stable)\n const items = new Map<string, LoopItem>();\n // Row keys in on-screen order. `items` keeps insertion order, which a\n // reorder leaves behind, and the DOM may be detached by teardown time.\n let order: string[] = [];\n let cachedNestedLoopNodes: PithyNode[] | null = null;\n let cachedTemplateFrag: DocumentFragment | null = null;\n\n /**\n * Update the loop to reflect the given collection:\n * - Diff keys (remove missing, add new).\n * - If churn is heavy: rebuild in a single batch (fast path).\n * - Else: compute minimal moves (LIS - Longest Increasing Subsequence), update signals, and reorder DOM ranges.\n */\n function update(collection: T[], node?: PithyNode): void {\n withinRender(() =>\n withBranchBoundary(anchor, () => updateNow(collection, node))\n );\n }\n\n function updateNow(collection: T[], node?: PithyNode): void {\n const liveParent = anchor.parentNode;\n\n // Flashing Policy\n const FLASH_ON_INSERT = true as const;\n const FLASH_ON_MOVE = false as const; // moves typically aren't \"re-renders\"\n const FLASH_ON_UPDATE: FlashUpdatePolicy = 'shallow-nested-ignored';\n\n // NOTE: We intentionally do NOT wrap the entire update() in batch().\n // createLoopItem builds DOM via pithyTreeToDom which creates reactive\n // effects. If those effects are deferred by an outer batch, the flush\n // can re-trigger the parent effect (in For.ts) causing infinite recursion.\n // Per-item batch() around signal updates is safe and sufficient.\n\n // Key Diff\n const newKeys = collection.map((it, idx) => trackByFn(it, idx));\n const newKeySet = new Set(newKeys);\n\n // Dev-time guard for duplicate keys (can corrupt the map & DOM)\n if (import.meta.env?.DEV) {\n const seen = new Set<string>();\n for (const k of newKeys) {\n if (seen.has(k)) {\n console.warn('[loop] duplicate key detected:', k, {\n node,\n collection,\n });\n }\n seen.add(k);\n }\n }\n\n if (!liveParent) {\n for (const [key, loopItem] of items) {\n if (!newKeySet.has(key)) {\n loopItem.destroy();\n items.delete(key);\n }\n }\n collection.forEach((item, idx) => {\n const existing = items.get(newKeys[idx]);\n if (existing) syncSignals(existing, item, idx, collection.length);\n });\n order = order.filter(k => items.has(k));\n return;\n }\n\n // Remove items that no longer exist\n let removedCount = 0;\n items.forEach((loopItem, key) => {\n if (!newKeySet.has(key)) {\n loopItem.destroy(); // unsubscribes + removes its DOM range\n items.delete(key);\n removedCount++;\n }\n });\n\n // Count additions\n const addedCount = newKeys.reduce(\n (acc, k) => acc + (items.has(k) ? 0 : 1),\n 0\n );\n\n // Churn heuristic (how much of the list changed)\n const n = newKeys.length;\n const churn = (addedCount + removedCount) / Math.max(1, n);\n\n // Rebuild Fast-Path\n // For very heavy churn, a single rebuild is often faster than many moves.\n const REBUILD_THRESHOLD = 0.5;\n if (churn > REBUILD_THRESHOLD) {\n const batchFrag = document.createDocumentFragment();\n\n for (let idx = 0; idx < collection.length; idx++) {\n const key = newKeys[idx];\n const item = collection[idx];\n const existing = items.get(key);\n\n if (existing) {\n // Update item + positional signals in a single batch to avoid double effect firing\n const prev = syncSignals(existing, item, idx, collection.length);\n if (prev !== item && shouldFlashUpdate(FLASH_ON_UPDATE, prev, item)) {\n const el = firstElInRange(existing.start, existing.end);\n if (el) flashUpdate(el);\n }\n // Move entire range into the batchFrag fragment\n batchFrag.appendChild(collectRange(existing.start, existing.end));\n } else {\n // Create new item\n if (!node && !templateNodes && !itemFactory) continue;\n const created = createLoopItem(\n node,\n item,\n idx,\n collection.length,\n key\n );\n items.set(key, created);\n batchFrag.appendChild(created.fragment);\n if (FLASH_ON_INSERT) {\n const el = firstElInRange(created.start, created.end);\n if (el) flashUpdate(el);\n }\n }\n }\n\n // Insert everything at once before the anchor\n safeInsertBefore(liveParent, batchFrag, anchor);\n order = newKeys.filter(k => items.has(k));\n return;\n }\n\n // Minimal-Move Path (LIS)\n // Goal: only move items that are out of order (items in LIS keep their place).\n\n // Current DOM order of existing items (sort by document position)\n const existingItems = Array.from(items.values());\n existingItems.sort((a, b) => {\n const pos = a.start.compareDocumentPosition(b.start);\n // if a follows b, put b first (i.e., a after b => return 1)\n if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n return 1;\n });\n const oldOrder = existingItems.map(i => i.key);\n\n // Map key -> new position\n const newPos = new Map<string, number>();\n newKeys.forEach((k, i) => newPos.set(k, i));\n\n // Sequence of positions for old items that still exist\n const seq: number[] = [];\n const seqKeys: string[] = [];\n for (const k of oldOrder) {\n const p = newPos.get(k);\n if (p != null) {\n seq.push(p);\n seqKeys.push(k);\n }\n }\n\n // Compute LIS over positions and mark keys to keep (no move)\n const lisIdxs = lis(seq); // indices into seq[]\n const keep = new Set(lisIdxs.map(i => seqKeys[i]));\n\n // Reorder by iterating the new order backwards and inserting before a moving cursor\n let cursor: ChildNode = anchor;\n\n for (let idx = collection.length - 1; idx >= 0; idx--) {\n const item = collection[idx];\n const key = newKeys[idx];\n const existing = items.get(key);\n\n if (existing) {\n // Update item + positional signals in a single batch to avoid double effect firing\n const prev = syncSignals(existing, item, idx, collection.length);\n if (prev !== item && shouldFlashUpdate(FLASH_ON_UPDATE, prev, item)) {\n const el = firstElInRange(existing.start, existing.end);\n if (el) flashUpdate(el);\n }\n\n if (keep.has(key)) {\n // Already in good relative position, don't move; just advance cursor\n cursor = existing.start;\n } else {\n // Move the entire range right before the cursor\n const rangeFrag = collectRange(existing.start, existing.end);\n safeInsertBefore(liveParent, rangeFrag, cursor);\n if (FLASH_ON_MOVE) {\n const el = firstElInRange(existing.start, existing.end);\n if (el) flashUpdate(el);\n }\n cursor = existing.start;\n }\n } else {\n // New item: create and insert before cursor\n if (!node && !templateNodes && !itemFactory) continue;\n const created = createLoopItem(node, item, idx, collection.length, key);\n items.set(key, created);\n safeInsertBefore(liveParent, created.fragment, cursor);\n if (FLASH_ON_INSERT) {\n const el = firstElInRange(created.start, created.end);\n if (el) flashUpdate(el);\n }\n cursor = created.start;\n }\n }\n order = newKeys.filter(k => items.has(k));\n }\n\n function syncSignals(\n existing: LoopItem,\n item: T,\n idx: number,\n total: number\n ): T {\n const prev = untrack(existing.signals.itemSig) as T;\n batch(() => {\n if (prev !== item) existing.signals.itemSig.set(item);\n updateLoopSignals(existing.signals, idx, total);\n });\n return prev;\n }\n\n /**\n * Create a new LoopItem:\n * - Build the item's DOM from the AST node and local ctx.\n * - Tag top-level elements with __pithyCtx (so events resolve nearest context).\n * - Cache & tag nested loop hosts to skip parent text-binding.\n * - Bind template directives first; then bind nested loops inside this item.\n * - Wrap the item range with [start..end] markers (for move/remove).\n */\n function createLoopItem(\n node: PithyNode | undefined,\n item: T,\n idx: number,\n total: number,\n key: string\n ): LoopItem {\n return createRoot(disposeRoot => buildLoopItem(disposeRoot));\n\n function buildLoopItem(disposeRoot: () => void): LoopItem {\n const signals = createLoopSignals(item, idx, total);\n const ctx = createLoopContext(\n parentCtx,\n signals,\n itemVar,\n indexVar,\n countVar,\n firstVar,\n lastVar,\n evenVar,\n oddVar\n );\n\n if (itemFactory) {\n const built = itemFactory(ctx);\n for (const n of Array.from(built.el.childNodes)) {\n if (n.nodeType === Node.ELEMENT_NODE) nodeExpando(n).__pithyCtx = ctx;\n }\n const { start, end } = createItemRange(key);\n const destroy = () => {\n built.destroy();\n disposeRoot();\n detachRange(start, end);\n };\n return {\n key,\n fragment: wrapInRange(start, built.el, end),\n signals,\n start,\n end,\n destroy,\n };\n }\n\n // 1) Build static DOM for this item\n let fragmentFromNode: DocumentFragment;\n\n if (!cachedTemplateFrag) {\n // First item: build template from AST once and cache it.\n // Use parentCtx so the cached template does not retain per-item signals.\n // restoreNodeMetadata replaces __pithyCtx with the real per-item ctx on each clone.\n if (templateNodes) {\n cachedTemplateFrag = pithyTreeToDom(templateNodes, parentCtx);\n } else {\n const nodeForRender = {\n ...node!,\n directives: { ...node!.directives },\n };\n delete nodeForRender.directives.for;\n cachedTemplateFrag = pithyTreeToDom([nodeForRender], parentCtx);\n markElementsAsLoopGenerated(cachedTemplateFrag, node!);\n }\n // Clone for this item (cache stays pristine)\n fragmentFromNode = cloneFragmentWithContext(cachedTemplateFrag, ctx);\n } else {\n // Subsequent items: clone cached DOM + restore metadata\n fragmentFromNode = cloneFragmentWithContext(cachedTemplateFrag, ctx);\n }\n\n // 2) Tag local context on top-level elements for nearest-ctx event resolution\n for (const n of Array.from(fragmentFromNode.childNodes)) {\n if (n.nodeType === Node.ELEMENT_NODE) nodeExpando(n).__pithyCtx = ctx;\n }\n\n // 3) Find nested loop nodes ONCE per AST source (cache on the node or in closure)\n const astChildren =\n templateNodes ?? (node?.isComponent ? [] : node!.children || []);\n const allNestedLoopNodes: PithyNode[] = templateNodes\n ? (cachedNestedLoopNodes ??= templateNodes.flatMap(tn => {\n // Include root template nodes that themselves carry @for\n // (findAllNestedLoopNodes skips the root, which is correct for\n // the directive path but misses top-level loops in templateNodes)\n const nested = findAllNestedLoopNodes(tn);\n if (tn.directives?.for) nested.unshift(tn);\n return nested;\n }))\n : ((node as PithyNode & { __nested?: PithyNode[] }).__nested ??=\n findAllNestedLoopNodes(node!));\n\n // 4) Build a data-pid => element map for this fragment and tag hosts to skip text-binding\n const pidMap = new Map<string, Element>();\n (fragmentFromNode as Element | DocumentFragment)\n .querySelectorAll?.('[data-pid]')\n .forEach(el => pidMap.set(el.getAttribute('data-pid')!, el as Element));\n\n for (const n of allNestedLoopNodes) {\n if (!n.nodeId) continue;\n const host = pidMap.get(n.nodeId);\n if (host) nodeExpando(host).__pithySkipText = true; // parent text binder must skip this subtree\n }\n\n // 5) Bind structural directives in the same order as compileTemplate\n const disposers: (() => void)[] = [];\n\n // 5a) Switch/case, then conditionals outside switch cases\n const structuralProcessedIds = bindSwitchCases(\n astChildren,\n fragmentFromNode,\n ctx,\n new Set<string>(),\n disposers\n );\n bindConditionals(\n astChildren,\n fragmentFromNode,\n ctx,\n structuralProcessedIds,\n disposers\n );\n\n // 5c) Bind nested loops (pass processedNodeIds to skip loops inside conditionals)\n const nestedLoopDisposers: (() => void)[] = [];\n bindForLoops(\n allNestedLoopNodes,\n fragmentFromNode,\n ctx,\n nestedLoopDisposers,\n structuralProcessedIds\n );\n disposers.push(...nestedLoopDisposers);\n\n // 5d) Bind template directives (text interpolations, events, etc.)\n bindTemplateDirectives(fragmentFromNode, ctx, disposers);\n orderByDocument(disposers);\n\n // 5e) Mark top-level elements to prevent parent from re-binding their text content\n for (const n of Array.from(fragmentFromNode.childNodes)) {\n if (n.nodeType === Node.ELEMENT_NODE) {\n nodeExpando(n).__pithySkipText = true;\n }\n }\n\n // 7) Wrap the whole item in [start..end] comments so we can move/remove it as a unit\n const { start, end } = createItemRange(key);\n const grouped = wrapInRange(start, fragmentFromNode, end);\n\n // 8) Cleanup function: unsubscribe effects/listeners and detach DOM range\n const destroy = () => {\n for (let i = disposers.length - 1; i >= 0; i--) disposers[i]();\n disposeRoot();\n detachRange(start, end);\n };\n\n return { key, fragment: grouped, node, signals, start, end, destroy };\n }\n }\n\n // Last row first.\n function destroyAll(): void {\n for (let i = order.length - 1; i >= 0; i--) {\n const item = items.get(order[i]);\n if (!item) continue;\n items.delete(order[i]);\n item.destroy();\n }\n items.forEach(item => item.destroy());\n items.clear();\n order = [];\n }\n\n return { update, destroyAll };\n}\n\n/**\n * O(n log n) Longest Increasing Subsequence.\n * Given an array of numbers `a`, returns the indices into `a` that form\n * a strictly increasing subsequence with maximal length.\n *\n * We use LIS on the sequence of \"new positions\" for existing items to minimize DOM moves:\n * - Items in the LIS are already in correct relative order and don't need to move.\n * - Only the remaining items are moved to their new positions.\n */\nfunction lis(a: number[]): number[] {\n const res: number[] = []; // res[k] is the index i of the smallest tail of an increasing subsequence of length k+1\n const m: number[] = []; // m[i] points to predecessor index for i in the LIS\n\n for (let i = 0; i < a.length; i++) {\n // binary search in res to find the length of the LIS that a[i] can extend\n let lo = 0,\n hi = res.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (a[res[mid]] < a[i]) lo = mid + 1;\n else hi = mid;\n }\n\n // update res and predecessor\n if (lo === res.length) res.push(i);\n else res[lo] = i;\n\n m[i] = lo ? res[lo - 1] : -1;\n }\n\n // reconstruct LIS indices from res/m\n let k = res[res.length - 1];\n const out: number[] = [];\n for (let i = res.length - 1; i >= 0; i--) {\n out[i] = k;\n k = m[k];\n }\n return out;\n}\n"]}
@@ -29,6 +29,8 @@ export interface NodeExpando {
29
29
  __pithyForwardAttrs?: Set<string>;
30
30
  /** Identifies that forwarding, so two tags in one scope stay two bindings. */
31
31
  __pithyForwardId?: number;
32
+ /** The boundary element a slot rendered this node for, wherever a portal moves it. */
33
+ __pithySlotOwner?: Element;
32
34
  }
33
35
  /** Records that `ctx`'s tag forwarded `names` onto `root`. */
34
36
  export declare function markForwardTarget(root: Element, ctx: Record<string, unknown>, names: Set<string>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"nodeExpando.d.ts","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,gBAAgB,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,0EAA0E;IAC1E,yEAAyE;IACzE,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;IACxD,YAAY,CAAC,EAAE,MAAM,EAAE,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oE;AACpE,wBAAgB,eAAe,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,WAAW,CAEpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"nodeExpando.js","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAgCA,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,IAAa,EACb,GAA4B,EAC5B,KAAkB;IAElB,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,iBAAiB,GAAG,GAAG,CAAC;IAC1B,CAAC,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAC9B,CAAC,CAAC,gBAAgB,GAAG,EAAE,aAAa,CAAC;AACvC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,EAAW,EAAE,GAAW;IACtD,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,gBAAgB,IAAI,GAAG,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CAAiB,IAAO;IACjD,OAAO,IAAuB,CAAC;AACjC,CAAC","sourcesContent":["import type { PithyNode } from '@pithyjs/compiler';\n\nexport interface StyleOwners {\n strings: string[];\n props: Map<string, [value: string, priority: string]>;\n}\n\nexport interface NodeExpando {\n __pithyCtx?: Record<string, unknown>;\n __pithyNode?: PithyNode;\n __nodeId?: string;\n __slotName?: string;\n __fallbackFactory?: () => DocumentFragment;\n __nested?: boolean;\n __pithySkipText?: boolean;\n __pithyComponentDom?: boolean;\n /** A build's component placeholder: renders it through the AOT binder. */\n /** Renders a build's placeholder; returns the nodes that replaced it. */\n __pithyAotMount?: (disposers: (() => void)[]) => Node[];\n __styleProps?: string[];\n __styleOwners?: StyleOwners;\n __selectValue?: { text: string; picks: Set<string> | null };\n __classToggles?: string[];\n __forwardedDirectives?: Map<string, string>;\n /** A component root's forwarded bindings evaluate in the tag's template. */\n __pithyForwardCtx?: Record<string, unknown>;\n /** The attributes the tag that set `__pithyForwardCtx` forwarded. */\n __pithyForwardAttrs?: Set<string>;\n /** Identifies that forwarding, so two tags in one scope stay two bindings. */\n __pithyForwardId?: number;\n}\n\nlet nextForwardId = 0;\n\n/** Records that `ctx`'s tag forwarded `names` onto `root`. */\nexport function markForwardTarget(\n root: Element,\n ctx: Record<string, unknown>,\n names: Set<string>\n): void {\n const x = nodeExpando(root);\n x.__pithyForwardCtx = ctx;\n x.__pithyForwardAttrs = names;\n x.__pithyForwardId = ++nextForwardId;\n}\n\n/** Keys a forwarded event by the forwarding that put it on `el`. */\nexport function forwardEventKey(el: Element, key: string): string {\n return `${nodeExpando(el).__pithyForwardId}|${key}`;\n}\n\nexport function nodeExpando<T extends Node>(node: T): T & NodeExpando {\n return node as T & NodeExpando;\n}\n"]}
1
+ {"version":3,"file":"nodeExpando.js","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAkCA,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,IAAa,EACb,GAA4B,EAC5B,KAAkB;IAElB,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,iBAAiB,GAAG,GAAG,CAAC;IAC1B,CAAC,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAC9B,CAAC,CAAC,gBAAgB,GAAG,EAAE,aAAa,CAAC;AACvC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,EAAW,EAAE,GAAW;IACtD,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,gBAAgB,IAAI,GAAG,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CAAiB,IAAO;IACjD,OAAO,IAAuB,CAAC;AACjC,CAAC","sourcesContent":["import type { PithyNode } from '@pithyjs/compiler';\n\nexport interface StyleOwners {\n strings: string[];\n props: Map<string, [value: string, priority: string]>;\n}\n\nexport interface NodeExpando {\n __pithyCtx?: Record<string, unknown>;\n __pithyNode?: PithyNode;\n __nodeId?: string;\n __slotName?: string;\n __fallbackFactory?: () => DocumentFragment;\n __nested?: boolean;\n __pithySkipText?: boolean;\n __pithyComponentDom?: boolean;\n /** A build's component placeholder: renders it through the AOT binder. */\n /** Renders a build's placeholder; returns the nodes that replaced it. */\n __pithyAotMount?: (disposers: (() => void)[]) => Node[];\n __styleProps?: string[];\n __styleOwners?: StyleOwners;\n __selectValue?: { text: string; picks: Set<string> | null };\n __classToggles?: string[];\n __forwardedDirectives?: Map<string, string>;\n /** A component root's forwarded bindings evaluate in the tag's template. */\n __pithyForwardCtx?: Record<string, unknown>;\n /** The attributes the tag that set `__pithyForwardCtx` forwarded. */\n __pithyForwardAttrs?: Set<string>;\n /** Identifies that forwarding, so two tags in one scope stay two bindings. */\n __pithyForwardId?: number;\n /** The boundary element a slot rendered this node for, wherever a portal moves it. */\n __pithySlotOwner?: Element;\n}\n\nlet nextForwardId = 0;\n\n/** Records that `ctx`'s tag forwarded `names` onto `root`. */\nexport function markForwardTarget(\n root: Element,\n ctx: Record<string, unknown>,\n names: Set<string>\n): void {\n const x = nodeExpando(root);\n x.__pithyForwardCtx = ctx;\n x.__pithyForwardAttrs = names;\n x.__pithyForwardId = ++nextForwardId;\n}\n\n/** Keys a forwarded event by the forwarding that put it on `el`. */\nexport function forwardEventKey(el: Element, key: string): string {\n return `${nodeExpando(el).__pithyForwardId}|${key}`;\n}\n\nexport function nodeExpando<T extends Node>(node: T): T & NodeExpando {\n return node as T & NodeExpando;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"renderBranch.d.ts","sourceRoot":"","sources":["../../src/compile/renderBranch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWnD,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,SAAS,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,EAAE,IAAI,GACX,MAAM,CAqCR;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAahD"}
1
+ {"version":3,"file":"renderBranch.d.ts","sourceRoot":"","sources":["../../src/compile/renderBranch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAanD,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,SAAS,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,EAAE,IAAI,GACX,MAAM,CAER;AA+CD,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAahD"}
@@ -1,5 +1,7 @@
1
1
  import { createRoot } from '@pithyjs/signals';
2
2
  import { bindConditionals } from './binds/bindConditionals.js';
3
+ import { withBranchBoundary } from './binds/bindErrorBoundary.js';
4
+ import { withinRender } from './ssrCrashes.js';
3
5
  import { flashUpdate } from './binds/bindTextInterpolations.js';
4
6
  import { bindSwitchBlock, bindSwitchCases } from './bindSwitchCases.js';
5
7
  import { bindTemplateDirectives } from './compileTemplate.js';
@@ -12,6 +14,9 @@ import { isSSRMode } from './ssrMode.js';
12
14
  * inserts it after `anchor`.
13
15
  */
14
16
  export function renderBranch(ast, ctx, anchor) {
17
+ return withinRender(() => buildBranch(ast, ctx, anchor));
18
+ }
19
+ function buildBranch(ast, ctx, anchor) {
15
20
  const branch = { nodes: [], disposers: [] };
16
21
  const rebuilt = pithyTreeToDom([ast], ctx).firstChild;
17
22
  if (!rebuilt || !anchor.parentNode)
@@ -22,7 +27,7 @@ export function renderBranch(ast, ctx, anchor) {
22
27
  fragment.appendChild(rebuilt);
23
28
  const children = ast.isComponent ? [] : ast.children || [];
24
29
  const { disposers } = branch;
25
- createRoot(disposeRoot => {
30
+ createRoot(disposeRoot => withBranchBoundary(anchor, () => {
26
31
  disposers.push(disposeRoot);
27
32
  const processed = new Set();
28
33
  if (ast.directives?.switch !== undefined) {
@@ -35,7 +40,7 @@ export function renderBranch(ast, ctx, anchor) {
35
40
  bindForLoops(children, rebuilt, ctx, disposers, processed);
36
41
  bindTemplateDirectives(fragment, ctx, disposers);
37
42
  orderByDocument(disposers);
38
- });
43
+ }));
39
44
  branch.nodes = Array.from(fragment.childNodes);
40
45
  anchor.parentNode.insertBefore(fragment, anchor.nextSibling);
41
46
  if (!isSSRMode()) {
@@ -1 +1 @@
1
- {"version":3,"file":"renderBranch.js","sourceRoot":"","sources":["../../src/compile/renderBranch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,S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Conditionals } from './binds/bindConditionals';\nimport { flashUpdate } from './binds/bindTextInterpolations';\nimport { bindSwitchBlock, bindSwitchCases } from './bindSwitchCases';\nimport { bindTemplateDirectives } from './compileTemplate';\nimport { bindForLoops } from './forLoops/bindForLoops';\nimport { orderByDocument } from './disposeOrder';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { isSSRMode } from './ssrMode';\n\nexport interface Branch {\n nodes: Node[];\n disposers: (() => void)[];\n}\n\n/**\n * Builds the DOM for one `@if` or `@case` branch from its AST, binds it, and\n * inserts it after `anchor`.\n */\nexport function renderBranch(\n ast: PithyNode,\n ctx: Record<string, unknown>,\n anchor: Node\n): Branch {\n const branch: Branch = { nodes: [], disposers: [] };\n const rebuilt = pithyTreeToDom([ast], ctx).firstChild as Element | null;\n if (!rebuilt || !anchor.parentNode) return branch;\n\n // A component tag is replaced by what it renders while binding, so the\n // fragment, not `rebuilt`, holds the nodes to insert and later remove.\n const fragment = document.createDocumentFragment();\n fragment.appendChild(rebuilt);\n const children = ast.isComponent ? [] : ast.children || [];\n const { disposers } = branch;\n\n createRoot(disposeRoot => {\n disposers.push(disposeRoot);\n const processed = new Set<string>();\n if (ast.directives?.switch !== undefined) {\n bindSwitchBlock(ast, rebuilt, ctx, processed, disposers);\n } else {\n bindSwitchCases(children, rebuilt, ctx, processed, disposers);\n }\n bindConditionals(children, rebuilt, ctx, processed, disposers);\n bindForLoops(children, rebuilt, ctx, disposers, processed);\n bindTemplateDirectives(fragment, ctx, disposers);\n orderByDocument(disposers);\n });\n\n branch.nodes = Array.from(fragment.childNodes);\n anchor.parentNode.insertBefore(fragment, anchor.nextSibling);\n\n if (!isSSRMode()) {\n queueMicrotask(() => {\n for (const node of branch.nodes) {\n if (node.nodeType === Node.ELEMENT_NODE) flashUpdate(node as Element);\n }\n });\n }\n return branch;\n}\n\n/** Disposes a branch's effects, last registered first, then removes its nodes. */\nexport function clearBranch(branch: Branch): void {\n for (let i = branch.disposers.length - 1; i >= 0; i--) {\n try {\n branch.disposers[i]();\n } catch {\n /* ignore */\n }\n }\n branch.disposers = [];\n for (const node of branch.nodes) {\n node.parentNode?.removeChild(node);\n }\n branch.nodes = [];\n}\n"]}
1
+ {"version":3,"file":"renderBranch.js","sourceRoot":"","sources":["../../src/compile/renderBranch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAc,EACd,GAA4B,EAC5B,MAAY;IAEZ,OAAO,YAAY,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,WAAW,CAClB,GAAc,EACd,GAA4B,EAC5B,MAAY;IAEZ,MAAM,MAAM,GAAW,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACpD,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,UAA4B,CAAC;IACxE,IAAI,CAAC,OAAO,IAAI,CAAC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,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAE7D,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,cAAc,CAAC,GAAG,EAAE;YAClB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBAChC,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY;oBAAE,WAAW,CAAC,IAAe,CAAC,CAAC;YACxE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACtD,IAAI,CAAC;YACH,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;IACD,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import type { PithyNode } from '@pithyjs/compiler';\nimport { createRoot } from '@pithyjs/signals';\nimport { bindConditionals } from './binds/bindConditionals';\nimport { withBranchBoundary } from './binds/bindErrorBoundary';\nimport { withinRender } from './ssrCrashes';\nimport { flashUpdate } from './binds/bindTextInterpolations';\nimport { bindSwitchBlock, bindSwitchCases } from './bindSwitchCases';\nimport { bindTemplateDirectives } from './compileTemplate';\nimport { bindForLoops } from './forLoops/bindForLoops';\nimport { orderByDocument } from './disposeOrder';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { isSSRMode } from './ssrMode';\n\nexport interface Branch {\n nodes: Node[];\n disposers: (() => void)[];\n}\n\n/**\n * Builds the DOM for one `@if` or `@case` branch from its AST, binds it, and\n * inserts it after `anchor`.\n */\nexport function renderBranch(\n ast: PithyNode,\n ctx: Record<string, unknown>,\n anchor: Node\n): Branch {\n return withinRender(() => buildBranch(ast, ctx, anchor));\n}\n\nfunction buildBranch(\n ast: PithyNode,\n ctx: Record<string, unknown>,\n anchor: Node\n): Branch {\n const branch: Branch = { nodes: [], disposers: [] };\n const rebuilt = pithyTreeToDom([ast], ctx).firstChild as Element | null;\n if (!rebuilt || !anchor.parentNode) return branch;\n\n // A component tag is replaced by what it renders while binding, so the\n // fragment, not `rebuilt`, holds the nodes to insert and later remove.\n const fragment = document.createDocumentFragment();\n fragment.appendChild(rebuilt);\n const children = ast.isComponent ? [] : ast.children || [];\n const { disposers } = branch;\n\n createRoot(disposeRoot =>\n withBranchBoundary(anchor, () => {\n disposers.push(disposeRoot);\n const processed = new Set<string>();\n if (ast.directives?.switch !== undefined) {\n bindSwitchBlock(ast, rebuilt, ctx, processed, disposers);\n } else {\n bindSwitchCases(children, rebuilt, ctx, processed, disposers);\n }\n bindConditionals(children, rebuilt, ctx, processed, disposers);\n bindForLoops(children, rebuilt, ctx, disposers, processed);\n bindTemplateDirectives(fragment, ctx, disposers);\n orderByDocument(disposers);\n })\n );\n\n branch.nodes = Array.from(fragment.childNodes);\n anchor.parentNode.insertBefore(fragment, anchor.nextSibling);\n\n if (!isSSRMode()) {\n queueMicrotask(() => {\n for (const node of branch.nodes) {\n if (node.nodeType === Node.ELEMENT_NODE) flashUpdate(node as Element);\n }\n });\n }\n return branch;\n}\n\n/** Disposes a branch's effects, last registered first, then removes its nodes. */\nexport function clearBranch(branch: Branch): void {\n for (let i = branch.disposers.length - 1; i >= 0; i--) {\n try {\n branch.disposers[i]();\n } catch {\n /* ignore */\n }\n }\n branch.disposers = [];\n for (const node of branch.nodes) {\n node.parentNode?.removeChild(node);\n }\n branch.nodes = [];\n}\n"]}
@@ -37,26 +37,8 @@ export interface SSRRenderCrash {
37
37
  * `bindComponentTags`, `fragment.contains(el)` in `applyBindings`). It can
38
38
  * no longer contribute to the output, so any record for it is stale.
39
39
  *
40
- * Retraction matters because the JIT `@if` path really does attempt the same tag
41
- * twice, measured by counting component invocations:
42
- *
43
- * 1. `bindStructuralDirectives` runs first and `handleConditionalChain` binds
44
- * the chosen branch while it is still DETACHED, so `el.closest('[data-error]')`
45
- * finds nothing and the crash is recorded.
46
- * 2. The branch is inserted, and `bindTemplateDirectives` then reaches the
47
- * still-raw tag on the assembled tree, where the boundary is visible and
48
- * accepts — retracting via case 1 above.
49
- *
50
- * Case 3 exists because accepting is synchronous: it immediately hides the
51
- * boundary's content, so a SECOND crashing component in that branch is detached
52
- * before it can be retried, and its detached-pass record would otherwise stand
53
- * and fail a route whose fallback rendered correctly.
54
- *
55
40
  * Every one of these is mutation-tested; removing any of them turns a correct
56
41
  * render into a failed route, or a broken one into a silent success.
57
- *
58
- * AOT invokes `applyComponent` once per `pid` and never retries, which is why
59
- * the equivalent AOT boundary case behaves differently — see BUG-023.
60
42
  */
61
43
  /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"clearSSRRenderCrash","stability":"internal","signature":"(el: Element) => void"} */
62
44
  export declare function clearSSRRenderCrash(el: Element): void;
@@ -66,6 +48,12 @@ export declare function clearSSRRenderCrash(el: Element): void;
66
48
  */
67
49
  /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resetSSRRenderCrashes","stability":"stable","signature":"() => void"} */
68
50
  export declare function resetSSRRenderCrashes(): void;
51
+ /**
52
+ * An element that left the tree being bound contributes nothing to the output:
53
+ * its recorded crash is stale, and an attributed one is only logged.
54
+ */
55
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"forgetCrash","stability":"internal","signature":"(el: Element) => void"} */
56
+ export declare function forgetCrash(el: Element): void;
69
57
  /**
70
58
  * Return the crashes still recorded once the render has finished, and empty
71
59
  * the collector.
@@ -77,23 +65,15 @@ export declare function resetSSRRenderCrashes(): void;
77
65
  * An earlier draft re-resolved each record's boundary here, dropping any crash
78
66
  * whose element had ended up inside an `@error-boundary`. That is unsound,
79
67
  * because a boundary *existing* above an element is not the same as that
80
- * boundary having *handled* the crash:
81
- *
82
- * - JIT never needed it. It does record a crash from the detached first
83
- * attempt, but the retry after insertion is caught by the boundary and
84
- * retracts that record itself (see `clearSSRRenderCrash`). By collect time
85
- * there is nothing left to re-resolve.
86
- * - AOT was actively broken by it. A branch factory binds its subtree while
87
- * detached, so `applyComponent`'s `el.closest('[data-error]')` finds
88
- * nothing and the boundary never receives the error — but the nodes are
89
- * then inserted *under* that boundary, so re-resolution saw one and
90
- * dropped the record. The boundary signal stayed null, its fallback never
91
- * activated, the raw component tag shipped, and the build went green: the
92
- * exact BUG-018 symptom, reintroduced by its own fix.
68
+ * boundary having *handled* the crash. A crash that a boundary rejected, or
69
+ * that ran where no boundary resolved, is placed under one afterwards just the
70
+ * same. Re-resolution dropped such a record: the boundary signal stayed null,
71
+ * its fallback never activated, the raw component tag shipped, and the build
72
+ * went green — the exact BUG-018 symptom, reintroduced by its own fix.
93
73
  *
94
- * That AOT boundary gap is real but predates this collector and is tracked
95
- * separately as BUG-023. Until it is fixed, such a crash fails its route, which
96
- * is the safe direction: a loud failure rather than silently truncated HTML.
74
+ * A crash in a branch, slot or component built detached is attributed to its
75
+ * boundary instead (`deferCrash`); whatever is still attributed here is
76
+ * recorded.
97
77
  */
98
78
  /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"collectUnhandledSSRRenderCrashes","stability":"stable","signature":"() => SSRRenderCrash[]"} */
99
79
  export declare function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[];
@@ -109,8 +89,56 @@ export declare function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[];
109
89
  * the boundary signal null, rendered no fallback, and failed the route, even
110
90
  * though the code called it "the same content loss as a crash".
111
91
  *
92
+ * With no `boundary`, a failure in a branch, slot or component built detached
93
+ * is attributed to the boundary its render sits under (`deferCrash`) and counts
94
+ * as handled here; `attribution` says how it is logged if no boundary takes it.
95
+ *
112
96
  * Callers still do their own logging, since the wording differs per failure.
113
97
  */
114
- /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"reportComponentFailure","stability":"internal","signature":"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null) => boolean"} */
115
- export declare function reportComponentFailure(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null): boolean;
98
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"reportComponentFailure","stability":"internal","signature":"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null, attribution?: Attribution) => boolean"} */
99
+ export declare function reportComponentFailure(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null, attribution?: Attribution): boolean;
100
+ /** How an attributed crash is logged: `message` if no boundary takes it, `onCaptured` if one does. */
101
+ export interface Attribution {
102
+ message?: string | null;
103
+ onCaptured?: () => void;
104
+ }
105
+ /** Whether `el` crashed and was attributed; a retry would run its setup twice, which a build never does. */
106
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"hasCrashed","stability":"internal","signature":"(el: Element) => boolean"} */
107
+ export declare function hasCrashed(el: Element): boolean;
108
+ /**
109
+ * Brackets a render transaction: a template bind, or one structural update
110
+ * that builds a branch and inserts it. Attributed crashes are resolved when the
111
+ * outermost one ends, so a boundary hides its content only once everything in
112
+ * it is bound and in place.
113
+ */
114
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"withinRender","stability":"internal","signature":"<T>(fn: () => T) => T"} */
115
+ export declare function withinRender<T>(fn: () => T): T;
116
+ /**
117
+ * Attributes a crash that reached no boundary through the DOM to the boundary
118
+ * its render sits under (`boundaryContext`): a branch, slot or component built
119
+ * detached. Returns `false` with no such context, so the caller handles the
120
+ * crash as before.
121
+ */
122
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"deferCrash","stability":"internal","signature":"(el: Element, tag: string, error: Error, attribution?: Attribution) => boolean"} */
123
+ export declare function deferCrash(el: Element, tag: string, error: Error, { message, onCaptured }?: Attribution): boolean;
124
+ /**
125
+ * Resolves attributed crashes once they are in place. Each goes to the nearest
126
+ * registered boundary at its final position, exactly as a crash placed there
127
+ * would, and within one resolution a boundary takes at most one error. In the
128
+ * browser this waits for the
129
+ * outermost render to end. A static render binds text once, so there the
130
+ * component pass of the template that owns a boundary resolves its crashes
131
+ * (`scope`), before that template's text is bound and after its components
132
+ * ran. `task` runs at the end of the task; `collect` after the HTML is
133
+ * serialized, and only records.
134
+ */
135
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resolveAttributedCrashes","stability":"internal","signature":"(mode?: 'render' | 'task' | 'collect', scope?: ParentNode) => void"} */
136
+ export declare function resolveAttributedCrashes(mode?: 'render' | 'task' | 'collect', scope?: ParentNode): void;
137
+ /**
138
+ * Before a component inside a boundary's fallback renders in a static render,
139
+ * that boundary takes its crashes, so content the component renders from the
140
+ * error (text is bound once there) has it.
141
+ */
142
+ /** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resolveBeforeFallback","stability":"internal","signature":"(el: Element) => void"} */
143
+ export declare function resolveBeforeFallback(el: Element): void;
116
144
  //# sourceMappingURL=ssrCrashes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrCrashes.d.ts","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAIF,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,KAAK,EAAE,KAAK,CAAC;CACd;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;A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