@pithyjs/core 0.1.0-beta.22 → 0.1.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/compile/bindSwitchCases.d.ts.map +1 -1
- package/dist/compile/bindSwitchCases.js +2 -1
- package/dist/compile/bindSwitchCases.js.map +1 -1
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +41 -78
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
- package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
- package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.d.ts +3 -3
- package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.js +7 -5
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.d.ts +8 -2
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.js +99 -25
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
- package/dist/compile/binds/propNames.d.ts +5 -1
- package/dist/compile/binds/propNames.d.ts.map +1 -1
- package/dist/compile/binds/propNames.js +36 -1
- package/dist/compile/binds/propNames.js.map +1 -1
- package/dist/compile/binds/propWarnings.d.ts +11 -0
- package/dist/compile/binds/propWarnings.d.ts.map +1 -0
- package/dist/compile/binds/propWarnings.js +43 -0
- package/dist/compile/binds/propWarnings.js.map +1 -0
- package/dist/compile/contentProjection.d.ts +14 -2
- package/dist/compile/contentProjection.d.ts.map +1 -1
- package/dist/compile/contentProjection.js +47 -9
- package/dist/compile/contentProjection.js.map +1 -1
- package/dist/compile/evalDiagnostics.d.ts +5 -0
- package/dist/compile/evalDiagnostics.d.ts.map +1 -1
- package/dist/compile/evalDiagnostics.js +5 -0
- package/dist/compile/evalDiagnostics.js.map +1 -1
- package/dist/compile/forLoops/createLoopManager.d.ts +3 -1
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
- package/dist/compile/forLoops/createLoopManager.js +9 -5
- package/dist/compile/forLoops/createLoopManager.js.map +1 -1
- package/dist/compile/nodeExpando.d.ts +1 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -1
- package/dist/compile/nodeExpando.js.map +1 -1
- package/dist/compile/ssrCrashes.d.ts +6 -0
- package/dist/compile/ssrCrashes.d.ts.map +1 -1
- package/dist/compile/ssrCrashes.js +91 -19
- package/dist/compile/ssrCrashes.js.map +1 -1
- package/dist/runtime/applyBindings.d.ts +6 -0
- package/dist/runtime/applyBindings.d.ts.map +1 -1
- package/dist/runtime/applyBindings.js +13 -2
- package/dist/runtime/applyBindings.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts +3 -1
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +14 -4
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applyDefer.js +2 -2
- package/dist/runtime/bindings/applyDefer.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +10 -4
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
- package/dist/runtime/bindings/applyStructural.js +19 -5
- package/dist/runtime/bindings/applyStructural.js.map +1 -1
- package/dist/runtime/bindings/helpers.d.ts.map +1 -1
- package/dist/runtime/bindings/helpers.js +2 -1
- package/dist/runtime/bindings/helpers.js.map +1 -1
- package/dist/runtime/bindings/types.d.ts +4 -0
- package/dist/runtime/bindings/types.d.ts.map +1 -1
- package/dist/runtime/bindings/types.js.map +1 -1
- package/dist/types/globals.d.ts +3 -0
- package/dist/types/globals.d.ts.map +1 -1
- package/dist/types/globals.js.map +1 -1
- package/package.json +2 -2
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { untrack } from '@pithyjs/signals';
|
|
10
10
|
import { pithyGlobals } from '../types/globals.js';
|
|
11
11
|
import { isSSRMode } from './ssrMode.js';
|
|
12
|
-
import { boundaryContext, findParentBoundary, isInHiddenContent, registeredClosest, setBoundaryError, slotOwnerOf, } from './binds/bindErrorBoundary.js';
|
|
12
|
+
import { boundaryContext, findParentBoundary, inOwnFallback, inBranch, isInHiddenContent, registeredClosest, setBoundaryError, slotOwnerOf, } from './binds/bindErrorBoundary.js';
|
|
13
13
|
/**
|
|
14
14
|
* Crashes recorded during the current server render, keyed by the placeholder
|
|
15
15
|
* element so a later binding pass over the same element can retract its own
|
|
@@ -160,14 +160,22 @@ export function collectUnhandledSSRRenderCrashes() {
|
|
|
160
160
|
export function reportComponentFailure(el, tag, error, boundary, attribution = {}) {
|
|
161
161
|
if (!boundary && deferCrash(el, tag, error, attribution))
|
|
162
162
|
return true;
|
|
163
|
-
return settleFailure(el, tag, error, boundary);
|
|
163
|
+
return settleFailure(el, tag, error, boundary, attribution);
|
|
164
164
|
}
|
|
165
|
-
function settleFailure(el, tag, error, boundary) {
|
|
165
|
+
function settleFailure(el, tag, error, boundary, attribution = {}) {
|
|
166
|
+
while (boundary && inOwnFallback(boundary, el)) {
|
|
167
|
+
const from = boundary;
|
|
168
|
+
boundary = findParentBoundary(from);
|
|
169
|
+
if (!boundary &&
|
|
170
|
+
!from.element.isConnected &&
|
|
171
|
+
deferCrash(el, tag, error, attribution))
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
166
174
|
// A boundary in scope is not a boundary that accepted: an already-active one
|
|
167
175
|
// with no free ancestor rejects, and that is as unhandled as having none.
|
|
168
176
|
const accepted = boundary ? setBoundaryError(boundary, error) : false;
|
|
169
177
|
if (isSSRMode()) {
|
|
170
|
-
if (accepted)
|
|
178
|
+
if (accepted || isInHiddenContent(el))
|
|
171
179
|
clearSSRRenderCrash(el);
|
|
172
180
|
else
|
|
173
181
|
recordSSRRenderCrash(el, tag, error);
|
|
@@ -179,6 +187,7 @@ const ops = {
|
|
|
179
187
|
owner: slotOwnerOf,
|
|
180
188
|
hidden: isInHiddenContent,
|
|
181
189
|
parent: findParentBoundary,
|
|
190
|
+
ownFallback: inOwnFallback,
|
|
182
191
|
settle: settleFailure,
|
|
183
192
|
};
|
|
184
193
|
let taskEndQueued = false;
|
|
@@ -246,6 +255,22 @@ export function withinRender(fn) {
|
|
|
246
255
|
resolveAttributedCrashes();
|
|
247
256
|
}
|
|
248
257
|
}
|
|
258
|
+
function branchFailures() {
|
|
259
|
+
const g = pithyGlobals();
|
|
260
|
+
return (g.__pithyBranchFailures ?? (g.__pithyBranchFailures = new WeakSet()));
|
|
261
|
+
}
|
|
262
|
+
/** Logs a component failure, and marks `el` when it failed in a branch. */
|
|
263
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"logFailure","stability":"internal","signature":"(el: Element, log: () => void) => void"} */
|
|
264
|
+
export function logFailure(el, log) {
|
|
265
|
+
if (inBranch())
|
|
266
|
+
branchFailures().add(el);
|
|
267
|
+
log();
|
|
268
|
+
}
|
|
269
|
+
/** Whether `el` failed while its branch was built; the pass that binds the inserted branch would retry it (BUG-161). */
|
|
270
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"failedInBranch","stability":"internal","signature":"(el: Element) => boolean"} */
|
|
271
|
+
export function failedInBranch(el) {
|
|
272
|
+
return branchFailures().has(el);
|
|
273
|
+
}
|
|
249
274
|
/**
|
|
250
275
|
* Attributes a crash that reached no boundary through the DOM to the boundary
|
|
251
276
|
* its render sits under (`boundaryContext`): a branch, slot or component built
|
|
@@ -274,6 +299,12 @@ export function deferCrash(el, tag, error, { message = null, onCaptured } = {})
|
|
|
274
299
|
resolveAtTaskEnd();
|
|
275
300
|
return true;
|
|
276
301
|
}
|
|
302
|
+
function hold(crash) {
|
|
303
|
+
var _a;
|
|
304
|
+
((_a = pithyGlobals()).__pithyAttributedCrashes ?? (_a.__pithyAttributedCrashes = [])).push(crash);
|
|
305
|
+
if (renderDepth() === 0)
|
|
306
|
+
resolveAtTaskEnd();
|
|
307
|
+
}
|
|
277
308
|
function reportCrashesOf(render) {
|
|
278
309
|
const list = heldCrashes();
|
|
279
310
|
if (!list?.length)
|
|
@@ -363,10 +394,16 @@ export function resolveAttributedCrashes(mode = 'render', scope) {
|
|
|
363
394
|
.map(entry => ({ entry, depth: depthOf(entry[0].element) }))
|
|
364
395
|
.sort((a, b) => b.depth - a.depth)
|
|
365
396
|
.map(({ entry }) => entry);
|
|
366
|
-
const
|
|
397
|
+
const run = {
|
|
398
|
+
groups,
|
|
399
|
+
handled: new Set(),
|
|
400
|
+
settled: new Set(),
|
|
401
|
+
resolved: new Set(),
|
|
402
|
+
final: mode === 'task',
|
|
403
|
+
};
|
|
367
404
|
for (const [boundary, group] of innermostFirst) {
|
|
368
405
|
try {
|
|
369
|
-
resolveGroup(boundary, group,
|
|
406
|
+
resolveGroup(boundary, group, run);
|
|
370
407
|
}
|
|
371
408
|
catch (err) {
|
|
372
409
|
reportResolveFailure(group, err);
|
|
@@ -385,26 +422,52 @@ function depthOf(node) {
|
|
|
385
422
|
depth++;
|
|
386
423
|
return depth;
|
|
387
424
|
}
|
|
425
|
+
function settleContent(boundary, run) {
|
|
426
|
+
if (run.settled.has(boundary))
|
|
427
|
+
return;
|
|
428
|
+
run.settled.add(boundary);
|
|
429
|
+
for (const [inner, group] of run.groups)
|
|
430
|
+
if (inner !== boundary &&
|
|
431
|
+
boundary.element.contains(inner.element) &&
|
|
432
|
+
!boundary.fallbackElement?.contains(inner.element))
|
|
433
|
+
resolveGroup(inner, group, run);
|
|
434
|
+
for (const crash of run.groups.get(boundary) ?? []) {
|
|
435
|
+
if (boundary.fallbackElement?.contains(crash.el))
|
|
436
|
+
continue;
|
|
437
|
+
if (partOfShown(crash, boundary))
|
|
438
|
+
logCrash(crash);
|
|
439
|
+
else
|
|
440
|
+
deliver(crash, boundary, run);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
388
443
|
/**
|
|
389
444
|
* One boundary's crashes, content before fallback, so the outcome does not
|
|
390
445
|
* depend on the order they happened in. Each is handled as a crash placed there
|
|
391
|
-
* directly: a content crash goes to the boundary, a fallback crash
|
|
392
|
-
* the boundary already shows its fallback, in which case it goes further out.
|
|
446
|
+
* directly: a content crash goes to the boundary, a fallback crash further out.
|
|
393
447
|
*/
|
|
394
|
-
function resolveGroup(boundary, group,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
448
|
+
function resolveGroup(boundary, group, run) {
|
|
449
|
+
if (run.resolved.has(boundary))
|
|
450
|
+
return;
|
|
451
|
+
run.resolved.add(boundary);
|
|
452
|
+
settleContent(boundary, run);
|
|
453
|
+
for (const crash of group) {
|
|
454
|
+
if (!boundary.fallbackElement?.contains(crash.el))
|
|
455
|
+
continue;
|
|
456
|
+
const outer = crash.ops.parent(boundary);
|
|
457
|
+
if (!outer && !run.final && !boundary.element.isConnected)
|
|
458
|
+
hold(crash);
|
|
459
|
+
else if (partOfShown(crash, outsideOwnFallback(crash, outer)))
|
|
403
460
|
logCrash(crash);
|
|
404
461
|
else
|
|
405
|
-
deliver(crash,
|
|
462
|
+
deliver(crash, outer, run);
|
|
406
463
|
}
|
|
407
464
|
}
|
|
465
|
+
function outsideOwnFallback(crash, from) {
|
|
466
|
+
let at = from;
|
|
467
|
+
while (at && crash.ops.ownFallback(at, crash.el))
|
|
468
|
+
at = crash.ops.parent(at);
|
|
469
|
+
return at;
|
|
470
|
+
}
|
|
408
471
|
// Slot content a portal moves out of its boundary goes to that boundary, as a
|
|
409
472
|
// component crash in it does through the slot frame. Only the nodes a slot
|
|
410
473
|
// rendered carry an owner: a root a component mounts during setup has none.
|
|
@@ -431,8 +494,17 @@ function showsError(boundary) {
|
|
|
431
494
|
* showing an error, as `setBoundaryError` escalates a crash placed there. One
|
|
432
495
|
* that reaches a boundary showing an error from this resolution is part of it.
|
|
433
496
|
*/
|
|
434
|
-
function deliver(crash, from,
|
|
497
|
+
function deliver(crash, from, run) {
|
|
498
|
+
const { handled, final } = run;
|
|
435
499
|
for (let at = from; at; at = crash.ops.parent(at)) {
|
|
500
|
+
if (crash.ops.ownFallback(at, crash.el)) {
|
|
501
|
+
if (!final && !at.element.isConnected && !crash.ops.parent(at)) {
|
|
502
|
+
hold(crash);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
settleContent(at, run);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
436
508
|
if (handled.has(at)) {
|
|
437
509
|
logCrash(crash);
|
|
438
510
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrCrashes.js","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,GAEZ,MAAM,2BAA2B,CAAC;AAcnC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,aAAa;IACpB,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;IACzB,OAAO,CAAC,CAAC,CAAC,iBAAiB,KAAnB,CAAC,CAAC,iBAAiB,GAAK,IAAI,GAAG,EAAE,EAAiC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,+IAA+I;AAC/I,MAAM,UAAU,mBAAmB,CAAC,EAAW;IAC7C,aAAa,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,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C5E,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBAAE,oBAAoB,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;;gBACnD,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;YACjE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QACD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;QACvB,CAAC;;YAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IACD,SAAS,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,iJAAiJ;AACjJ,MAAM,UAAU,qBAAqB,CAAC,EAAW;IAC/C,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,MAAM;QAAE,OAAO;IACnD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACrE,IAAI,KAAK;QAAE,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.ssr-crashes\",\n \"title\": \"SSR Unhandled Component Crash Collector\",\n \"category\": \"runtime\",\n \"risk\": \"high\"\n}\n*/\n\nimport { untrack } from '@pithyjs/signals';\nimport { pithyGlobals } from '../types/globals';\nimport { isSSRMode } from './ssrMode';\nimport {\n boundaryContext,\n findParentBoundary,\n isInHiddenContent,\n registeredClosest,\n setBoundaryError,\n slotOwnerOf,\n type BoundaryInfo,\n} from './binds/bindErrorBoundary';\n\n/**\n * A component render crash recorded during a static/server render.\n */\nexport interface SSRRenderCrash {\n /** The custom-element placeholder the crashed component was to replace. */\n el: Element;\n /** Authored tag name, for the failure message. */\n tag: string;\n /** The error the component threw. */\n error: Error;\n}\n\n/**\n * Crashes recorded during the current server render, keyed by the placeholder\n * element so a later binding pass over the same element can retract its own\n * earlier record (see `clearSSRRenderCrash`).\n *\n * Held on `globalThis`, not in this module. `@pithyjs/ssr` depends on\n * `@pithyjs/core` as a regular dependency, so an app and the SSR package can\n * resolve two physical copies: `html()` would record into the app's copy while\n * `renderToString()` collected and reset the SSR package's, reintroducing\n * BUG-018 *and* leaking the app copy's DOM records for the life of the process.\n * The same reasoning already puts `__PITHY_SSR__` and `__getComponentContext`\n * on this bridge.\n *\n * A `Map` (not a `WeakMap`) because the collector must be enumerable at flush\n * time. `resetSSRRenderCrashes()` is what keeps it from retaining DOM across\n * renders — the SSR renderer calls it in a `finally`.\n */\nfunction crashRegistry(): Map<Element, SSRRenderCrash> {\n const g = pithyGlobals();\n return (g.__pithySSRCrashes ??= new Map()) as Map<Element, SSRRenderCrash>;\n}\n\n/**\n * Forget any crash previously recorded for `el`.\n *\n * Called only at points where the record is provably no longer the outcome, and\n * NEVER before invoking a component. Retracting eagerly at the top of an attempt\n * hides a failed retry: a component that throws detached and then returns\n * something unusable would have its only record erased, shipping a page with a\n * missing subtree and a green build. The three call sites are:\n *\n * 1. A boundary ACCEPTING the error (`setBoundaryError()` returning `true`).\n * A boundary merely being in scope is not enough — an already-active one\n * with no free ancestor rejects the error, and that is as unhandled as\n * having no boundary at all.\n * 2. A component returning a usable node that then successfully reaches the\n * document, i.e. after `replaceWith` has not thrown.\n * 3. An element that has left the tree being bound (`scope.contains(el)` in\n * `bindComponentTags`, `fragment.contains(el)` in `applyBindings`). It can\n * no longer contribute to the output, so any record for it is stale.\n *\n * Every one of these is mutation-tested; removing any of them turns a correct\n * render into a failed route, or a broken one into a silent success.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"clearSSRRenderCrash\",\"stability\":\"internal\",\"signature\":\"(el: Element) => void\"} */\nexport function clearSSRRenderCrash(el: Element): void {\n crashRegistry().delete(el);\n}\n\n/**\n * Record a component failure that no error boundary took ownership of.\n *\n * The precondition is **not** \"no boundary was in scope\". It is that no boundary\n * ACCEPTED the error, which is a strictly weaker thing: `setBoundaryError()`\n * rejects an error when the nearest boundary is already showing one and no\n * ancestor is free, and both binders call this on that path with a boundary\n * very much present. Getting the two confused is what this whole module exists\n * to prevent.\n *\n * Nor is \"crash\" limited to a thrown error. The binders also record a component\n * that returned an unusable result, and one whose rendered node failed to reach\n * the document — both leave the raw tag exactly where a throw would, which is\n * the same content loss from the page's point of view.\n *\n * Callers must have established `isSSRMode()` themselves; this does not\n * re-check.\n */\nfunction recordSSRRenderCrash(el: Element, tag: string, error: unknown): void {\n crashRegistry().set(el, {\n el,\n tag,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n}\n\n/**\n * Drop every recorded crash. Called by the SSR renderer before a render starts\n * and again in its `finally`, so one route's crash can never fail the next.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"resetSSRRenderCrashes\",\"stability\":\"stable\",\"signature\":\"() => void\"} */\nexport function resetSSRRenderCrashes(): void {\n crashRegistry().clear();\n const g = pithyGlobals();\n g.__pithyAttributedCrashes = [];\n g.__pithyRenderDepth = 0;\n}\n\n/**\n * An element that left the tree being bound contributes nothing to the output:\n * its recorded crash is stale, and an attributed one is only logged.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"forgetCrash\",\"stability\":\"internal\",\"signature\":\"(el: Element) => void\"} */\nexport function forgetCrash(el: Element): void {\n clearSSRRenderCrash(el);\n const crash = takeAttributedCrash(el);\n if (crash) logCrash(crash);\n}\n\nfunction takeAttributedCrash(el: Element): AttributedCrash | undefined {\n const list = heldCrashes();\n const at = list?.findIndex(crash => crash.el === el) ?? -1;\n return at >= 0 ? list?.splice(at, 1)[0] : undefined;\n}\n\n/**\n * Return the crashes still recorded once the render has finished, and empty\n * the collector.\n *\n * Every surviving record is a failure. A record is only ever retracted by\n * `clearSSRRenderCrash`, i.e. by a genuine re-attempt at the same element that\n * then went better — never by inspecting the finished tree.\n *\n * An earlier draft re-resolved each record's boundary here, dropping any crash\n * whose element had ended up inside an `@error-boundary`. That is unsound,\n * because a boundary *existing* above an element is not the same as that\n * boundary having *handled* the crash. A crash that a boundary rejected, or\n * that ran where no boundary resolved, is placed under one afterwards just the\n * same. Re-resolution dropped such a record: the boundary signal stayed null,\n * its fallback never activated, the raw component tag shipped, and the build\n * went green — the exact BUG-018 symptom, reintroduced by its own fix.\n *\n * A crash in a branch, slot or component built detached is attributed to its\n * boundary instead (`deferCrash`); whatever is still attributed here is\n * recorded.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"collectUnhandledSSRRenderCrashes\",\"stability\":\"stable\",\"signature\":\"() => SSRRenderCrash[]\"} */\nexport function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[] {\n resolveAttributedCrashes('collect');\n const registry = crashRegistry();\n const unhandled = [...registry.values()];\n registry.clear();\n return unhandled;\n}\n\n/**\n * Hand a component failure to its `@error-boundary`, or record it if none takes\n * it. Returns whether a boundary accepted ownership.\n *\n * The single funnel for every way a component can fail to produce content: a\n * thrown error, an unusable return value, and a rendered node that never reached\n * the document. They were handled in five separate places and drifted — the\n * throw paths consulted the boundary while the malformed paths recorded\n * directly, so a component under `@error-boundary` that returned garbage left\n * the boundary signal null, rendered no fallback, and failed the route, even\n * though the code called it \"the same content loss as a crash\".\n *\n * With no `boundary`, a failure in a branch, slot or component built detached\n * is attributed to the boundary its render sits under (`deferCrash`) and counts\n * as handled here; `attribution` says how it is logged if no boundary takes it.\n *\n * Callers still do their own logging, since the wording differs per failure.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"reportComponentFailure\",\"stability\":\"internal\",\"signature\":\"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null, attribution?: Attribution) => boolean\"} */\nexport function reportComponentFailure(\n el: Element,\n tag: string,\n error: Error,\n boundary: BoundaryInfo | null,\n attribution: Attribution = {}\n): boolean {\n if (!boundary && deferCrash(el, tag, error, attribution)) return true;\n return settleFailure(el, tag, error, boundary);\n}\n\n/** How an attributed crash is logged: `message` if no boundary takes it, `onCaptured` if one does. */\nexport interface Attribution {\n message?: string | null;\n onCaptured?: () => void;\n}\n\nfunction settleFailure(\n el: Element,\n tag: string,\n error: Error,\n boundary: BoundaryInfo | null\n): boolean {\n // A boundary in scope is not a boundary that accepted: an already-active one\n // with no free ancestor rejects, and that is as unhandled as having none.\n const accepted = boundary ? setBoundaryError(boundary, error) : false;\n\n if (isSSRMode()) {\n if (accepted) clearSSRRenderCrash(el);\n else recordSSRRenderCrash(el, tag, error);\n }\n\n return accepted;\n}\n\n/** A crash raised where no boundary was reachable, owned by the boundary its render sat under. */\ninterface AttributedCrash extends SSRRenderCrash {\n /** The boundary the branch, slot or component was built for: the crash waits until it is inside. */\n boundaryEl: Element;\n message: string | null;\n onCaptured?: () => void;\n ops: CrashOps;\n /** The outermost render it was attributed in; `0` outside any. */\n render: number;\n}\n\n/** The copy of core that attributed a crash answers these, against its own boundaries. */\ninterface CrashOps {\n locate: (el: Element) => BoundaryInfo | null;\n owner: (node: Node) => Element | null;\n hidden: (node: Node) => boolean;\n parent: (boundary: BoundaryInfo) => BoundaryInfo | null;\n settle: typeof settleFailure;\n}\n\nconst ops: CrashOps = {\n locate: registeredClosest,\n owner: slotOwnerOf,\n hidden: isInHiddenContent,\n parent: findParentBoundary,\n settle: settleFailure,\n};\n\nlet taskEndQueued = false;\n\n// A crash that is neither in place nor hidden when a render ends may belong to\n// content its caller inserts right after (a slot rendered from an effect): it\n// waits once, to the end of the task, before it is reported.\nfunction resolveAtTaskEnd(): void {\n if (taskEndQueued) return;\n taskEndQueued = true;\n queueMicrotask(() => {\n taskEndQueued = false;\n resolveAttributedCrashes('task');\n });\n}\n\n// Shared on `globalThis` for the reason the registry is: a second copy of core\n// must neither miss these nor resolve them in the middle of a render.\n\nfunction heldCrashes(): AttributedCrash[] | undefined {\n return pithyGlobals().__pithyAttributedCrashes as\n | AttributedCrash[]\n | undefined;\n}\n\nfunction renderDepth(change = 0): number {\n const g = pithyGlobals();\n return (g.__pithyRenderDepth = (g.__pithyRenderDepth ?? 0) + change);\n}\n\nfunction currentRender(): number {\n return renderDepth() > 0 ? (pithyGlobals().__pithyRenderId ?? 0) : 0;\n}\n\nfunction crashedElements(): WeakSet<Element> {\n const g = pithyGlobals();\n return (g.__pithyCrashedElements ??= new WeakSet()) as WeakSet<Element>;\n}\n\n/** Whether `el` crashed and was attributed; a retry would run its setup twice, which a build never does. */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"hasCrashed\",\"stability\":\"internal\",\"signature\":\"(el: Element) => boolean\"} */\nexport function hasCrashed(el: Element): boolean {\n return crashedElements().has(el);\n}\n\n/**\n * Brackets a render transaction: a template bind, or one structural update\n * that builds a branch and inserts it. Attributed crashes are resolved when the\n * outermost one ends, so a boundary hides its content only once everything in\n * it is bound and in place.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"withinRender\",\"stability\":\"internal\",\"signature\":\"<T>(fn: () => T) => T\"} */\nexport function withinRender<T>(fn: () => T): T {\n const g = pithyGlobals();\n if (renderDepth() === 0) g.__pithyRenderId = (g.__pithyRenderId ?? 0) + 1;\n const render = g.__pithyRenderId ?? 0;\n renderDepth(1);\n let failed = false;\n try {\n return fn();\n } catch (err) {\n failed = true;\n throw err;\n } finally {\n renderDepth(-1);\n // Never throws, so a failed render keeps its own error. Its caller disposes\n // what it bound, boundaries included, so its own crashes are only reported.\n if (failed && renderDepth() === 0) reportCrashesOf(render);\n else resolveAttributedCrashes();\n }\n}\n\n/**\n * Attributes a crash that reached no boundary through the DOM to the boundary\n * its render sits under (`boundaryContext`): a branch, slot or component built\n * detached. Returns `false` with no such context, so the caller handles the\n * crash as before.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"deferCrash\",\"stability\":\"internal\",\"signature\":\"(el: Element, tag: string, error: Error, attribution?: Attribution) => boolean\"} */\nexport function deferCrash(\n el: Element,\n tag: string,\n error: Error,\n { message = null, onCaptured }: Attribution = {}\n): boolean {\n const boundaryEl = boundaryContext();\n if (!boundaryEl) return false;\n crashedElements().add(el);\n takeAttributedCrash(el);\n (pithyGlobals().__pithyAttributedCrashes ??= []).push({\n el,\n tag,\n error,\n boundaryEl,\n message,\n onCaptured,\n ops,\n render: currentRender(),\n });\n if (renderDepth() === 0) resolveAtTaskEnd();\n return true;\n}\n\nfunction reportCrashesOf(render: number): void {\n const list = heldCrashes();\n if (!list?.length) return;\n for (const crash of list.splice(0)) {\n if (crash.render !== render) list.push(crash);\n else\n try {\n unhandled(crash);\n } catch (err) {\n reportResolveFailure([crash], err);\n }\n }\n}\n\nfunction logCrash(crash: AttributedCrash): void {\n if (crash.message) console.error(crash.message, crash.error);\n}\n\nfunction unhandled(crash: AttributedCrash): void {\n crash.ops.settle(crash.el, crash.tag, crash.error, null);\n logCrash(crash);\n}\n\n/**\n * Resolves attributed crashes once they are in place. Each goes to the nearest\n * registered boundary at its final position, exactly as a crash placed there\n * would, and within one resolution a boundary takes at most one error. In the\n * browser this waits for the\n * outermost render to end. A static render binds text once, so there the\n * component pass of the template that owns a boundary resolves its crashes\n * (`scope`), before that template's text is bound and after its components\n * ran. `task` runs at the end of the task; `collect` after the HTML is\n * serialized, and only records.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"resolveAttributedCrashes\",\"stability\":\"internal\",\"signature\":\"(mode?: 'render' | 'task' | 'collect', scope?: ParentNode) => void\"} */\nexport function resolveAttributedCrashes(\n mode: 'render' | 'task' | 'collect' = 'render',\n scope?: ParentNode\n): void {\n const list = heldCrashes();\n if (!list?.length) return;\n const midRender = mode === 'render' && renderDepth() > 0;\n if (midRender && (!scope || !isSSRMode())) return;\n const groups = new Map<BoundaryInfo, AttributedCrash[]>();\n const into = (boundary: BoundaryInfo, crash: AttributedCrash) => {\n const group = groups.get(boundary);\n if (group) group.push(crash);\n else groups.set(boundary, [crash]);\n };\n let waiting = false;\n for (const crash of list.splice(0)) {\n try {\n if (mode === 'collect') {\n unhandled(crash);\n continue;\n }\n if (midRender && !scope?.contains(crash.boundaryEl)) {\n list.push(crash);\n continue;\n }\n const target = placedAt(crash);\n if (partOfShown(crash, target)) {\n logCrash(crash);\n continue;\n }\n if (target) into(target, crash);\n // In its boundary with no registered one around it, or out of time.\n else if (\n mode === 'task' ||\n (!midRender && crash.boundaryEl.contains(crash.el))\n )\n unhandled(crash);\n else {\n // Not inserted yet: its caller may insert it right after.\n list.push(crash);\n waiting ||= !midRender;\n }\n } catch (err) {\n reportResolveFailure([crash], err);\n }\n }\n if (waiting) resolveAtTaskEnd();\n const innermostFirst = [...groups.entries()]\n .map(entry => ({ entry, depth: depthOf(entry[0].element) }))\n .sort((a, b) => b.depth - a.depth)\n .map(({ entry }) => entry);\n const handled = new Set<BoundaryInfo>();\n for (const [boundary, group] of innermostFirst) {\n try {\n resolveGroup(boundary, group, handled);\n } catch (err) {\n reportResolveFailure(group, err);\n }\n }\n}\n\nfunction reportResolveFailure(crashes: AttributedCrash[], err: unknown): void {\n for (const crash of crashes)\n if (isSSRMode()) recordSSRRenderCrash(crash.el, crash.tag, crash.error);\n console.error('❌ Resolving a component crash failed:', err);\n}\n\nfunction depthOf(node: Node): number {\n let depth = 0;\n for (let at = node.parentNode; at; at = at.parentNode) depth++;\n return depth;\n}\n\n/**\n * One boundary's crashes, content before fallback, so the outcome does not\n * depend on the order they happened in. Each is handled as a crash placed there\n * directly: a content crash goes to the boundary, a fallback crash too unless\n * the boundary already shows its fallback, in which case it goes further out.\n */\nfunction resolveGroup(\n boundary: BoundaryInfo,\n group: AttributedCrash[],\n handled: Set<BoundaryInfo>\n): void {\n const inFallback = (crash: AttributedCrash) =>\n !!boundary.fallbackElement?.contains(crash.el);\n for (const crash of group.filter(crash => !inFallback(crash)))\n if (partOfShown(crash, boundary)) logCrash(crash);\n else deliver(crash, boundary, handled);\n for (const crash of group.filter(inFallback)) {\n if (partOfShown(crash, boundary)) logCrash(crash);\n else\n deliver(\n crash,\n showsError(boundary) ? crash.ops.parent(boundary) : boundary,\n handled\n );\n }\n}\n\n// Slot content a portal moves out of its boundary goes to that boundary, as a\n// component crash in it does through the slot frame. Only the nodes a slot\n// rendered carry an owner: a root a component mounts during setup has none.\nfunction placedAt(crash: AttributedCrash): BoundaryInfo | null {\n const { el, ops } = crash;\n const at = ops.locate(el);\n if (at || !el.isConnected) return at;\n const owner = ops.owner(el);\n return owner && !owner.contains(el) ? ops.locate(owner) : null;\n}\n\n// A delivery earlier in the resolution can hide it. A nearest boundary still\n// free takes it, though an ancestor hides both, as it would a crash placed there.\nfunction partOfShown(\n crash: AttributedCrash,\n nearest: BoundaryInfo | null\n): boolean {\n return crash.ops.hidden(crash.el) && (!nearest || showsError(nearest));\n}\n\n// As `setBoundaryError` decides: by the signal, which a `batch()` sets before\n// the boundary's effect updates `isActive`.\nfunction showsError(boundary: BoundaryInfo): boolean {\n return untrack(() => boundary.errorSignal()) !== null;\n}\n\n/**\n * Hands a crash to the first boundary from `from` outward that is not already\n * showing an error, as `setBoundaryError` escalates a crash placed there. One\n * that reaches a boundary showing an error from this resolution is part of it.\n */\nfunction deliver(\n crash: AttributedCrash,\n from: BoundaryInfo | null,\n handled: Set<BoundaryInfo>\n): void {\n for (let at = from; at; at = crash.ops.parent(at)) {\n if (handled.has(at)) {\n logCrash(crash);\n return;\n }\n if (showsError(at)) continue;\n let accepted = false;\n try {\n accepted = crash.ops.settle(crash.el, crash.tag, crash.error, at);\n } catch (err) {\n // An effect of the boundary threw; the crash is settled only if it took it.\n if (!showsError(at)) reportResolveFailure([crash], err);\n else console.error('❌ Resolving a component crash failed:', err);\n handled.add(at);\n return;\n }\n if (accepted) {\n handled.add(at);\n crash.onCaptured?.();\n } else logCrash(crash);\n return;\n }\n unhandled(crash);\n}\n\n/**\n * Before a component inside a boundary's fallback renders in a static render,\n * that boundary takes its crashes, so content the component renders from the\n * error (text is bound once there) has it.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"resolveBeforeFallback\",\"stability\":\"internal\",\"signature\":\"(el: Element) => void\"} */\nexport function resolveBeforeFallback(el: Element): void {\n if (!isSSRMode() || !heldCrashes()?.length) return;\n const owner = el.closest('[data-fallback]')?.closest('[data-error]');\n if (owner) resolveAttributedCrashes('render', owner);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ssrCrashes.js","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,GAEZ,MAAM,2BAA2B,CAAC;AAcnC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,aAAa;IACpB,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;IACzB,OAAO,CAAC,CAAC,CAAC,iBAAiB,KAAnB,CAAC,CAAC,iBAAiB,GAAK,IAAI,GAAG,EAAE,EAAiC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,+IAA+I;AAC/I,MAAM,UAAU,mBAAmB,CAAC,EAAW;IAC7C,aAAa,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,oBAAoB,CAAC,EAAW,EAAE,GAAW,EAAE,KAAc;IACpE,aAAa,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE;QACtB,EAAE;QACF,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B,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC;YACH,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,4EAA4E;YAC5E,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBAAE,oBAAoB,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;;gBACnD,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;YACjE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QACD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;QACvB,CAAC;;YAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IACD,SAAS,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,iJAAiJ;AACjJ,MAAM,UAAU,qBAAqB,CAAC,EAAW;IAC/C,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,MAAM;QAAE,OAAO;IACnD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACrE,IAAI,KAAK;QAAE,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.ssr-crashes\",\n \"title\": \"SSR Unhandled Component Crash Collector\",\n \"category\": \"runtime\",\n \"risk\": \"high\"\n}\n*/\n\nimport { untrack } from '@pithyjs/signals';\nimport { pithyGlobals } from '../types/globals';\nimport { isSSRMode } from './ssrMode';\nimport {\n boundaryContext,\n findParentBoundary,\n inOwnFallback,\n inBranch,\n isInHiddenContent,\n registeredClosest,\n setBoundaryError,\n slotOwnerOf,\n type BoundaryInfo,\n} from './binds/bindErrorBoundary';\n\n/**\n * A component render crash recorded during a static/server render.\n */\nexport interface SSRRenderCrash {\n /** The custom-element placeholder the crashed component was to replace. */\n el: Element;\n /** Authored tag name, for the failure message. */\n tag: string;\n /** The error the component threw. */\n error: Error;\n}\n\n/**\n * Crashes recorded during the current server render, keyed by the placeholder\n * element so a later binding pass over the same element can retract its own\n * earlier record (see `clearSSRRenderCrash`).\n *\n * Held on `globalThis`, not in this module. `@pithyjs/ssr` depends on\n * `@pithyjs/core` as a regular dependency, so an app and the SSR package can\n * resolve two physical copies: `html()` would record into the app's copy while\n * `renderToString()` collected and reset the SSR package's, reintroducing\n * BUG-018 *and* leaking the app copy's DOM records for the life of the process.\n * The same reasoning already puts `__PITHY_SSR__` and `__getComponentContext`\n * on this bridge.\n *\n * A `Map` (not a `WeakMap`) because the collector must be enumerable at flush\n * time. `resetSSRRenderCrashes()` is what keeps it from retaining DOM across\n * renders — the SSR renderer calls it in a `finally`.\n */\nfunction crashRegistry(): Map<Element, SSRRenderCrash> {\n const g = pithyGlobals();\n return (g.__pithySSRCrashes ??= new Map()) as Map<Element, SSRRenderCrash>;\n}\n\n/**\n * Forget any crash previously recorded for `el`.\n *\n * Called only at points where the record is provably no longer the outcome, and\n * NEVER before invoking a component. Retracting eagerly at the top of an attempt\n * hides a failed retry: a component that throws detached and then returns\n * something unusable would have its only record erased, shipping a page with a\n * missing subtree and a green build. The three call sites are:\n *\n * 1. A boundary ACCEPTING the error (`setBoundaryError()` returning `true`).\n * A boundary merely being in scope is not enough — an already-active one\n * with no free ancestor rejects the error, and that is as unhandled as\n * having no boundary at all.\n * 2. A component returning a usable node that then successfully reaches the\n * document, i.e. after `replaceWith` has not thrown.\n * 3. An element that has left the tree being bound (`scope.contains(el)` in\n * `bindComponentTags`, `fragment.contains(el)` in `applyBindings`). It can\n * no longer contribute to the output, so any record for it is stale.\n *\n * Every one of these is mutation-tested; removing any of them turns a correct\n * render into a failed route, or a broken one into a silent success.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"clearSSRRenderCrash\",\"stability\":\"internal\",\"signature\":\"(el: Element) => void\"} */\nexport function clearSSRRenderCrash(el: Element): void {\n crashRegistry().delete(el);\n}\n\n/**\n * Record a component failure that no error boundary took ownership of.\n *\n * The precondition is **not** \"no boundary was in scope\". It is that no boundary\n * ACCEPTED the error, which is a strictly weaker thing: `setBoundaryError()`\n * rejects an error when the nearest boundary is already showing one and no\n * ancestor is free, and both binders call this on that path with a boundary\n * very much present. Getting the two confused is what this whole module exists\n * to prevent.\n *\n * Nor is \"crash\" limited to a thrown error. The binders also record a component\n * that returned an unusable result, and one whose rendered node failed to reach\n * the document — both leave the raw tag exactly where a throw would, which is\n * the same content loss from the page's point of view.\n *\n * Callers must have established `isSSRMode()` themselves; this does not\n * re-check.\n */\nfunction recordSSRRenderCrash(el: Element, tag: string, error: unknown): void {\n crashRegistry().set(el, {\n el,\n tag,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n}\n\n/**\n * Drop every recorded crash. Called by the SSR renderer before a render starts\n * and again in its `finally`, so one route's crash can never fail the next.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"resetSSRRenderCrashes\",\"stability\":\"stable\",\"signature\":\"() => void\"} */\nexport function resetSSRRenderCrashes(): void {\n crashRegistry().clear();\n const g = pithyGlobals();\n g.__pithyAttributedCrashes = [];\n g.__pithyRenderDepth = 0;\n}\n\n/**\n * An element that left the tree being bound contributes nothing to the output:\n * its recorded crash is stale, and an attributed one is only logged.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"forgetCrash\",\"stability\":\"internal\",\"signature\":\"(el: Element) => void\"} */\nexport function forgetCrash(el: Element): void {\n clearSSRRenderCrash(el);\n const crash = takeAttributedCrash(el);\n if (crash) logCrash(crash);\n}\n\nfunction takeAttributedCrash(el: Element): AttributedCrash | undefined {\n const list = heldCrashes();\n const at = list?.findIndex(crash => crash.el === el) ?? -1;\n return at >= 0 ? list?.splice(at, 1)[0] : undefined;\n}\n\n/**\n * Return the crashes still recorded once the render has finished, and empty\n * the collector.\n *\n * Every surviving record is a failure. A record is only ever retracted by\n * `clearSSRRenderCrash`, i.e. by a genuine re-attempt at the same element that\n * then went better — never by inspecting the finished tree.\n *\n * An earlier draft re-resolved each record's boundary here, dropping any crash\n * whose element had ended up inside an `@error-boundary`. That is unsound,\n * because a boundary *existing* above an element is not the same as that\n * boundary having *handled* the crash. A crash that a boundary rejected, or\n * that ran where no boundary resolved, is placed under one afterwards just the\n * same. Re-resolution dropped such a record: the boundary signal stayed null,\n * its fallback never activated, the raw component tag shipped, and the build\n * went green — the exact BUG-018 symptom, reintroduced by its own fix.\n *\n * A crash in a branch, slot or component built detached is attributed to its\n * boundary instead (`deferCrash`); whatever is still attributed here is\n * recorded.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"collectUnhandledSSRRenderCrashes\",\"stability\":\"stable\",\"signature\":\"() => SSRRenderCrash[]\"} */\nexport function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[] {\n resolveAttributedCrashes('collect');\n const registry = crashRegistry();\n const unhandled = [...registry.values()];\n registry.clear();\n return unhandled;\n}\n\n/**\n * Hand a component failure to its `@error-boundary`, or record it if none takes\n * it. Returns whether a boundary accepted ownership.\n *\n * The single funnel for every way a component can fail to produce content: a\n * thrown error, an unusable return value, and a rendered node that never reached\n * the document. They were handled in five separate places and drifted — the\n * throw paths consulted the boundary while the malformed paths recorded\n * directly, so a component under `@error-boundary` that returned garbage left\n * the boundary signal null, rendered no fallback, and failed the route, even\n * though the code called it \"the same content loss as a crash\".\n *\n * With no `boundary`, a failure in a branch, slot or component built detached\n * is attributed to the boundary its render sits under (`deferCrash`) and counts\n * as handled here; `attribution` says how it is logged if no boundary takes it.\n *\n * Callers still do their own logging, since the wording differs per failure.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"reportComponentFailure\",\"stability\":\"internal\",\"signature\":\"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null, attribution?: Attribution) => boolean\"} */\nexport function reportComponentFailure(\n el: Element,\n tag: string,\n error: Error,\n boundary: BoundaryInfo | null,\n attribution: Attribution = {}\n): boolean {\n if (!boundary && deferCrash(el, tag, error, attribution)) return true;\n return settleFailure(el, tag, error, boundary, attribution);\n}\n\n/** How an attributed crash is logged: `message` if no boundary takes it, `onCaptured` if one does. */\nexport interface Attribution {\n message?: string | null;\n onCaptured?: () => void;\n}\n\nfunction settleFailure(\n el: Element,\n tag: string,\n error: Error,\n boundary: BoundaryInfo | null,\n attribution: Attribution = {}\n): boolean {\n while (boundary && inOwnFallback(boundary, el)) {\n const from: BoundaryInfo = boundary;\n boundary = findParentBoundary(from);\n if (\n !boundary &&\n !from.element.isConnected &&\n deferCrash(el, tag, error, attribution)\n )\n return true;\n }\n // A boundary in scope is not a boundary that accepted: an already-active one\n // with no free ancestor rejects, and that is as unhandled as having none.\n const accepted = boundary ? setBoundaryError(boundary, error) : false;\n\n if (isSSRMode()) {\n if (accepted || isInHiddenContent(el)) clearSSRRenderCrash(el);\n else recordSSRRenderCrash(el, tag, error);\n }\n\n return accepted;\n}\n\n/** A crash raised where no boundary was reachable, owned by the boundary its render sat under. */\ninterface AttributedCrash extends SSRRenderCrash {\n /** The boundary the branch, slot or component was built for: the crash waits until it is inside. */\n boundaryEl: Element;\n message: string | null;\n onCaptured?: () => void;\n ops: CrashOps;\n /** The outermost render it was attributed in; `0` outside any. */\n render: number;\n}\n\n/** The copy of core that attributed a crash answers these, against its own boundaries. */\ninterface CrashOps {\n locate: (el: Element) => BoundaryInfo | null;\n owner: (node: Node) => Element | null;\n hidden: (node: Node) => boolean;\n parent: (boundary: BoundaryInfo) => BoundaryInfo | null;\n ownFallback: (boundary: BoundaryInfo, el: Element) => boolean;\n settle: typeof settleFailure;\n}\n\nconst ops: CrashOps = {\n locate: registeredClosest,\n owner: slotOwnerOf,\n hidden: isInHiddenContent,\n parent: findParentBoundary,\n ownFallback: inOwnFallback,\n settle: settleFailure,\n};\n\nlet taskEndQueued = false;\n\n// A crash that is neither in place nor hidden when a render ends may belong to\n// content its caller inserts right after (a slot rendered from an effect): it\n// waits once, to the end of the task, before it is reported.\nfunction resolveAtTaskEnd(): void {\n if (taskEndQueued) return;\n taskEndQueued = true;\n queueMicrotask(() => {\n taskEndQueued = false;\n resolveAttributedCrashes('task');\n });\n}\n\n// Shared on `globalThis` for the reason the registry is: a second copy of core\n// must neither miss these nor resolve them in the middle of a render.\n\nfunction heldCrashes(): AttributedCrash[] | undefined {\n return pithyGlobals().__pithyAttributedCrashes as\n | AttributedCrash[]\n | undefined;\n}\n\nfunction renderDepth(change = 0): number {\n const g = pithyGlobals();\n return (g.__pithyRenderDepth = (g.__pithyRenderDepth ?? 0) + change);\n}\n\nfunction currentRender(): number {\n return renderDepth() > 0 ? (pithyGlobals().__pithyRenderId ?? 0) : 0;\n}\n\nfunction crashedElements(): WeakSet<Element> {\n const g = pithyGlobals();\n return (g.__pithyCrashedElements ??= new WeakSet()) as WeakSet<Element>;\n}\n\n/** Whether `el` crashed and was attributed; a retry would run its setup twice, which a build never does. */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"hasCrashed\",\"stability\":\"internal\",\"signature\":\"(el: Element) => boolean\"} */\nexport function hasCrashed(el: Element): boolean {\n return crashedElements().has(el);\n}\n\n/**\n * Brackets a render transaction: a template bind, or one structural update\n * that builds a branch and inserts it. Attributed crashes are resolved when the\n * outermost one ends, so a boundary hides its content only once everything in\n * it is bound and in place.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"withinRender\",\"stability\":\"internal\",\"signature\":\"<T>(fn: () => T) => T\"} */\nexport function withinRender<T>(fn: () => T): T {\n const g = pithyGlobals();\n if (renderDepth() === 0) g.__pithyRenderId = (g.__pithyRenderId ?? 0) + 1;\n const render = g.__pithyRenderId ?? 0;\n renderDepth(1);\n let failed = false;\n try {\n return fn();\n } catch (err) {\n failed = true;\n throw err;\n } finally {\n renderDepth(-1);\n // Never throws, so a failed render keeps its own error. Its caller disposes\n // what it bound, boundaries included, so its own crashes are only reported.\n if (failed && renderDepth() === 0) reportCrashesOf(render);\n else resolveAttributedCrashes();\n }\n}\n\nfunction branchFailures(): WeakSet<Element> {\n const g = pithyGlobals();\n return (g.__pithyBranchFailures ??= new WeakSet()) as WeakSet<Element>;\n}\n\n/** Logs a component failure, and marks `el` when it failed in a branch. */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"logFailure\",\"stability\":\"internal\",\"signature\":\"(el: Element, log: () => void) => void\"} */\nexport function logFailure(el: Element, log: () => void): void {\n if (inBranch()) branchFailures().add(el);\n log();\n}\n\n/** Whether `el` failed while its branch was built; the pass that binds the inserted branch would retry it (BUG-161). */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"failedInBranch\",\"stability\":\"internal\",\"signature\":\"(el: Element) => boolean\"} */\nexport function failedInBranch(el: Element): boolean {\n return branchFailures().has(el);\n}\n\n/**\n * Attributes a crash that reached no boundary through the DOM to the boundary\n * its render sits under (`boundaryContext`): a branch, slot or component built\n * detached. Returns `false` with no such context, so the caller handles the\n * crash as before.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"deferCrash\",\"stability\":\"internal\",\"signature\":\"(el: Element, tag: string, error: Error, attribution?: Attribution) => boolean\"} */\nexport function deferCrash(\n el: Element,\n tag: string,\n error: Error,\n { message = null, onCaptured }: Attribution = {}\n): boolean {\n const boundaryEl = boundaryContext();\n if (!boundaryEl) return false;\n crashedElements().add(el);\n takeAttributedCrash(el);\n (pithyGlobals().__pithyAttributedCrashes ??= []).push({\n el,\n tag,\n error,\n boundaryEl,\n message,\n onCaptured,\n ops,\n render: currentRender(),\n });\n if (renderDepth() === 0) resolveAtTaskEnd();\n return true;\n}\n\nfunction hold(crash: AttributedCrash): void {\n (pithyGlobals().__pithyAttributedCrashes ??= []).push(crash);\n if (renderDepth() === 0) resolveAtTaskEnd();\n}\n\nfunction reportCrashesOf(render: number): void {\n const list = heldCrashes();\n if (!list?.length) return;\n for (const crash of list.splice(0)) {\n if (crash.render !== render) list.push(crash);\n else\n try {\n unhandled(crash);\n } catch (err) {\n reportResolveFailure([crash], err);\n }\n }\n}\n\nfunction logCrash(crash: AttributedCrash): void {\n if (crash.message) console.error(crash.message, crash.error);\n}\n\nfunction unhandled(crash: AttributedCrash): void {\n crash.ops.settle(crash.el, crash.tag, crash.error, null);\n logCrash(crash);\n}\n\n/**\n * Resolves attributed crashes once they are in place. Each goes to the nearest\n * registered boundary at its final position, exactly as a crash placed there\n * would, and within one resolution a boundary takes at most one error. In the\n * browser this waits for the\n * outermost render to end. A static render binds text once, so there the\n * component pass of the template that owns a boundary resolves its crashes\n * (`scope`), before that template's text is bound and after its components\n * ran. `task` runs at the end of the task; `collect` after the HTML is\n * serialized, and only records.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"resolveAttributedCrashes\",\"stability\":\"internal\",\"signature\":\"(mode?: 'render' | 'task' | 'collect', scope?: ParentNode) => void\"} */\nexport function resolveAttributedCrashes(\n mode: 'render' | 'task' | 'collect' = 'render',\n scope?: ParentNode\n): void {\n const list = heldCrashes();\n if (!list?.length) return;\n const midRender = mode === 'render' && renderDepth() > 0;\n if (midRender && (!scope || !isSSRMode())) return;\n const groups = new Map<BoundaryInfo, AttributedCrash[]>();\n const into = (boundary: BoundaryInfo, crash: AttributedCrash) => {\n const group = groups.get(boundary);\n if (group) group.push(crash);\n else groups.set(boundary, [crash]);\n };\n let waiting = false;\n for (const crash of list.splice(0)) {\n try {\n if (mode === 'collect') {\n unhandled(crash);\n continue;\n }\n if (midRender && !scope?.contains(crash.boundaryEl)) {\n list.push(crash);\n continue;\n }\n const target = placedAt(crash);\n if (partOfShown(crash, target)) {\n logCrash(crash);\n continue;\n }\n if (target) into(target, crash);\n // In its boundary with no registered one around it, or out of time.\n else if (\n mode === 'task' ||\n (!midRender && crash.boundaryEl.contains(crash.el))\n )\n unhandled(crash);\n else {\n // Not inserted yet: its caller may insert it right after.\n list.push(crash);\n waiting ||= !midRender;\n }\n } catch (err) {\n reportResolveFailure([crash], err);\n }\n }\n if (waiting) resolveAtTaskEnd();\n const innermostFirst = [...groups.entries()]\n .map(entry => ({ entry, depth: depthOf(entry[0].element) }))\n .sort((a, b) => b.depth - a.depth)\n .map(({ entry }) => entry);\n const run: Run = {\n groups,\n handled: new Set(),\n settled: new Set(),\n resolved: new Set(),\n final: mode === 'task',\n };\n for (const [boundary, group] of innermostFirst) {\n try {\n resolveGroup(boundary, group, run);\n } catch (err) {\n reportResolveFailure(group, err);\n }\n }\n}\n\nfunction reportResolveFailure(crashes: AttributedCrash[], err: unknown): void {\n for (const crash of crashes)\n if (isSSRMode()) recordSSRRenderCrash(crash.el, crash.tag, crash.error);\n console.error('❌ Resolving a component crash failed:', err);\n}\n\nfunction depthOf(node: Node): number {\n let depth = 0;\n for (let at = node.parentNode; at; at = at.parentNode) depth++;\n return depth;\n}\n\ninterface Run {\n groups: Map<BoundaryInfo, AttributedCrash[]>;\n handled: Set<BoundaryInfo>;\n settled: Set<BoundaryInfo>;\n resolved: Set<BoundaryInfo>;\n final: boolean;\n}\n\nfunction settleContent(boundary: BoundaryInfo, run: Run): void {\n if (run.settled.has(boundary)) return;\n run.settled.add(boundary);\n for (const [inner, group] of run.groups)\n if (\n inner !== boundary &&\n boundary.element.contains(inner.element) &&\n !boundary.fallbackElement?.contains(inner.element)\n )\n resolveGroup(inner, group, run);\n for (const crash of run.groups.get(boundary) ?? []) {\n if (boundary.fallbackElement?.contains(crash.el)) continue;\n if (partOfShown(crash, boundary)) logCrash(crash);\n else deliver(crash, boundary, run);\n }\n}\n\n/**\n * One boundary's crashes, content before fallback, so the outcome does not\n * depend on the order they happened in. Each is handled as a crash placed there\n * directly: a content crash goes to the boundary, a fallback crash further out.\n */\nfunction resolveGroup(\n boundary: BoundaryInfo,\n group: AttributedCrash[],\n run: Run\n): void {\n if (run.resolved.has(boundary)) return;\n run.resolved.add(boundary);\n settleContent(boundary, run);\n for (const crash of group) {\n if (!boundary.fallbackElement?.contains(crash.el)) continue;\n const outer = crash.ops.parent(boundary);\n if (!outer && !run.final && !boundary.element.isConnected) hold(crash);\n else if (partOfShown(crash, outsideOwnFallback(crash, outer)))\n logCrash(crash);\n else deliver(crash, outer, run);\n }\n}\n\nfunction outsideOwnFallback(\n crash: AttributedCrash,\n from: BoundaryInfo | null\n): BoundaryInfo | null {\n let at = from;\n while (at && crash.ops.ownFallback(at, crash.el)) at = crash.ops.parent(at);\n return at;\n}\n\n// Slot content a portal moves out of its boundary goes to that boundary, as a\n// component crash in it does through the slot frame. Only the nodes a slot\n// rendered carry an owner: a root a component mounts during setup has none.\nfunction placedAt(crash: AttributedCrash): BoundaryInfo | null {\n const { el, ops } = crash;\n const at = ops.locate(el);\n if (at || !el.isConnected) return at;\n const owner = ops.owner(el);\n return owner && !owner.contains(el) ? ops.locate(owner) : null;\n}\n\n// A delivery earlier in the resolution can hide it. A nearest boundary still\n// free takes it, though an ancestor hides both, as it would a crash placed there.\nfunction partOfShown(\n crash: AttributedCrash,\n nearest: BoundaryInfo | null\n): boolean {\n return crash.ops.hidden(crash.el) && (!nearest || showsError(nearest));\n}\n\n// As `setBoundaryError` decides: by the signal, which a `batch()` sets before\n// the boundary's effect updates `isActive`.\nfunction showsError(boundary: BoundaryInfo): boolean {\n return untrack(() => boundary.errorSignal()) !== null;\n}\n\n/**\n * Hands a crash to the first boundary from `from` outward that is not already\n * showing an error, as `setBoundaryError` escalates a crash placed there. One\n * that reaches a boundary showing an error from this resolution is part of it.\n */\nfunction deliver(\n crash: AttributedCrash,\n from: BoundaryInfo | null,\n run: Run\n): void {\n const { handled, final } = run;\n for (let at = from; at; at = crash.ops.parent(at)) {\n if (crash.ops.ownFallback(at, crash.el)) {\n if (!final && !at.element.isConnected && !crash.ops.parent(at)) {\n hold(crash);\n return;\n }\n settleContent(at, run);\n continue;\n }\n if (handled.has(at)) {\n logCrash(crash);\n return;\n }\n if (showsError(at)) continue;\n let accepted = false;\n try {\n accepted = crash.ops.settle(crash.el, crash.tag, crash.error, at);\n } catch (err) {\n // An effect of the boundary threw; the crash is settled only if it took it.\n if (!showsError(at)) reportResolveFailure([crash], err);\n else console.error('❌ Resolving a component crash failed:', err);\n handled.add(at);\n return;\n }\n if (accepted) {\n handled.add(at);\n crash.onCaptured?.();\n } else logCrash(crash);\n return;\n }\n unhandled(crash);\n}\n\n/**\n * Before a component inside a boundary's fallback renders in a static render,\n * that boundary takes its crashes, so content the component renders from the\n * error (text is bound once there) has it.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.ssr-crashes\",\"name\":\"resolveBeforeFallback\",\"stability\":\"internal\",\"signature\":\"(el: Element) => void\"} */\nexport function resolveBeforeFallback(el: Element): void {\n if (!isSSRMode() || !heldCrashes()?.length) return;\n const owner = el.closest('[data-fallback]')?.closest('[data-error]');\n if (owner) resolveAttributedCrashes('render', owner);\n}\n"]}
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { type Desc, type EventDesc, type InterpDesc, type ClassDesc, type ClassesDesc, type StyleDesc, type BoundDesc, type RefDesc, type BindDesc, type CompDesc, type DeferDesc, type ErrorDesc, type ProjDesc, type IfDesc, type ForDesc, type SwitchDesc } from './bindings/index.js';
|
|
9
9
|
export type { Desc, EventDesc, InterpDesc, ClassDesc, ClassesDesc, StyleDesc, BoundDesc, RefDesc, BindDesc, CompDesc, DeferDesc, ErrorDesc, ProjDesc, IfDesc, ForDesc, SwitchDesc, };
|
|
10
|
+
/**
|
|
11
|
+
* Marks a later `<slot>` of a name (`dup`). Generated code imports it, so a
|
|
12
|
+
* core older than the plugin fails to link instead of misplacing fallbacks.
|
|
13
|
+
*/
|
|
14
|
+
/** @codexApi {"parent":"pithy.runtime.apply-bindings","name":"__slotDup","stability":"internal","signature":"true"} */
|
|
15
|
+
export declare const __slotDup = true;
|
|
10
16
|
/**
|
|
11
17
|
* Applies pre-extracted binding descriptors to an AOT-generated DOM fragment.
|
|
12
18
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyBindings.d.ts","sourceRoot":"","sources":["../../src/runtime/applyBindings.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAWF,OAAO,EAsBL,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,IAAI,EACJ,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,GACX,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8RAA8R;AAC9R,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,IAAI,EAAE,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,oBAAoB,UAAO,GAC1B;IAAE,EAAE,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAI/C"}
|
|
1
|
+
{"version":3,"file":"applyBindings.d.ts","sourceRoot":"","sources":["../../src/runtime/applyBindings.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAWF,OAAO,EAsBL,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,IAAI,EACJ,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,GACX,CAAC;AAIF;;;GAGG;AACH,uHAAuH;AACvH,eAAO,MAAM,SAAS,OAAO,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8RAA8R;AAC9R,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,IAAI,EAAE,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,oBAAoB,UAAO,GAC1B;IAAE,EAAE,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAI/C"}
|
|
@@ -12,6 +12,12 @@ import { orderByDocument } from '../compile/disposeOrder.js';
|
|
|
12
12
|
import { executeCustomDirectiveBinders } from '../compile/binds/directiveRegistry.js';
|
|
13
13
|
import { buildPidMap, buildCommentMap, mergeContexts, nearestCtx, applyRef, applyError, markBoundary, applyProjection, applyComponent, applyBind, applyInterpolation, markSkeletonText, applyEvent, applyClass, applyClasses, applyStyle, applyBound, applyIf, applyFor, applySwitch, applyDefer, } from './bindings/index.js';
|
|
14
14
|
// ─── Main entry point ─────────────────────────────────────────────────────────
|
|
15
|
+
/**
|
|
16
|
+
* Marks a later `<slot>` of a name (`dup`). Generated code imports it, so a
|
|
17
|
+
* core older than the plugin fails to link instead of misplacing fallbacks.
|
|
18
|
+
*/
|
|
19
|
+
/** @codexApi {"parent":"pithy.runtime.apply-bindings","name":"__slotDup","stability":"internal","signature":"true"} */
|
|
20
|
+
export const __slotDup = true;
|
|
15
21
|
/**
|
|
16
22
|
* Applies pre-extracted binding descriptors to an AOT-generated DOM fragment.
|
|
17
23
|
*
|
|
@@ -111,6 +117,11 @@ function applyBindings(fragment, bindings, context, ownsDestroyCallbacks) {
|
|
|
111
117
|
// render left in place) is rendered through this hook, in the context it
|
|
112
118
|
// was written in.
|
|
113
119
|
const comps = (byType.get('comp') ?? []);
|
|
120
|
+
const boundOn = (pid) => import.meta.env?.DEV
|
|
121
|
+
? (byType.get('bound') ?? [])
|
|
122
|
+
.filter(b => b.pid === pid)
|
|
123
|
+
.map(b => b.attr)
|
|
124
|
+
: [];
|
|
114
125
|
const mounted = new Set();
|
|
115
126
|
const binds = new Map();
|
|
116
127
|
const live = new Map();
|
|
@@ -129,7 +140,7 @@ function applyBindings(fragment, bindings, context, ownsDestroyCallbacks) {
|
|
|
129
140
|
const failed = failedIn.get(d);
|
|
130
141
|
if (failed === true || (failed && el.parentNode === failed))
|
|
131
142
|
return [];
|
|
132
|
-
const nodes = applyComponent(d, el, ctx, slotDisposers, pidMap, scope);
|
|
143
|
+
const nodes = applyComponent(d, el, ctx, slotDisposers, pidMap, scope, boundOn(d.pid));
|
|
133
144
|
failedIn.set(d, nodes ? null : el.parentNode);
|
|
134
145
|
// On failure `pidMap` still holds the previous root.
|
|
135
146
|
const root = nodes && pidMap.get(d.pid);
|
|
@@ -175,7 +186,7 @@ function applyBindings(fragment, bindings, context, ownsDestroyCallbacks) {
|
|
|
175
186
|
// subtree: that calls `applyBindings` with the branch's OWN fragment as
|
|
176
187
|
// `fragment`, so its placeholders are inside it and still bind.
|
|
177
188
|
if (el && fragment.contains(el)) {
|
|
178
|
-
if (!applyComponent(d, el, ctx, disposers, pidMap))
|
|
189
|
+
if (!applyComponent(d, el, ctx, disposers, pidMap, undefined, boundOn(d.pid)))
|
|
179
190
|
failedIn.set(d, true);
|
|
180
191
|
binds.delete(d.pid);
|
|
181
192
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyBindings.js","sourceRoot":"","sources":["../../src/runtime/applyBindings.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,YAAY,GACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACV,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,UAAU,GAiBX,MAAM,YAAY,CAAC;AAsBpB,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8RAA8R;AAC9R,MAAM,UAAU,eAAe,CAC7B,QAA0B,EAC1B,QAAgB,EAChB,OAAgC,EAChC,oBAAoB,GAAG,IAAI;IAE3B,OAAO,YAAY,CAAC,GAAG,EAAE,CACvB,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,CAAC,CACjE,CAA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;oBACP,4BAA4B;gBAC9B,CAAC;YACH,CAAC;YACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACrB,8DAA8D;YAC9D,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtD,IAAI,CAAC;oBACH,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxB,CAAC;gBAAC,MAAM,CAAC;oBACP,4BAA4B;gBAC9B,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.apply-bindings\",\n \"title\": \"AOT Binding Applicator\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { drainDestroyCallbacks } from './onDestroy';\nimport {\n forgetCrash,\n resolveAttributedCrashes,\n withinRender,\n} from '../compile/ssrCrashes';\nimport { nodeExpando } from '../compile/nodeExpando';\nimport { orderByDocument } from '../compile/disposeOrder';\nimport { executeCustomDirectiveBinders } from '../compile/binds/directiveRegistry';\nimport {\n buildPidMap,\n buildCommentMap,\n mergeContexts,\n nearestCtx,\n applyRef,\n applyError,\n markBoundary,\n applyProjection,\n applyComponent,\n applyBind,\n applyInterpolation,\n markSkeletonText,\n applyEvent,\n applyClass,\n applyClasses,\n applyStyle,\n applyBound,\n applyIf,\n applyFor,\n applySwitch,\n applyDefer,\n type Desc,\n type EventDesc,\n type InterpDesc,\n type ClassDesc,\n type ClassesDesc,\n type StyleDesc,\n type BoundDesc,\n type RefDesc,\n type BindDesc,\n type CompDesc,\n type DeferDesc,\n type ErrorDesc,\n type ProjDesc,\n type IfDesc,\n type ForDesc,\n type SwitchDesc,\n} from './bindings';\n\n// Re-export types for external consumers\nexport type {\n Desc,\n EventDesc,\n InterpDesc,\n ClassDesc,\n ClassesDesc,\n StyleDesc,\n BoundDesc,\n RefDesc,\n BindDesc,\n CompDesc,\n DeferDesc,\n ErrorDesc,\n ProjDesc,\n IfDesc,\n ForDesc,\n SwitchDesc,\n};\n\n// ─── Main entry point ─────────────────────────────────────────────────────────\n\n/**\n * Applies pre-extracted binding descriptors to an AOT-generated DOM fragment.\n *\n * This is the Phase 5 runtime binder — the counterpart to the build-time\n * codegen (Phases 1-4). It processes descriptor arrays emitted by\n * generateDomFactory + generateBindings and wires reactive effects,\n * event handlers, component mounts, and structural directive logic.\n *\n * **Binding order** mirrors (but is not identical to) bindTemplateDirectives:\n * 1. Structural: switch → if → for\n * 2. Non-structural: ref → error → projection → component → bind →\n * interpolation → event → class → classes → style → bound attr →\n * custom directives → defer\n *\n * Differences from JIT bindTemplateDirectives:\n * - AOT has an explicit `style` phase (JIT folds inline styles into bound attrs)\n *\n * Custom directives (registered via `registerDirectiveBinder`, e.g. the\n * router's `@routerLink`) run even when `bindings` is empty: codegen emits no\n * descriptor for them, only the `data-*` marker attribute.\n *\n * @param fragment - DOM fragment created by the AOT factory function\n * @param bindings - Array of binding descriptors from codegen\n * @param context - Reactive context object with signals, methods, components\n */\n/** @codexApi {\"parent\":\"pithy.runtime.apply-bindings\",\"name\":\"__applyBindings\",\"stability\":\"experimental\",\"signature\":\"(fragment: DocumentFragment, bindings: Desc[], context: Record<string, unknown>, ownsDestroyCallbacks?: boolean) => { el: DocumentFragment; destroy: () => void }\"} */\nexport function __applyBindings(\n fragment: DocumentFragment,\n bindings: Desc[],\n context: Record<string, unknown>,\n ownsDestroyCallbacks = true\n): { el: DocumentFragment; destroy: () => void } {\n return withinRender(() =>\n applyBindings(fragment, bindings, context, ownsDestroyCallbacks)\n );\n}\n\nfunction applyBindings(\n fragment: DocumentFragment,\n bindings: Desc[],\n context: Record<string, unknown>,\n ownsDestroyCallbacks: boolean\n): { el: DocumentFragment; destroy: () => void } {\n // Drain onDestroy() callbacks BEFORE processing bindings — child components\n // instantiated during binding will drain their own callbacks independently.\n const destroyCallbacks = ownsDestroyCallbacks ? drainDestroyCallbacks() : [];\n\n const disposers: (() => void)[] = [];\n\n // Merge parent component + async (SSR) contexts — AOT factories bypass html().\n // Before the empty-bindings branch: custom binders must see the same context\n // whether or not the template also carries an ordinary descriptor.\n const ctx = mergeContexts(context);\n\n if (bindings.length === 0) {\n try {\n executeCustomDirectiveBinders(fragment, ctx, disposers);\n } catch (err) {\n unwind(disposers, destroyCallbacks);\n throw err;\n }\n return bindingsResult(fragment, disposers, destroyCallbacks);\n }\n\n if (bindings.some(d => d.t === 'interp')) markSkeletonText(fragment);\n\n // Build lookup maps\n const pidMap = buildPidMap(fragment);\n const commentMap = buildCommentMap(fragment);\n\n // Group descriptors by type for ordered processing\n const byType = new Map<string, Desc[]>();\n for (const d of bindings as Desc[]) {\n const list = byType.get(d.t) ?? [];\n list.push(d);\n byType.set(d.t, list);\n }\n\n try {\n // ─── Phase 1: Structural directives (shape-changing) ─────────────────\n // Order: switch → if → for (matches bindStructuralDirectives)\n\n // Marked, not registered: a branch built below must `closest()` its boundary.\n for (const d of (byType.get('error') ?? []) as ErrorDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) markBoundary(d, el);\n }\n\n for (const d of (byType.get('switch') ?? []) as SwitchDesc[]) {\n applySwitch(d, pidMap, ctx, disposers);\n }\n for (const d of (byType.get('if') ?? []) as IfDesc[]) {\n applyIf(d, commentMap, ctx, disposers);\n }\n for (const d of (byType.get('for') ?? []) as ForDesc[]) {\n applyFor(d, commentMap, ctx, disposers);\n }\n\n // ─── Phase 2: Non-structural bindings ────────────────────────────────\n // Order matches bindTemplateDirectives: ref → error → proj → comp →\n // bind → interp → event → class → classes → style → bound → defer\n\n for (const d of (byType.get('ref') ?? []) as RefDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyRef(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('error') ?? []) as ErrorDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyError(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('proj') ?? []) as ProjDesc[]) {\n applyProjection(d, commentMap, ctx, disposers);\n }\n\n // A placeholder that reaches a runtime-compiled component's binder (slot\n // content serialized into a descriptor without `slots`, or a failed\n // render left in place) is rendered through this hook, in the context it\n // was written in.\n const comps = (byType.get('comp') ?? []) as CompDesc[];\n const mounted = new Set<CompDesc>();\n // A hooked tag's forwarded bindings live on its latest root, owned by the\n // disposers of whoever rendered it, and are replayed on every mount.\n type Bind = (el: Element, ds: (() => void)[]) => void;\n const binds = new Map<string, Bind[]>();\n const live = new Map<string, { root: Element; ds: (() => void)[] }>();\n // A placeholder that failed stays put, and every enclosing slot's pass\n // finds it again; a re-mount moves it first. One this pass already\n // rendered is never retried (`true`).\n const failedIn = new Map<CompDesc, ParentNode | null | true>();\n for (const d of comps) {\n const el = pidMap.get(d.pid);\n if (!el) continue;\n const scope = nearestCtx(el, ctx);\n binds.set(d.pid, []);\n nodeExpando(el).__pithyAotMount = slotDisposers => {\n mounted.add(d);\n const failed = failedIn.get(d);\n if (failed === true || (failed && el.parentNode === failed)) return [];\n const nodes = applyComponent(d, el, ctx, slotDisposers, pidMap, scope);\n failedIn.set(d, nodes ? null : el.parentNode);\n // On failure `pidMap` still holds the previous root.\n const root = nodes && pidMap.get(d.pid);\n if (!nodes || !root) return nodes ?? [];\n const mount = { root, ds: slotDisposers };\n live.set(d.pid, mount);\n // A slot closed before a later binding is queued must not receive it.\n slotDisposers.push(() => {\n if (live.get(d.pid) === mount) live.delete(d.pid);\n });\n for (const bind of binds.get(d.pid) ?? []) bind(root, slotDisposers);\n return nodes;\n };\n }\n const forwarded = (pid: string, bind: Bind) => {\n const stored = binds.get(pid);\n const mount = live.get(pid);\n stored?.push(bind);\n if (mount) bind(mount.root, mount.ds);\n else if (!stored) {\n const el = pidMap.get(pid);\n if (el) bind(el, disposers);\n }\n };\n\n for (const d of comps) {\n if (mounted.has(d)) continue;\n const el = pidMap.get(d.pid);\n // `pidMap` is built once, up front. An activated `@error-boundary`\n // detaches its normal children, so a later sibling's placeholder can\n // still be in the map while no longer being in the tree. Rendering it is\n // pointless — and because it can no longer resolve the boundary that\n // already handled the failure, recording its crash would fail a route\n // whose fallback rendered perfectly well. Mirrors the `scope.contains(el)`\n // guard in `bindComponentTags`.\n //\n // This does not affect a structural branch factory binding a detached\n // subtree: that calls `applyBindings` with the branch's OWN fragment as\n // `fragment`, so its placeholders are inside it and still bind.\n if (el && fragment.contains(el)) {\n if (!applyComponent(d, el, ctx, disposers, pidMap))\n failedIn.set(d, true);\n binds.delete(d.pid);\n } else if (el) {\n // Left the tree, so it contributes nothing to the output — and any crash\n // recorded for it on an earlier detached pass is stale. Same reasoning\n // as the `scope.contains(el)` skip in `bindComponentTags`.\n forgetCrash(el);\n }\n }\n\n resolveAttributedCrashes('render', fragment);\n\n for (const d of (byType.get('bind') ?? []) as BindDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyBind(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('interp') ?? []) as InterpDesc[]) {\n // pid === '' means root-level text node (no parent element with data-pid)\n const el = d.pid === '' ? fragment : pidMap.get(d.pid);\n if (el) applyInterpolation(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('event') ?? []) as EventDesc[]) {\n forwarded(d.pid, (el, ds) => applyEvent(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('class') ?? []) as ClassDesc[]) {\n forwarded(d.pid, (el, ds) => applyClass(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('classes') ?? []) as ClassesDesc[]) {\n forwarded(d.pid, (el, ds) => applyClasses(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('style') ?? []) as StyleDesc[]) {\n forwarded(d.pid, (el, ds) => applyStyle(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('bound') ?? []) as BoundDesc[]) {\n forwarded(d.pid, (el, ds) => applyBound(d, el, ctx, ds));\n }\n\n executeCustomDirectiveBinders(fragment, ctx, disposers);\n\n for (const d of (byType.get('defer') ?? []) as DeferDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyDefer(d, el as HTMLElement, ctx, disposers);\n }\n orderByDocument(disposers);\n } catch (err) {\n unwind(disposers, destroyCallbacks);\n throw err;\n }\n\n return bindingsResult(fragment, disposers, destroyCallbacks);\n}\n\n/** Runs everything registered so far after a partial bind fails. */\nfunction unwind(\n disposers: (() => void)[],\n destroyCallbacks: (() => void)[]\n): void {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore */\n }\n }\n}\n\nfunction bindingsResult(\n fragment: DocumentFragment,\n disposers: (() => void)[],\n destroyCallbacks: (() => void)[]\n): { el: DocumentFragment; destroy: () => void } {\n return {\n el: fragment,\n destroy() {\n // Reverse order: child disposers (pushed later) run before parents\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore disposal errors */\n }\n }\n disposers.length = 0;\n // onDestroy callbacks in LIFO order, after template disposers\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore disposal errors */\n }\n }\n destroyCallbacks.length = 0;\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"applyBindings.js","sourceRoot":"","sources":["../../src/runtime/applyBindings.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,YAAY,GACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACV,QA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CAAC;oBACH,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxB,CAAC;gBAAC,MAAM,CAAC;oBACP,4BAA4B;gBAC9B,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.apply-bindings\",\n \"title\": \"AOT Binding Applicator\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { drainDestroyCallbacks } from './onDestroy';\nimport {\n forgetCrash,\n resolveAttributedCrashes,\n withinRender,\n} from '../compile/ssrCrashes';\nimport { nodeExpando } from '../compile/nodeExpando';\nimport { orderByDocument } from '../compile/disposeOrder';\nimport { executeCustomDirectiveBinders } from '../compile/binds/directiveRegistry';\nimport {\n buildPidMap,\n buildCommentMap,\n mergeContexts,\n nearestCtx,\n applyRef,\n applyError,\n markBoundary,\n applyProjection,\n applyComponent,\n applyBind,\n applyInterpolation,\n markSkeletonText,\n applyEvent,\n applyClass,\n applyClasses,\n applyStyle,\n applyBound,\n applyIf,\n applyFor,\n applySwitch,\n applyDefer,\n type Desc,\n type EventDesc,\n type InterpDesc,\n type ClassDesc,\n type ClassesDesc,\n type StyleDesc,\n type BoundDesc,\n type RefDesc,\n type BindDesc,\n type CompDesc,\n type DeferDesc,\n type ErrorDesc,\n type ProjDesc,\n type IfDesc,\n type ForDesc,\n type SwitchDesc,\n} from './bindings';\n\n// Re-export types for external consumers\nexport type {\n Desc,\n EventDesc,\n InterpDesc,\n ClassDesc,\n ClassesDesc,\n StyleDesc,\n BoundDesc,\n RefDesc,\n BindDesc,\n CompDesc,\n DeferDesc,\n ErrorDesc,\n ProjDesc,\n IfDesc,\n ForDesc,\n SwitchDesc,\n};\n\n// ─── Main entry point ─────────────────────────────────────────────────────────\n\n/**\n * Marks a later `<slot>` of a name (`dup`). Generated code imports it, so a\n * core older than the plugin fails to link instead of misplacing fallbacks.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.apply-bindings\",\"name\":\"__slotDup\",\"stability\":\"internal\",\"signature\":\"true\"} */\nexport const __slotDup = true;\n\n/**\n * Applies pre-extracted binding descriptors to an AOT-generated DOM fragment.\n *\n * This is the Phase 5 runtime binder — the counterpart to the build-time\n * codegen (Phases 1-4). It processes descriptor arrays emitted by\n * generateDomFactory + generateBindings and wires reactive effects,\n * event handlers, component mounts, and structural directive logic.\n *\n * **Binding order** mirrors (but is not identical to) bindTemplateDirectives:\n * 1. Structural: switch → if → for\n * 2. Non-structural: ref → error → projection → component → bind →\n * interpolation → event → class → classes → style → bound attr →\n * custom directives → defer\n *\n * Differences from JIT bindTemplateDirectives:\n * - AOT has an explicit `style` phase (JIT folds inline styles into bound attrs)\n *\n * Custom directives (registered via `registerDirectiveBinder`, e.g. the\n * router's `@routerLink`) run even when `bindings` is empty: codegen emits no\n * descriptor for them, only the `data-*` marker attribute.\n *\n * @param fragment - DOM fragment created by the AOT factory function\n * @param bindings - Array of binding descriptors from codegen\n * @param context - Reactive context object with signals, methods, components\n */\n/** @codexApi {\"parent\":\"pithy.runtime.apply-bindings\",\"name\":\"__applyBindings\",\"stability\":\"experimental\",\"signature\":\"(fragment: DocumentFragment, bindings: Desc[], context: Record<string, unknown>, ownsDestroyCallbacks?: boolean) => { el: DocumentFragment; destroy: () => void }\"} */\nexport function __applyBindings(\n fragment: DocumentFragment,\n bindings: Desc[],\n context: Record<string, unknown>,\n ownsDestroyCallbacks = true\n): { el: DocumentFragment; destroy: () => void } {\n return withinRender(() =>\n applyBindings(fragment, bindings, context, ownsDestroyCallbacks)\n );\n}\n\nfunction applyBindings(\n fragment: DocumentFragment,\n bindings: Desc[],\n context: Record<string, unknown>,\n ownsDestroyCallbacks: boolean\n): { el: DocumentFragment; destroy: () => void } {\n // Drain onDestroy() callbacks BEFORE processing bindings — child components\n // instantiated during binding will drain their own callbacks independently.\n const destroyCallbacks = ownsDestroyCallbacks ? drainDestroyCallbacks() : [];\n\n const disposers: (() => void)[] = [];\n\n // Merge parent component + async (SSR) contexts — AOT factories bypass html().\n // Before the empty-bindings branch: custom binders must see the same context\n // whether or not the template also carries an ordinary descriptor.\n const ctx = mergeContexts(context);\n\n if (bindings.length === 0) {\n try {\n executeCustomDirectiveBinders(fragment, ctx, disposers);\n } catch (err) {\n unwind(disposers, destroyCallbacks);\n throw err;\n }\n return bindingsResult(fragment, disposers, destroyCallbacks);\n }\n\n if (bindings.some(d => d.t === 'interp')) markSkeletonText(fragment);\n\n // Build lookup maps\n const pidMap = buildPidMap(fragment);\n const commentMap = buildCommentMap(fragment);\n\n // Group descriptors by type for ordered processing\n const byType = new Map<string, Desc[]>();\n for (const d of bindings as Desc[]) {\n const list = byType.get(d.t) ?? [];\n list.push(d);\n byType.set(d.t, list);\n }\n\n try {\n // ─── Phase 1: Structural directives (shape-changing) ─────────────────\n // Order: switch → if → for (matches bindStructuralDirectives)\n\n // Marked, not registered: a branch built below must `closest()` its boundary.\n for (const d of (byType.get('error') ?? []) as ErrorDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) markBoundary(d, el);\n }\n\n for (const d of (byType.get('switch') ?? []) as SwitchDesc[]) {\n applySwitch(d, pidMap, ctx, disposers);\n }\n for (const d of (byType.get('if') ?? []) as IfDesc[]) {\n applyIf(d, commentMap, ctx, disposers);\n }\n for (const d of (byType.get('for') ?? []) as ForDesc[]) {\n applyFor(d, commentMap, ctx, disposers);\n }\n\n // ─── Phase 2: Non-structural bindings ────────────────────────────────\n // Order matches bindTemplateDirectives: ref → error → proj → comp →\n // bind → interp → event → class → classes → style → bound → defer\n\n for (const d of (byType.get('ref') ?? []) as RefDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyRef(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('error') ?? []) as ErrorDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyError(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('proj') ?? []) as ProjDesc[]) {\n applyProjection(d, commentMap, ctx, disposers);\n }\n\n // A placeholder that reaches a runtime-compiled component's binder (slot\n // content serialized into a descriptor without `slots`, or a failed\n // render left in place) is rendered through this hook, in the context it\n // was written in.\n const comps = (byType.get('comp') ?? []) as CompDesc[];\n const boundOn = (pid: string) =>\n import.meta.env?.DEV\n ? ((byType.get('bound') ?? []) as BoundDesc[])\n .filter(b => b.pid === pid)\n .map(b => b.attr)\n : [];\n const mounted = new Set<CompDesc>();\n // A hooked tag's forwarded bindings live on its latest root, owned by the\n // disposers of whoever rendered it, and are replayed on every mount.\n type Bind = (el: Element, ds: (() => void)[]) => void;\n const binds = new Map<string, Bind[]>();\n const live = new Map<string, { root: Element; ds: (() => void)[] }>();\n // A placeholder that failed stays put, and every enclosing slot's pass\n // finds it again; a re-mount moves it first. One this pass already\n // rendered is never retried (`true`).\n const failedIn = new Map<CompDesc, ParentNode | null | true>();\n for (const d of comps) {\n const el = pidMap.get(d.pid);\n if (!el) continue;\n const scope = nearestCtx(el, ctx);\n binds.set(d.pid, []);\n nodeExpando(el).__pithyAotMount = slotDisposers => {\n mounted.add(d);\n const failed = failedIn.get(d);\n if (failed === true || (failed && el.parentNode === failed)) return [];\n const nodes = applyComponent(\n d,\n el,\n ctx,\n slotDisposers,\n pidMap,\n scope,\n boundOn(d.pid)\n );\n failedIn.set(d, nodes ? null : el.parentNode);\n // On failure `pidMap` still holds the previous root.\n const root = nodes && pidMap.get(d.pid);\n if (!nodes || !root) return nodes ?? [];\n const mount = { root, ds: slotDisposers };\n live.set(d.pid, mount);\n // A slot closed before a later binding is queued must not receive it.\n slotDisposers.push(() => {\n if (live.get(d.pid) === mount) live.delete(d.pid);\n });\n for (const bind of binds.get(d.pid) ?? []) bind(root, slotDisposers);\n return nodes;\n };\n }\n const forwarded = (pid: string, bind: Bind) => {\n const stored = binds.get(pid);\n const mount = live.get(pid);\n stored?.push(bind);\n if (mount) bind(mount.root, mount.ds);\n else if (!stored) {\n const el = pidMap.get(pid);\n if (el) bind(el, disposers);\n }\n };\n\n for (const d of comps) {\n if (mounted.has(d)) continue;\n const el = pidMap.get(d.pid);\n // `pidMap` is built once, up front. An activated `@error-boundary`\n // detaches its normal children, so a later sibling's placeholder can\n // still be in the map while no longer being in the tree. Rendering it is\n // pointless — and because it can no longer resolve the boundary that\n // already handled the failure, recording its crash would fail a route\n // whose fallback rendered perfectly well. Mirrors the `scope.contains(el)`\n // guard in `bindComponentTags`.\n //\n // This does not affect a structural branch factory binding a detached\n // subtree: that calls `applyBindings` with the branch's OWN fragment as\n // `fragment`, so its placeholders are inside it and still bind.\n if (el && fragment.contains(el)) {\n if (\n !applyComponent(\n d,\n el,\n ctx,\n disposers,\n pidMap,\n undefined,\n boundOn(d.pid)\n )\n )\n failedIn.set(d, true);\n binds.delete(d.pid);\n } else if (el) {\n // Left the tree, so it contributes nothing to the output — and any crash\n // recorded for it on an earlier detached pass is stale. Same reasoning\n // as the `scope.contains(el)` skip in `bindComponentTags`.\n forgetCrash(el);\n }\n }\n\n resolveAttributedCrashes('render', fragment);\n\n for (const d of (byType.get('bind') ?? []) as BindDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyBind(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('interp') ?? []) as InterpDesc[]) {\n // pid === '' means root-level text node (no parent element with data-pid)\n const el = d.pid === '' ? fragment : pidMap.get(d.pid);\n if (el) applyInterpolation(d, el, ctx, disposers);\n }\n\n for (const d of (byType.get('event') ?? []) as EventDesc[]) {\n forwarded(d.pid, (el, ds) => applyEvent(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('class') ?? []) as ClassDesc[]) {\n forwarded(d.pid, (el, ds) => applyClass(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('classes') ?? []) as ClassesDesc[]) {\n forwarded(d.pid, (el, ds) => applyClasses(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('style') ?? []) as StyleDesc[]) {\n forwarded(d.pid, (el, ds) => applyStyle(d, el, ctx, ds));\n }\n\n for (const d of (byType.get('bound') ?? []) as BoundDesc[]) {\n forwarded(d.pid, (el, ds) => applyBound(d, el, ctx, ds));\n }\n\n executeCustomDirectiveBinders(fragment, ctx, disposers);\n\n for (const d of (byType.get('defer') ?? []) as DeferDesc[]) {\n const el = pidMap.get(d.pid);\n if (el) applyDefer(d, el as HTMLElement, ctx, disposers);\n }\n orderByDocument(disposers);\n } catch (err) {\n unwind(disposers, destroyCallbacks);\n throw err;\n }\n\n return bindingsResult(fragment, disposers, destroyCallbacks);\n}\n\n/** Runs everything registered so far after a partial bind fails. */\nfunction unwind(\n disposers: (() => void)[],\n destroyCallbacks: (() => void)[]\n): void {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore */\n }\n }\n}\n\nfunction bindingsResult(\n fragment: DocumentFragment,\n disposers: (() => void)[],\n destroyCallbacks: (() => void)[]\n): { el: DocumentFragment; destroy: () => void } {\n return {\n el: fragment,\n destroy() {\n // Reverse order: child disposers (pushed later) run before parents\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore disposal errors */\n }\n }\n disposers.length = 0;\n // onDestroy callbacks in LIFO order, after template disposers\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore disposal errors */\n }\n }\n destroyCallbacks.length = 0;\n },\n };\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { CompDesc, BindingContext } from './types.js';
|
|
2
|
-
export declare function applyComponent(d: CompDesc, el: Element, ctx: BindingContext, disposers: (() => void)[], pidMap: Map<string, Element>, scope?: BindingContext
|
|
2
|
+
export declare function applyComponent(d: CompDesc, el: Element, ctx: BindingContext, disposers: (() => void)[], pidMap: Map<string, Element>, scope?: BindingContext,
|
|
3
|
+
/** The `[attr]` names on the tag; DEV only. */
|
|
4
|
+
bound?: string[]): Node[] | undefined;
|
|
3
5
|
//# sourceMappingURL=applyComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyComponent.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applyComponent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"applyComponent.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applyComponent.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAC;AAmJtE,wBAAgB,cAAc,CAC5B,CAAC,EAAE,QAAQ,EACX,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,EACzB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,KAAK,CAAC,EAAE,cAAc;AACtB,+CAA+C;AAC/C,KAAK,GAAE,MAAM,EAAO,GACnB,IAAI,EAAE,GAAG,SAAS,CAkQpB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compileExpression } from '../../compile/compileExpression.js';
|
|
2
2
|
import { boundaryForElement, replaceHidden, runWithBoundary, withSlotBoundary, slotContentHidden, } from '../../compile/binds/bindErrorBoundary.js';
|
|
3
|
-
import { linkOuterSlotMap, } from '../../compile/contentProjection.js';
|
|
3
|
+
import { linkOuterSlotMap, nameSlotMap, } from '../../compile/contentProjection.js';
|
|
4
4
|
import { collectForwardedAttrs, applyForwardedAttrs, } from '../../compile/binds/forwardedAttrs.js';
|
|
5
5
|
import { nativeTags } from '@pithyjs/compiler';
|
|
6
6
|
import { createRoot, untrack } from '@pithyjs/signals';
|
|
@@ -11,7 +11,8 @@ import { isSSRMode } from '../../compile/ssrMode.js';
|
|
|
11
11
|
import { isRenderableComponentEl } from '../../compile/componentResult.js';
|
|
12
12
|
import { clearSSRRenderCrash, reportComponentFailure, resolveBeforeFallback, } from '../../compile/ssrCrashes.js';
|
|
13
13
|
import { isolateDestroyCallbacks } from '../onDestroy.js';
|
|
14
|
-
import {
|
|
14
|
+
import { readPropNames } from '../../compile/binds/propNames.js';
|
|
15
|
+
import { warnBoundProps, warnUnexpectedProps, } from '../../compile/binds/propWarnings.js';
|
|
15
16
|
import { watchStaleRowProp } from '../../compile/binds/staleRowProps.js';
|
|
16
17
|
import { markForwardTarget, nodeExpando } from '../../compile/nodeExpando.js';
|
|
17
18
|
import { anchorDisposer, componentDisposer } from '../../compile/disposeOrder.js';
|
|
@@ -38,7 +39,7 @@ function extractExpectedPropNames(fn) {
|
|
|
38
39
|
if (cached)
|
|
39
40
|
return cached;
|
|
40
41
|
try {
|
|
41
|
-
const parsed =
|
|
42
|
+
const parsed = readPropNames(fn);
|
|
42
43
|
const names = parsed.fromParam ? parsed.names : [];
|
|
43
44
|
// Detect likely minification: single-char names suggest mangled output
|
|
44
45
|
if (import.meta.env?.DEV &&
|
|
@@ -115,7 +116,9 @@ function slotsFromChildren(el, slotMap) {
|
|
|
115
116
|
}
|
|
116
117
|
return injection;
|
|
117
118
|
}
|
|
118
|
-
export function applyComponent(d, el, ctx, disposers, pidMap, scope
|
|
119
|
+
export function applyComponent(d, el, ctx, disposers, pidMap, scope,
|
|
120
|
+
/** The `[attr]` names on the tag; DEV only. */
|
|
121
|
+
bound = []) {
|
|
119
122
|
// Skip native HTML elements — prevents <div> matching a `div` in context.
|
|
120
123
|
// Only apply when the authored tag is already lowercase; PascalCase tags like
|
|
121
124
|
// <Button> are valid components even though "button" is a native tag.
|
|
@@ -175,7 +178,14 @@ export function applyComponent(d, el, ctx, disposers, pidMap, scope) {
|
|
|
175
178
|
// Leave undefined — child uses defaults
|
|
176
179
|
}
|
|
177
180
|
}
|
|
181
|
+
if (import.meta.env?.DEV) {
|
|
182
|
+
const names = readPropNames(componentFn);
|
|
183
|
+
warnUnexpectedProps(names, props, d.tag);
|
|
184
|
+
warnBoundProps(names.names, bound, d.tag);
|
|
185
|
+
}
|
|
178
186
|
const slotMap = new Map();
|
|
187
|
+
if (import.meta.env?.DEV)
|
|
188
|
+
nameSlotMap(slotMap, d.tag, componentFn);
|
|
179
189
|
linkOuterSlotMap(slotMap, localCtx);
|
|
180
190
|
let injection;
|
|
181
191
|
if (d.slots) {
|