@pithyjs/core 0.1.0-beta.2 → 0.1.0-beta.21
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 +46 -8
- package/dist/a11y/focus-trap.d.ts +11 -3
- package/dist/a11y/focus-trap.d.ts.map +1 -1
- package/dist/a11y/focus-trap.js +55 -10
- package/dist/a11y/focus-trap.js.map +1 -1
- package/dist/a11y/index.d.ts +4 -4
- package/dist/a11y/index.js +4 -4
- package/dist/a11y/index.js.map +1 -1
- package/dist/a11y/keyboard-utils.js.map +1 -1
- package/dist/a11y/roving-tabindex.js.map +1 -1
- package/dist/a11y/skip-link.js.map +1 -1
- package/dist/compile/bindSwitchCases.d.ts +8 -3
- package/dist/compile/bindSwitchCases.d.ts.map +1 -1
- package/dist/compile/bindSwitchCases.js +137 -183
- package/dist/compile/bindSwitchCases.js.map +1 -1
- package/dist/compile/binds/bindAfterComponents.d.ts +4 -0
- package/dist/compile/binds/bindAfterComponents.d.ts.map +1 -0
- package/dist/compile/binds/bindAfterComponents.js +26 -0
- package/dist/compile/binds/bindAfterComponents.js.map +1 -0
- package/dist/compile/binds/bindAfterProjection.d.ts +7 -0
- package/dist/compile/binds/bindAfterProjection.d.ts.map +1 -0
- package/dist/compile/binds/bindAfterProjection.js +15 -0
- package/dist/compile/binds/bindAfterProjection.js.map +1 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts +8 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
- package/dist/compile/binds/bindBoundAttributes.js +227 -21
- package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
- package/dist/compile/binds/bindClassDirectives.d.ts +3 -2
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindClassDirectives.js +58 -21
- package/dist/compile/binds/bindClassDirectives.js.map +1 -1
- package/dist/compile/binds/bindComponentsTags.d.ts +2 -0
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +186 -74
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindConditionals.d.ts +2 -2
- package/dist/compile/binds/bindConditionals.d.ts.map +1 -1
- package/dist/compile/binds/bindConditionals.js +22 -5
- package/dist/compile/binds/bindConditionals.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.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.js +21 -19
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.d.ts +61 -0
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.js +272 -16
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
- package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -1
- package/dist/compile/binds/bindEventHandlers.js +15 -5
- package/dist/compile/binds/bindEventHandlers.js.map +1 -1
- package/dist/compile/binds/bindRefDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindRefDirectives.js +2 -1
- package/dist/compile/binds/bindRefDirectives.js.map +1 -1
- package/dist/compile/binds/bindStyleDirectives.d.ts +17 -0
- package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindStyleDirectives.js +48 -0
- package/dist/compile/binds/bindStyleDirectives.js.map +1 -0
- package/dist/compile/binds/bindTextInterpolations.d.ts +4 -2
- package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
- package/dist/compile/binds/bindTextInterpolations.js +87 -35
- package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
- package/dist/compile/binds/declaredDirective.d.ts +12 -0
- package/dist/compile/binds/declaredDirective.d.ts.map +1 -0
- package/dist/compile/binds/declaredDirective.js +42 -0
- package/dist/compile/binds/declaredDirective.js.map +1 -0
- package/dist/compile/binds/directiveRegistry.js.map +1 -1
- package/dist/compile/binds/forwardedAttrs.d.ts +4 -2
- package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -1
- package/dist/compile/binds/forwardedAttrs.js +10 -2
- package/dist/compile/binds/forwardedAttrs.js.map +1 -1
- package/dist/compile/binds/propNames.d.ts +14 -0
- package/dist/compile/binds/propNames.d.ts.map +1 -0
- package/dist/compile/binds/propNames.js +116 -0
- package/dist/compile/binds/propNames.js.map +1 -0
- package/dist/compile/binds/staleRowProps.d.ts +9 -0
- package/dist/compile/binds/staleRowProps.d.ts.map +1 -0
- package/dist/compile/binds/staleRowProps.js +86 -0
- package/dist/compile/binds/staleRowProps.js.map +1 -0
- package/dist/compile/compileExpression.js.map +1 -1
- package/dist/compile/compileNodes.d.ts.map +1 -1
- package/dist/compile/compileNodes.js +16 -7
- package/dist/compile/compileNodes.js.map +1 -1
- package/dist/compile/compileTemplate.d.ts +3 -4
- package/dist/compile/compileTemplate.d.ts.map +1 -1
- package/dist/compile/compileTemplate.js +36 -54
- package/dist/compile/compileTemplate.js.map +1 -1
- package/dist/compile/componentResult.js.map +1 -1
- package/dist/compile/contentProjection.d.ts +15 -3
- package/dist/compile/contentProjection.d.ts.map +1 -1
- package/dist/compile/contentProjection.js +90 -9
- package/dist/compile/contentProjection.js.map +1 -1
- package/dist/compile/disposeOrder.d.ts +35 -0
- package/dist/compile/disposeOrder.d.ts.map +1 -0
- package/dist/compile/disposeOrder.js +81 -0
- package/dist/compile/disposeOrder.js.map +1 -0
- package/dist/compile/evalDiagnostics.d.ts +7 -0
- package/dist/compile/evalDiagnostics.d.ts.map +1 -0
- package/dist/compile/evalDiagnostics.js +8 -0
- package/dist/compile/evalDiagnostics.js.map +1 -0
- package/dist/compile/forLoops/bindForLoops.d.ts +3 -3
- package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
- package/dist/compile/forLoops/bindForLoops.js +18 -13
- package/dist/compile/forLoops/bindForLoops.js.map +1 -1
- package/dist/compile/forLoops/createLoopManager.d.ts +3 -3
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
- package/dist/compile/forLoops/createLoopManager.js +44 -26
- package/dist/compile/forLoops/createLoopManager.js.map +1 -1
- package/dist/compile/forLoops/index.d.ts +5 -5
- package/dist/compile/forLoops/index.js +5 -5
- package/dist/compile/forLoops/index.js.map +1 -1
- package/dist/compile/forLoops/loopHelpers.js.map +1 -1
- package/dist/compile/forLoops/loopSignals.d.ts.map +1 -1
- package/dist/compile/forLoops/loopSignals.js +15 -1
- package/dist/compile/forLoops/loopSignals.js.map +1 -1
- package/dist/compile/forLoops/loopTraversal.js +2 -2
- package/dist/compile/forLoops/loopTraversal.js.map +1 -1
- package/dist/compile/handleConditionalChain.d.ts +2 -2
- package/dist/compile/handleConditionalChain.d.ts.map +1 -1
- package/dist/compile/handleConditionalChain.js +23 -89
- package/dist/compile/handleConditionalChain.js.map +1 -1
- package/dist/compile/index.d.ts +17 -17
- package/dist/compile/index.js +14 -14
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/injectScopedStyle.js.map +1 -1
- package/dist/compile/nodeExpando.d.ts +28 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -1
- package/dist/compile/nodeExpando.js +12 -0
- package/dist/compile/nodeExpando.js.map +1 -1
- package/dist/compile/parseHtml.js +12 -6
- package/dist/compile/parseHtml.js.map +1 -1
- package/dist/compile/pithyTreeToDom.d.ts.map +1 -1
- package/dist/compile/pithyTreeToDom.js +17 -12
- package/dist/compile/pithyTreeToDom.js.map +1 -1
- package/dist/compile/renderBranch.d.ts +13 -0
- package/dist/compile/renderBranch.d.ts.map +1 -0
- package/dist/compile/renderBranch.js +72 -0
- package/dist/compile/renderBranch.js.map +1 -0
- package/dist/compile/renderChildren.d.ts +12 -2
- package/dist/compile/renderChildren.d.ts.map +1 -1
- package/dist/compile/renderChildren.js +33 -4
- package/dist/compile/renderChildren.js.map +1 -1
- package/dist/compile/ssrCrashes.d.ts +65 -37
- package/dist/compile/ssrCrashes.d.ts.map +1 -1
- package/dist/compile/ssrCrashes.js +344 -39
- package/dist/compile/ssrCrashes.js.map +1 -1
- package/dist/compile/ssrMode.js +1 -1
- package/dist/compile/ssrMode.js.map +1 -1
- package/dist/compile/textValue.js.map +1 -1
- package/dist/compile/trimBlankEdges.d.ts +2 -0
- package/dist/compile/trimBlankEdges.d.ts.map +1 -0
- package/dist/compile/trimBlankEdges.js +15 -0
- package/dist/compile/trimBlankEdges.js.map +1 -0
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +2 -2
- package/dist/interfaces/index.js +2 -2
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/ref-signal.interface.js.map +1 -1
- package/dist/interfaces/ref.interface.js.map +1 -1
- package/dist/runtime/applyBindings.d.ts +9 -5
- package/dist/runtime/applyBindings.d.ts.map +1 -1
- package/dist/runtime/applyBindings.js +130 -43
- package/dist/runtime/applyBindings.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts +2 -2
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +143 -87
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applyDefer.d.ts +1 -1
- package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
- package/dist/runtime/bindings/applyDefer.js +16 -15
- package/dist/runtime/bindings/applyDefer.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts +10 -1
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +117 -46
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/dist/runtime/bindings/applyStructural.d.ts +1 -1
- package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
- package/dist/runtime/bindings/applyStructural.js +140 -124
- package/dist/runtime/bindings/applyStructural.js.map +1 -1
- package/dist/runtime/bindings/helpers.d.ts +8 -1
- package/dist/runtime/bindings/helpers.d.ts.map +1 -1
- package/dist/runtime/bindings/helpers.js +36 -2
- package/dist/runtime/bindings/helpers.js.map +1 -1
- package/dist/runtime/bindings/index.d.ts +6 -6
- package/dist/runtime/bindings/index.d.ts.map +1 -1
- package/dist/runtime/bindings/index.js +5 -5
- package/dist/runtime/bindings/index.js.map +1 -1
- package/dist/runtime/bindings/types.d.ts +2 -0
- package/dist/runtime/bindings/types.d.ts.map +1 -1
- package/dist/runtime/bindings/types.js.map +1 -1
- package/dist/runtime/bootstrap.d.ts +1 -1
- package/dist/runtime/bootstrap.js +1 -1
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/createContextProxy.js.map +1 -1
- package/dist/runtime/deferHelpers.d.ts +1 -1
- package/dist/runtime/deferHelpers.js.map +1 -1
- package/dist/runtime/html.js +7 -7
- package/dist/runtime/html.js.map +1 -1
- package/dist/runtime/index.d.ts +6 -6
- package/dist/runtime/index.js +6 -6
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/lazy.js +1 -1
- package/dist/runtime/lazy.js.map +1 -1
- package/dist/runtime/module-cache.js.map +1 -1
- package/dist/runtime/onDestroy.d.ts +7 -0
- package/dist/runtime/onDestroy.d.ts.map +1 -1
- package/dist/runtime/onDestroy.js +16 -1
- package/dist/runtime/onDestroy.js.map +1 -1
- package/dist/runtime/parseIdentifiersFromTemplate.js +1 -1
- package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -1
- package/dist/runtime/resource/createAction.d.ts +1 -1
- package/dist/runtime/resource/createAction.js +1 -1
- package/dist/runtime/resource/createAction.js.map +1 -1
- package/dist/runtime/resource/createResource.d.ts +1 -1
- package/dist/runtime/resource/createResource.d.ts.map +1 -1
- package/dist/runtime/resource/createResource.js +3 -4
- package/dist/runtime/resource/createResource.js.map +1 -1
- package/dist/runtime/resource/engine.d.ts +1 -1
- package/dist/runtime/resource/engine.js.map +1 -1
- package/dist/runtime/resource/index.d.ts +3 -3
- package/dist/runtime/resource/index.js +2 -2
- package/dist/runtime/resource/index.js.map +1 -1
- package/dist/runtime/resource/types.js.map +1 -1
- package/dist/types/globals.d.ts +10 -2
- package/dist/types/globals.d.ts.map +1 -1
- package/dist/types/globals.js.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/index.d.ts +2 -2
- package/dist/utilities/index.js +2 -2
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/ref-signal.utility.d.ts +1 -1
- package/dist/utilities/ref-signal.utility.js.map +1 -1
- package/dist/utilities/ref.untility.d.ts +1 -1
- package/dist/utilities/ref.untility.js.map +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createRoot } from '@pithyjs/signals';
|
|
2
|
+
import { bindConditionals } from './binds/bindConditionals.js';
|
|
3
|
+
import { withBranchBoundary } from './binds/bindErrorBoundary.js';
|
|
4
|
+
import { withinRender } from './ssrCrashes.js';
|
|
5
|
+
import { flashUpdate } from './binds/bindTextInterpolations.js';
|
|
6
|
+
import { bindSwitchBlock, bindSwitchCases } from './bindSwitchCases.js';
|
|
7
|
+
import { bindTemplateDirectives } from './compileTemplate.js';
|
|
8
|
+
import { bindForLoops } from './forLoops/bindForLoops.js';
|
|
9
|
+
import { orderByDocument } from './disposeOrder.js';
|
|
10
|
+
import { pithyTreeToDom } from './pithyTreeToDom.js';
|
|
11
|
+
import { isSSRMode } from './ssrMode.js';
|
|
12
|
+
/**
|
|
13
|
+
* Builds the DOM for one `@if` or `@case` branch from its AST, binds it, and
|
|
14
|
+
* inserts it after `anchor`.
|
|
15
|
+
*/
|
|
16
|
+
export function renderBranch(ast, ctx, anchor) {
|
|
17
|
+
return withinRender(() => buildBranch(ast, ctx, anchor));
|
|
18
|
+
}
|
|
19
|
+
function buildBranch(ast, ctx, anchor) {
|
|
20
|
+
const branch = { nodes: [], disposers: [] };
|
|
21
|
+
const rebuilt = pithyTreeToDom([ast], ctx).firstChild;
|
|
22
|
+
if (!rebuilt || !anchor.parentNode)
|
|
23
|
+
return branch;
|
|
24
|
+
// A component tag is replaced by what it renders while binding, so the
|
|
25
|
+
// fragment, not `rebuilt`, holds the nodes to insert and later remove.
|
|
26
|
+
const fragment = document.createDocumentFragment();
|
|
27
|
+
fragment.appendChild(rebuilt);
|
|
28
|
+
const children = ast.isComponent ? [] : ast.children || [];
|
|
29
|
+
const { disposers } = branch;
|
|
30
|
+
createRoot(disposeRoot => withBranchBoundary(anchor, () => {
|
|
31
|
+
disposers.push(disposeRoot);
|
|
32
|
+
const processed = new Set();
|
|
33
|
+
if (ast.directives?.switch !== undefined) {
|
|
34
|
+
bindSwitchBlock(ast, rebuilt, ctx, processed, disposers);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
bindSwitchCases(children, rebuilt, ctx, processed, disposers);
|
|
38
|
+
}
|
|
39
|
+
bindConditionals(children, rebuilt, ctx, processed, disposers);
|
|
40
|
+
bindForLoops(children, rebuilt, ctx, disposers, processed);
|
|
41
|
+
bindTemplateDirectives(fragment, ctx, disposers);
|
|
42
|
+
orderByDocument(disposers);
|
|
43
|
+
}));
|
|
44
|
+
branch.nodes = Array.from(fragment.childNodes);
|
|
45
|
+
anchor.parentNode.insertBefore(fragment, anchor.nextSibling);
|
|
46
|
+
if (!isSSRMode()) {
|
|
47
|
+
queueMicrotask(() => {
|
|
48
|
+
for (const node of branch.nodes) {
|
|
49
|
+
if (node.nodeType === Node.ELEMENT_NODE)
|
|
50
|
+
flashUpdate(node);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return branch;
|
|
55
|
+
}
|
|
56
|
+
/** Disposes a branch's effects, last registered first, then removes its nodes. */
|
|
57
|
+
export function clearBranch(branch) {
|
|
58
|
+
for (let i = branch.disposers.length - 1; i >= 0; i--) {
|
|
59
|
+
try {
|
|
60
|
+
branch.disposers[i]();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
/* ignore */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
branch.disposers = [];
|
|
67
|
+
for (const node of branch.nodes) {
|
|
68
|
+
node.parentNode?.removeChild(node);
|
|
69
|
+
}
|
|
70
|
+
branch.nodes = [];
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=renderBranch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderBranch.js","sourceRoot":"","sources":["../../src/compile/renderBranch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAc,EACd,GAA4B,EAC5B,MAAY;IAEZ,OAAO,YAAY,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,WAAW,CAClB,GAAc,EACd,GAA4B,EAC5B,MAAY;IAEZ,MAAM,MAAM,GAAW,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACp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;IAEF,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAE7D,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,cAAc,CAAC,GAAG,EAAE;YAClB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBAChC,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY;oBAAE,WAAW,CAAC,IAAe,CAAC,CAAC;YACxE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACtD,IAAI,CAAC;YACH,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;IACD,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import type { PithyNode } from '@pithyjs/compiler';\nimport { createRoot } from '@pithyjs/signals';\nimport { bindConditionals } from './binds/bindConditionals';\nimport { withBranchBoundary } from './binds/bindErrorBoundary';\nimport { withinRender } from './ssrCrashes';\nimport { flashUpdate } from './binds/bindTextInterpolations';\nimport { bindSwitchBlock, bindSwitchCases } from './bindSwitchCases';\nimport { bindTemplateDirectives } from './compileTemplate';\nimport { bindForLoops } from './forLoops/bindForLoops';\nimport { orderByDocument } from './disposeOrder';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { isSSRMode } from './ssrMode';\n\nexport interface Branch {\n nodes: Node[];\n disposers: (() => void)[];\n}\n\n/**\n * Builds the DOM for one `@if` or `@case` branch from its AST, binds it, and\n * inserts it after `anchor`.\n */\nexport function renderBranch(\n ast: PithyNode,\n ctx: Record<string, unknown>,\n anchor: Node\n): Branch {\n return withinRender(() => buildBranch(ast, ctx, anchor));\n}\n\nfunction buildBranch(\n ast: PithyNode,\n ctx: Record<string, unknown>,\n anchor: Node\n): Branch {\n const branch: Branch = { nodes: [], disposers: [] };\n const rebuilt = pithyTreeToDom([ast], ctx).firstChild as Element | null;\n if (!rebuilt || !anchor.parentNode) return branch;\n\n // A component tag is replaced by what it renders while binding, so the\n // fragment, not `rebuilt`, holds the nodes to insert and later remove.\n const fragment = document.createDocumentFragment();\n fragment.appendChild(rebuilt);\n const children = ast.isComponent ? [] : ast.children || [];\n const { disposers } = branch;\n\n createRoot(disposeRoot =>\n withBranchBoundary(anchor, () => {\n disposers.push(disposeRoot);\n const processed = new Set<string>();\n if (ast.directives?.switch !== undefined) {\n bindSwitchBlock(ast, rebuilt, ctx, processed, disposers);\n } else {\n bindSwitchCases(children, rebuilt, ctx, processed, disposers);\n }\n bindConditionals(children, rebuilt, ctx, processed, disposers);\n bindForLoops(children, rebuilt, ctx, disposers, processed);\n bindTemplateDirectives(fragment, ctx, disposers);\n orderByDocument(disposers);\n })\n );\n\n branch.nodes = Array.from(fragment.childNodes);\n anchor.parentNode.insertBefore(fragment, anchor.nextSibling);\n\n if (!isSSRMode()) {\n queueMicrotask(() => {\n for (const node of branch.nodes) {\n if (node.nodeType === Node.ELEMENT_NODE) flashUpdate(node as Element);\n }\n });\n }\n return branch;\n}\n\n/** Disposes a branch's effects, last registered first, then removes its nodes. */\nexport function clearBranch(branch: Branch): void {\n for (let i = branch.disposers.length - 1; i >= 0; i--) {\n try {\n branch.disposers[i]();\n } catch {\n /* ignore */\n }\n }\n branch.disposers = [];\n for (const node of branch.nodes) {\n node.parentNode?.removeChild(node);\n }\n branch.nodes = [];\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PithyNode } from '@pithyjs/compiler';
|
|
2
|
-
import { type PithyComponentContext } from '../types/globals';
|
|
3
|
-
import type { ChildFactory } from '../runtime/bindings/types';
|
|
2
|
+
import { type PithyComponentContext } from '../types/globals.js';
|
|
3
|
+
import type { ChildFactory } from '../runtime/bindings/types.js';
|
|
4
|
+
import { type SlotMap } from './contentProjection.js';
|
|
5
|
+
type SlotRenderer = NonNullable<ReturnType<SlotMap['get']>>;
|
|
4
6
|
/**
|
|
5
7
|
* If the registry renderer has set `globalThis.__pithyProjectedChildren` (a
|
|
6
8
|
* `DocumentFragment` of already-rendered slot children), returns and clears it —
|
|
@@ -8,6 +10,8 @@ import type { ChildFactory } from '../runtime/bindings/types';
|
|
|
8
10
|
* children on the registry path. The registry path has no AST fallback, so a
|
|
9
11
|
* second `renderChildren()`/`captureChildren()` call returns an empty fragment.
|
|
10
12
|
*
|
|
13
|
+
* A build-compiled parent's default slot is rendered afresh on every call.
|
|
14
|
+
*
|
|
11
15
|
* Otherwise compiles child AST nodes from the current component context through
|
|
12
16
|
* the full pipeline (structural + non-structural directives). This enables
|
|
13
17
|
* nested components inside projected content — unlike `<slot>`, which inserts
|
|
@@ -50,11 +54,16 @@ export declare function captureChildren(): {
|
|
|
50
54
|
el: DocumentFragment;
|
|
51
55
|
destroy: () => void;
|
|
52
56
|
};
|
|
57
|
+
/** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"ChildPayload","stability":"experimental","signature":"interface ChildPayload"} */
|
|
53
58
|
export interface ChildPayload {
|
|
54
59
|
context: PithyComponentContext | undefined;
|
|
55
60
|
factory?: ChildFactory;
|
|
56
61
|
astNodes?: PithyNode[];
|
|
57
62
|
projected?: DocumentFragment;
|
|
63
|
+
/** A build's default slot, rendered by `renderChildren()` on each call. */
|
|
64
|
+
slot?: SlotRenderer;
|
|
65
|
+
/** What a `<slot>` among `astNodes` receives. */
|
|
66
|
+
outer?: SlotMap;
|
|
58
67
|
}
|
|
59
68
|
/**
|
|
60
69
|
* Reads the children addressed to the component being rendered, without
|
|
@@ -64,4 +73,5 @@ export interface ChildPayload {
|
|
|
64
73
|
*/
|
|
65
74
|
/** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"readChildPayload","stability":"experimental","signature":"() => ChildPayload"} */
|
|
66
75
|
export declare function readChildPayload(): ChildPayload;
|
|
76
|
+
export {};
|
|
67
77
|
//# sourceMappingURL=renderChildren.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderChildren.d.ts","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAgB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"renderChildren.d.ts","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAgB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGjE,KAAK,YAAY,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,wKAAwK;AACxK,wBAAgB,cAAc,IAAI;IAChC,EAAE,EAAE,gBAAgB,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CA+CA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,yKAAyK;AACzK,wBAAgB,eAAe,IAAI;IACjC,EAAE,EAAE,gBAAgB,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CASA;AASD,+IAA+I;AAC/I,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC3C,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,2EAA2E;IAC3E,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,iDAAiD;IACjD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,+IAA+I;AAC/I,wBAAgB,gBAAgB,IAAI,YAAY,CAa/C"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { compileNodes } from './compileNodes';
|
|
2
|
-
import { pithyGlobals } from '../types/globals';
|
|
1
|
+
import { compileNodes } from './compileNodes.js';
|
|
2
|
+
import { pithyGlobals } from '../types/globals.js';
|
|
3
|
+
import { outerSlotMap } from './contentProjection.js';
|
|
4
|
+
import { withSlotBoundary } from './binds/bindErrorBoundary.js';
|
|
3
5
|
/**
|
|
4
6
|
* If the registry renderer has set `globalThis.__pithyProjectedChildren` (a
|
|
5
7
|
* `DocumentFragment` of already-rendered slot children), returns and clears it —
|
|
@@ -7,6 +9,8 @@ import { pithyGlobals } from '../types/globals';
|
|
|
7
9
|
* children on the registry path. The registry path has no AST fallback, so a
|
|
8
10
|
* second `renderChildren()`/`captureChildren()` call returns an empty fragment.
|
|
9
11
|
*
|
|
12
|
+
* A build-compiled parent's default slot is rendered afresh on every call.
|
|
13
|
+
*
|
|
10
14
|
* Otherwise compiles child AST nodes from the current component context through
|
|
11
15
|
* the full pipeline (structural + non-structural directives). This enables
|
|
12
16
|
* nested components inside projected content — unlike `<slot>`, which inserts
|
|
@@ -24,6 +28,19 @@ export function renderChildren() {
|
|
|
24
28
|
return { el: injected, destroy: () => { } };
|
|
25
29
|
}
|
|
26
30
|
const componentCtx = pithyGlobals().__pithyComponentContext;
|
|
31
|
+
const slot = buildDefaultSlot(componentCtx);
|
|
32
|
+
if (slot) {
|
|
33
|
+
const disposers = [];
|
|
34
|
+
const el = slot(disposers);
|
|
35
|
+
return {
|
|
36
|
+
el,
|
|
37
|
+
destroy: () => {
|
|
38
|
+
for (let i = disposers.length - 1; i >= 0; i--)
|
|
39
|
+
disposers[i]();
|
|
40
|
+
disposers.length = 0;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
27
44
|
// A parent composing atoms by direct call after captureChildren() cleared its
|
|
28
45
|
// context is still mid-render (`rendering` truthy) — not the misuse this guards
|
|
29
46
|
// against, so a consumed context alone must not trigger the warning.
|
|
@@ -34,9 +51,13 @@ export function renderChildren() {
|
|
|
34
51
|
const childAstNodes = componentCtx?.__childAstNodes ?? [];
|
|
35
52
|
// Strip internal __ properties, keep parent scope (includes components, signals, etc.)
|
|
36
53
|
const parentCtx = componentCtx
|
|
37
|
-
? Object.fromEntries(Object.entries(componentCtx).filter(([k]) => !k.startsWith('__')))
|
|
54
|
+
? Object.fromEntries(Object.entries(componentCtx).filter(([k]) => !k.startsWith('__') || k === '__pithyRowLocals'))
|
|
38
55
|
: {};
|
|
39
|
-
|
|
56
|
+
// What a `<slot>` among the children receives.
|
|
57
|
+
const outer = outerSlotMap(componentCtx?.__slotMap);
|
|
58
|
+
if (outer)
|
|
59
|
+
parentCtx.__slotMap = outer;
|
|
60
|
+
return withSlotBoundary(undefined, componentCtx?.__slotHost, () => compileNodes(childAstNodes, parentCtx));
|
|
40
61
|
}
|
|
41
62
|
/**
|
|
42
63
|
* Captures projected children and clears the component context so
|
|
@@ -73,6 +94,12 @@ export function captureChildren() {
|
|
|
73
94
|
g.__pithyComponentContext = prevCtx?.__parentComponentContext ?? undefined;
|
|
74
95
|
return result;
|
|
75
96
|
}
|
|
97
|
+
/** Default-slot renderer of a build-compiled parent; it has no AST. */
|
|
98
|
+
function buildDefaultSlot(ctx) {
|
|
99
|
+
return ctx && !ctx.__childAstNodes && !ctx.__childFactory
|
|
100
|
+
? ctx.__slotMap?.get('')
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
76
103
|
/**
|
|
77
104
|
* Reads the children addressed to the component being rendered, without
|
|
78
105
|
* consuming them. `factory` and `astNodes` are mutually exclusive: an AOT child
|
|
@@ -90,6 +117,8 @@ export function readChildPayload() {
|
|
|
90
117
|
factory,
|
|
91
118
|
astNodes: !factory && ast && ast.length > 0 ? ast : undefined,
|
|
92
119
|
projected: g.__pithyProjectedChildren,
|
|
120
|
+
slot: buildDefaultSlot(context),
|
|
121
|
+
outer: outerSlotMap(context?.__slotMap),
|
|
93
122
|
};
|
|
94
123
|
}
|
|
95
124
|
//# sourceMappingURL=renderChildren.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderChildren.js","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAA8B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"renderChildren.js","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAA8B,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAI7D;;;;;;;;;;;;;;;;GAgBG;AACH,wKAAwK;AACxK,MAAM,UAAU,cAAc;IA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,OAAO,EAAE,cAAc,CAAC;IACxC,MAAM,GAAG,GAAG,OAAO,EAAE,eAAe,CAAC;IACrC,OAAO;QACL,OAAO;QACP,OAAO;QACP,QAAQ,EAAE,CAAC,OAAO,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;QAC7D,SAAS,EAAE,CAAC,CAAC,wBAAwB;QACrC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC;QAC/B,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC;KACxC,CAAC;AACJ,CAAC","sourcesContent":["import { compileNodes } from './compileNodes';\nimport type { PithyNode } from '@pithyjs/compiler';\nimport { pithyGlobals, type PithyComponentContext } from '../types/globals';\nimport type { ChildFactory } from '../runtime/bindings/types';\nimport { outerSlotMap, type SlotMap } from './contentProjection';\nimport { withSlotBoundary } from './binds/bindErrorBoundary';\n\ntype SlotRenderer = NonNullable<ReturnType<SlotMap['get']>>;\n\n/**\n * If the registry renderer has set `globalThis.__pithyProjectedChildren` (a\n * `DocumentFragment` of already-rendered slot children), returns and clears it —\n * single-consume, so the first caller wins. This delivers construction-time\n * children on the registry path. The registry path has no AST fallback, so a\n * second `renderChildren()`/`captureChildren()` call returns an empty fragment.\n *\n * A build-compiled parent's default slot is rendered afresh on every call.\n *\n * Otherwise compiles child AST nodes from the current component context through\n * the full pipeline (structural + non-structural directives). This enables\n * nested components inside projected content — unlike `<slot>`, which inserts\n * DOM after `bindComponentTags` has already run.\n *\n * Use inside component functions (Stack, Grid, etc.) that need to compile\n * their children without named slots or fallback content.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"renderChildren\",\"stability\":\"stable\",\"signature\":\"() => { el: DocumentFragment; destroy: () => void }\"} */\nexport function renderChildren(): {\n el: DocumentFragment;\n destroy: () => void;\n} {\n const globalScope = pithyGlobals();\n const injected = globalScope.__pithyProjectedChildren;\n if (injected) {\n globalScope.__pithyProjectedChildren = undefined;\n return { el: injected, destroy: () => {} };\n }\n\n const componentCtx = pithyGlobals().__pithyComponentContext;\n const slot = buildDefaultSlot(componentCtx);\n if (slot) {\n const disposers: (() => void)[] = [];\n const el = slot(disposers);\n return {\n el,\n destroy: () => {\n for (let i = disposers.length - 1; i >= 0; i--) disposers[i]();\n disposers.length = 0;\n },\n };\n }\n\n // A parent composing atoms by direct call after captureChildren() cleared its\n // context is still mid-render (`rendering` truthy) — not the misuse this guards\n // against, so a consumed context alone must not trigger the warning.\n const rendering = pithyGlobals().__pithyRenderingComponent;\n if (import.meta.env?.DEV && !componentCtx && !rendering) {\n console.warn('[renderChildren] Called outside component render context');\n }\n\n const childAstNodes: PithyNode[] = componentCtx?.__childAstNodes ?? [];\n\n // Strip internal __ properties, keep parent scope (includes components, signals, etc.)\n const parentCtx: Record<string, unknown> = componentCtx\n ? Object.fromEntries(\n Object.entries(componentCtx).filter(\n ([k]) => !k.startsWith('__') || k === '__pithyRowLocals'\n )\n )\n : {};\n // What a `<slot>` among the children receives.\n const outer = outerSlotMap(componentCtx?.__slotMap);\n if (outer) parentCtx.__slotMap = outer;\n\n return withSlotBoundary(undefined, componentCtx?.__slotHost, () =>\n compileNodes(childAstNodes, parentCtx)\n );\n}\n\n/**\n * Captures projected children and clears the component context so\n * inner component calls (e.g. `Heading()`, `Text()`) don't consume\n * the outer component's children.\n *\n * After capture, the current component's context on `globalThis` is\n * reset to the value of `__parentComponentContext` if present, or\n * otherwise to `undefined`. In the current core implementation,\n * `__parentComponentContext` is not set by the runtime, so this\n * effectively clears the active component context to prevent child\n * leakage into inner component calls.\n *\n * **Important invariant:** This function must be called exactly once per\n * component, before any inner component function calls. It consumes the\n * current context's children — a second call would return an empty fragment.\n * After this call, the caller must not rely on reading its own context\n * properties from `globalThis.__pithyComponentContext`.\n *\n * For 3+ levels of nesting (e.g., section A → section B → atoms), each\n * level should call `captureChildren()` independently. Any multi-level\n * parent restoration depends on `__parentComponentContext` being managed\n * by external tooling; the core library only performs a best-effort reset\n * from that property when present.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"captureChildren\",\"stability\":\"stable\",\"signature\":\"() => { el: DocumentFragment; destroy: () => void }\"} */\nexport function captureChildren(): {\n el: DocumentFragment;\n destroy: () => void;\n} {\n const g = pithyGlobals();\n const prevCtx = g.__pithyComponentContext;\n const result = renderChildren();\n // Clear context so inner component calls start fresh.\n // If there was a parent context, it will be restored by the parent's\n // own render cycle — we only need to prevent child leakage here.\n g.__pithyComponentContext = prevCtx?.__parentComponentContext ?? undefined;\n return result;\n}\n\n/** Default-slot renderer of a build-compiled parent; it has no AST. */\nfunction buildDefaultSlot(ctx: PithyComponentContext | undefined) {\n return ctx && !ctx.__childAstNodes && !ctx.__childFactory\n ? ctx.__slotMap?.get('')\n : undefined;\n}\n\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"ChildPayload\",\"stability\":\"experimental\",\"signature\":\"interface ChildPayload\"} */\nexport interface ChildPayload {\n context: PithyComponentContext | undefined;\n factory?: ChildFactory;\n astNodes?: PithyNode[];\n projected?: DocumentFragment;\n /** A build's default slot, rendered by `renderChildren()` on each call. */\n slot?: SlotRenderer;\n /** What a `<slot>` among `astNodes` receives. */\n outer?: SlotMap;\n}\n\n/**\n * Reads the children addressed to the component being rendered, without\n * consuming them. `factory` and `astNodes` are mutually exclusive: an AOT child\n * factory wins, because a JIT parent's AST can reach an AOT component's context\n * through `mergeContexts`, never the reverse.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"readChildPayload\",\"stability\":\"experimental\",\"signature\":\"() => ChildPayload\"} */\nexport function readChildPayload(): ChildPayload {\n const g = pithyGlobals();\n const context = g.__pithyComponentContext;\n const factory = context?.__childFactory;\n const ast = context?.__childAstNodes;\n return {\n context,\n factory,\n astNodes: !factory && ast && ast.length > 0 ? ast : undefined,\n projected: g.__pithyProjectedChildren,\n slot: buildDefaultSlot(context),\n outer: outerSlotMap(context?.__slotMap),\n };\n}\n"]}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"risk": "high"
|
|
7
7
|
}
|
|
8
8
|
*/
|
|
9
|
-
import { type BoundaryInfo } from './binds/bindErrorBoundary';
|
|
9
|
+
import { type BoundaryInfo } from './binds/bindErrorBoundary.js';
|
|
10
10
|
/**
|
|
11
11
|
* A component render crash recorded during a static/server render.
|
|
12
12
|
*/
|
|
@@ -37,26 +37,8 @@ export interface SSRRenderCrash {
|
|
|
37
37
|
* `bindComponentTags`, `fragment.contains(el)` in `applyBindings`). It can
|
|
38
38
|
* no longer contribute to the output, so any record for it is stale.
|
|
39
39
|
*
|
|
40
|
-
* Retraction matters because the JIT `@if` path really does attempt the same tag
|
|
41
|
-
* twice, measured by counting component invocations:
|
|
42
|
-
*
|
|
43
|
-
* 1. `bindStructuralDirectives` runs first and `handleConditionalChain` binds
|
|
44
|
-
* the chosen branch while it is still DETACHED, so `el.closest('[data-error]')`
|
|
45
|
-
* finds nothing and the crash is recorded.
|
|
46
|
-
* 2. The branch is inserted, and `bindTemplateDirectives` then reaches the
|
|
47
|
-
* still-raw tag on the assembled tree, where the boundary is visible and
|
|
48
|
-
* accepts — retracting via case 1 above.
|
|
49
|
-
*
|
|
50
|
-
* Case 3 exists because accepting is synchronous: it immediately hides the
|
|
51
|
-
* boundary's content, so a SECOND crashing component in that branch is detached
|
|
52
|
-
* before it can be retried, and its detached-pass record would otherwise stand
|
|
53
|
-
* and fail a route whose fallback rendered correctly.
|
|
54
|
-
*
|
|
55
40
|
* Every one of these is mutation-tested; removing any of them turns a correct
|
|
56
41
|
* render into a failed route, or a broken one into a silent success.
|
|
57
|
-
*
|
|
58
|
-
* AOT invokes `applyComponent` once per `pid` and never retries, which is why
|
|
59
|
-
* the equivalent AOT boundary case behaves differently — see BUG-023.
|
|
60
42
|
*/
|
|
61
43
|
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"clearSSRRenderCrash","stability":"internal","signature":"(el: Element) => void"} */
|
|
62
44
|
export declare function clearSSRRenderCrash(el: Element): void;
|
|
@@ -66,6 +48,12 @@ export declare function clearSSRRenderCrash(el: Element): void;
|
|
|
66
48
|
*/
|
|
67
49
|
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resetSSRRenderCrashes","stability":"stable","signature":"() => void"} */
|
|
68
50
|
export declare function resetSSRRenderCrashes(): void;
|
|
51
|
+
/**
|
|
52
|
+
* An element that left the tree being bound contributes nothing to the output:
|
|
53
|
+
* its recorded crash is stale, and an attributed one is only logged.
|
|
54
|
+
*/
|
|
55
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"forgetCrash","stability":"internal","signature":"(el: Element) => void"} */
|
|
56
|
+
export declare function forgetCrash(el: Element): void;
|
|
69
57
|
/**
|
|
70
58
|
* Return the crashes still recorded once the render has finished, and empty
|
|
71
59
|
* the collector.
|
|
@@ -77,23 +65,15 @@ export declare function resetSSRRenderCrashes(): void;
|
|
|
77
65
|
* An earlier draft re-resolved each record's boundary here, dropping any crash
|
|
78
66
|
* whose element had ended up inside an `@error-boundary`. That is unsound,
|
|
79
67
|
* because a boundary *existing* above an element is not the same as that
|
|
80
|
-
* boundary having *handled* the crash
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* there is nothing left to re-resolve.
|
|
86
|
-
* - AOT was actively broken by it. A branch factory binds its subtree while
|
|
87
|
-
* detached, so `applyComponent`'s `el.closest('[data-error]')` finds
|
|
88
|
-
* nothing and the boundary never receives the error — but the nodes are
|
|
89
|
-
* then inserted *under* that boundary, so re-resolution saw one and
|
|
90
|
-
* dropped the record. The boundary signal stayed null, its fallback never
|
|
91
|
-
* activated, the raw component tag shipped, and the build went green: the
|
|
92
|
-
* exact BUG-018 symptom, reintroduced by its own fix.
|
|
68
|
+
* boundary having *handled* the crash. A crash that a boundary rejected, or
|
|
69
|
+
* that ran where no boundary resolved, is placed under one afterwards just the
|
|
70
|
+
* same. Re-resolution dropped such a record: the boundary signal stayed null,
|
|
71
|
+
* its fallback never activated, the raw component tag shipped, and the build
|
|
72
|
+
* went green — the exact BUG-018 symptom, reintroduced by its own fix.
|
|
93
73
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
74
|
+
* A crash in a branch, slot or component built detached is attributed to its
|
|
75
|
+
* boundary instead (`deferCrash`); whatever is still attributed here is
|
|
76
|
+
* recorded.
|
|
97
77
|
*/
|
|
98
78
|
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"collectUnhandledSSRRenderCrashes","stability":"stable","signature":"() => SSRRenderCrash[]"} */
|
|
99
79
|
export declare function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[];
|
|
@@ -109,8 +89,56 @@ export declare function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[];
|
|
|
109
89
|
* the boundary signal null, rendered no fallback, and failed the route, even
|
|
110
90
|
* though the code called it "the same content loss as a crash".
|
|
111
91
|
*
|
|
92
|
+
* With no `boundary`, a failure in a branch, slot or component built detached
|
|
93
|
+
* is attributed to the boundary its render sits under (`deferCrash`) and counts
|
|
94
|
+
* as handled here; `attribution` says how it is logged if no boundary takes it.
|
|
95
|
+
*
|
|
112
96
|
* Callers still do their own logging, since the wording differs per failure.
|
|
113
97
|
*/
|
|
114
|
-
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"reportComponentFailure","stability":"internal","signature":"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null) => boolean"} */
|
|
115
|
-
export declare function reportComponentFailure(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null): boolean;
|
|
98
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"reportComponentFailure","stability":"internal","signature":"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null, attribution?: Attribution) => boolean"} */
|
|
99
|
+
export declare function reportComponentFailure(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null, attribution?: Attribution): boolean;
|
|
100
|
+
/** How an attributed crash is logged: `message` if no boundary takes it, `onCaptured` if one does. */
|
|
101
|
+
export interface Attribution {
|
|
102
|
+
message?: string | null;
|
|
103
|
+
onCaptured?: () => void;
|
|
104
|
+
}
|
|
105
|
+
/** Whether `el` crashed and was attributed; a retry would run its setup twice, which a build never does. */
|
|
106
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"hasCrashed","stability":"internal","signature":"(el: Element) => boolean"} */
|
|
107
|
+
export declare function hasCrashed(el: Element): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Brackets a render transaction: a template bind, or one structural update
|
|
110
|
+
* that builds a branch and inserts it. Attributed crashes are resolved when the
|
|
111
|
+
* outermost one ends, so a boundary hides its content only once everything in
|
|
112
|
+
* it is bound and in place.
|
|
113
|
+
*/
|
|
114
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"withinRender","stability":"internal","signature":"<T>(fn: () => T) => T"} */
|
|
115
|
+
export declare function withinRender<T>(fn: () => T): T;
|
|
116
|
+
/**
|
|
117
|
+
* Attributes a crash that reached no boundary through the DOM to the boundary
|
|
118
|
+
* its render sits under (`boundaryContext`): a branch, slot or component built
|
|
119
|
+
* detached. Returns `false` with no such context, so the caller handles the
|
|
120
|
+
* crash as before.
|
|
121
|
+
*/
|
|
122
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"deferCrash","stability":"internal","signature":"(el: Element, tag: string, error: Error, attribution?: Attribution) => boolean"} */
|
|
123
|
+
export declare function deferCrash(el: Element, tag: string, error: Error, { message, onCaptured }?: Attribution): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Resolves attributed crashes once they are in place. Each goes to the nearest
|
|
126
|
+
* registered boundary at its final position, exactly as a crash placed there
|
|
127
|
+
* would, and within one resolution a boundary takes at most one error. In the
|
|
128
|
+
* browser this waits for the
|
|
129
|
+
* outermost render to end. A static render binds text once, so there the
|
|
130
|
+
* component pass of the template that owns a boundary resolves its crashes
|
|
131
|
+
* (`scope`), before that template's text is bound and after its components
|
|
132
|
+
* ran. `task` runs at the end of the task; `collect` after the HTML is
|
|
133
|
+
* serialized, and only records.
|
|
134
|
+
*/
|
|
135
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resolveAttributedCrashes","stability":"internal","signature":"(mode?: 'render' | 'task' | 'collect', scope?: ParentNode) => void"} */
|
|
136
|
+
export declare function resolveAttributedCrashes(mode?: 'render' | 'task' | 'collect', scope?: ParentNode): void;
|
|
137
|
+
/**
|
|
138
|
+
* Before a component inside a boundary's fallback renders in a static render,
|
|
139
|
+
* that boundary takes its crashes, so content the component renders from the
|
|
140
|
+
* error (text is bound once there) has it.
|
|
141
|
+
*/
|
|
142
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resolveBeforeFallback","stability":"internal","signature":"(el: Element) => void"} */
|
|
143
|
+
export declare function resolveBeforeFallback(el: Element): void;
|
|
116
144
|
//# sourceMappingURL=ssrCrashes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrCrashes.d.ts","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;
|
|
1
|
+
{"version":3,"file":"ssrCrashes.d.ts","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAKF,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,KAAK,EAAE,KAAK,CAAC;CACd;AAwBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,+IAA+I;AAC/I,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAErD;AA4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