@pithyjs/core 0.1.0-beta.0 → 0.1.0-beta.1
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 +27 -2
- package/dist/compile/bindSwitchCases.js +5 -2
- package/dist/compile/bindSwitchCases.js.map +1 -1
- package/dist/compile/binds/bindClassDirectives.d.ts +2 -0
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindClassDirectives.js +18 -15
- package/dist/compile/binds/bindClassDirectives.js.map +1 -1
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +90 -33
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.js +41 -11
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.d.ts +13 -2
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.js +17 -7
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
- package/dist/compile/binds/forwardedAttrs.d.ts +22 -0
- package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -0
- package/dist/compile/binds/forwardedAttrs.js +66 -0
- package/dist/compile/binds/forwardedAttrs.js.map +1 -0
- package/dist/compile/componentResult.d.ts +100 -0
- package/dist/compile/componentResult.d.ts.map +1 -0
- package/dist/compile/componentResult.js +138 -0
- package/dist/compile/componentResult.js.map +1 -0
- package/dist/compile/forLoops/createLoopManager.d.ts +4 -1
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
- package/dist/compile/forLoops/createLoopManager.js +120 -92
- package/dist/compile/forLoops/createLoopManager.js.map +1 -1
- package/dist/compile/handleConditionalChain.d.ts.map +1 -1
- package/dist/compile/handleConditionalChain.js +21 -18
- package/dist/compile/handleConditionalChain.js.map +1 -1
- package/dist/compile/index.d.ts +6 -3
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +19 -3
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/renderChildren.d.ts +17 -0
- package/dist/compile/renderChildren.d.ts.map +1 -1
- package/dist/compile/renderChildren.js +20 -1
- package/dist/compile/renderChildren.js.map +1 -1
- package/dist/compile/ssrCrashes.d.ts +116 -0
- package/dist/compile/ssrCrashes.d.ts.map +1 -0
- package/dist/compile/ssrCrashes.js +173 -0
- package/dist/compile/ssrCrashes.js.map +1 -0
- package/dist/runtime/applyBindings.d.ts +3 -3
- package/dist/runtime/applyBindings.d.ts.map +1 -1
- package/dist/runtime/applyBindings.js +28 -4
- package/dist/runtime/applyBindings.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +102 -13
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
- package/dist/runtime/bindings/applyDefer.js +40 -12
- package/dist/runtime/bindings/applyDefer.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts +2 -1
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +27 -3
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/dist/runtime/bindings/index.d.ts +2 -2
- package/dist/runtime/bindings/index.d.ts.map +1 -1
- package/dist/runtime/bindings/index.js +1 -1
- package/dist/runtime/bindings/index.js.map +1 -1
- package/dist/runtime/bindings/types.d.ts +12 -1
- package/dist/runtime/bindings/types.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/resource/createAction.d.ts +44 -0
- package/dist/runtime/resource/createAction.d.ts.map +1 -0
- package/dist/runtime/resource/createAction.js +102 -0
- package/dist/runtime/resource/createAction.js.map +1 -0
- package/dist/runtime/resource/createResource.d.ts +56 -0
- package/dist/runtime/resource/createResource.d.ts.map +1 -0
- package/dist/runtime/resource/createResource.js +103 -0
- package/dist/runtime/resource/createResource.js.map +1 -0
- package/dist/runtime/resource/engine.d.ts +136 -0
- package/dist/runtime/resource/engine.d.ts.map +1 -0
- package/dist/runtime/resource/engine.js +363 -0
- package/dist/runtime/resource/engine.js.map +1 -0
- package/dist/runtime/resource/index.d.ts +19 -0
- package/dist/runtime/resource/index.d.ts.map +1 -0
- package/dist/runtime/resource/index.js +18 -0
- package/dist/runtime/resource/index.js.map +1 -0
- package/dist/runtime/resource/types.d.ts +240 -0
- package/dist/runtime/resource/types.d.ts.map +1 -0
- package/dist/runtime/resource/types.js +9 -0
- package/dist/runtime/resource/types.js.map +1 -0
- package/dist/types/globals.d.ts +9 -0
- package/dist/types/globals.d.ts.map +1 -1
- package/dist/types/globals.js.map +1 -1
- package/dist/types/index.d.ts +15 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.ssr-crashes",
|
|
4
|
+
"title": "SSR Unhandled Component Crash Collector",
|
|
5
|
+
"category": "runtime",
|
|
6
|
+
"risk": "high"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
import { type BoundaryInfo } from './binds/bindErrorBoundary';
|
|
10
|
+
/**
|
|
11
|
+
* A component render crash recorded during a static/server render.
|
|
12
|
+
*/
|
|
13
|
+
export interface SSRRenderCrash {
|
|
14
|
+
/** The custom-element placeholder the crashed component was to replace. */
|
|
15
|
+
el: Element;
|
|
16
|
+
/** Authored tag name, for the failure message. */
|
|
17
|
+
tag: string;
|
|
18
|
+
/** The error the component threw. */
|
|
19
|
+
error: Error;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Forget any crash previously recorded for `el`.
|
|
23
|
+
*
|
|
24
|
+
* Called only at points where the record is provably no longer the outcome, and
|
|
25
|
+
* NEVER before invoking a component. Retracting eagerly at the top of an attempt
|
|
26
|
+
* hides a failed retry: a component that throws detached and then returns
|
|
27
|
+
* something unusable would have its only record erased, shipping a page with a
|
|
28
|
+
* missing subtree and a green build. The three call sites are:
|
|
29
|
+
*
|
|
30
|
+
* 1. A boundary ACCEPTING the error (`setBoundaryError()` returning `true`).
|
|
31
|
+
* A boundary merely being in scope is not enough — an already-active one
|
|
32
|
+
* with no free ancestor rejects the error, and that is as unhandled as
|
|
33
|
+
* having no boundary at all.
|
|
34
|
+
* 2. A component returning a usable node that then successfully reaches the
|
|
35
|
+
* document, i.e. after `replaceWith` has not thrown.
|
|
36
|
+
* 3. An element that has left the tree being bound (`scope.contains(el)` in
|
|
37
|
+
* `bindComponentTags`, `fragment.contains(el)` in `applyBindings`). It can
|
|
38
|
+
* no longer contribute to the output, so any record for it is stale.
|
|
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
|
+
* Every one of these is mutation-tested; removing any of them turns a correct
|
|
56
|
+
* 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
|
+
*/
|
|
61
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"clearSSRRenderCrash","stability":"internal","signature":"(el: Element) => void"} */
|
|
62
|
+
export declare function clearSSRRenderCrash(el: Element): void;
|
|
63
|
+
/**
|
|
64
|
+
* Drop every recorded crash. Called by the SSR renderer before a render starts
|
|
65
|
+
* and again in its `finally`, so one route's crash can never fail the next.
|
|
66
|
+
*/
|
|
67
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resetSSRRenderCrashes","stability":"stable","signature":"() => void"} */
|
|
68
|
+
export declare function resetSSRRenderCrashes(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Return the crashes still recorded once the render has finished, and empty
|
|
71
|
+
* the collector.
|
|
72
|
+
*
|
|
73
|
+
* Every surviving record is a failure. A record is only ever retracted by
|
|
74
|
+
* `clearSSRRenderCrash`, i.e. by a genuine re-attempt at the same element that
|
|
75
|
+
* then went better — never by inspecting the finished tree.
|
|
76
|
+
*
|
|
77
|
+
* An earlier draft re-resolved each record's boundary here, dropping any crash
|
|
78
|
+
* whose element had ended up inside an `@error-boundary`. That is unsound,
|
|
79
|
+
* because a boundary *existing* above an element is not the same as that
|
|
80
|
+
* boundary having *handled* the crash:
|
|
81
|
+
*
|
|
82
|
+
* - JIT never needed it. It does record a crash from the detached first
|
|
83
|
+
* attempt, but the retry after insertion is caught by the boundary and
|
|
84
|
+
* retracts that record itself (see `clearSSRRenderCrash`). By collect time
|
|
85
|
+
* there is nothing left to re-resolve.
|
|
86
|
+
* - AOT was actively broken by it. A branch factory binds its subtree while
|
|
87
|
+
* detached, so `applyComponent`'s `el.closest('[data-error]')` finds
|
|
88
|
+
* nothing and the boundary never receives the error — but the nodes are
|
|
89
|
+
* then inserted *under* that boundary, so re-resolution saw one and
|
|
90
|
+
* dropped the record. The boundary signal stayed null, its fallback never
|
|
91
|
+
* activated, the raw component tag shipped, and the build went green: the
|
|
92
|
+
* exact BUG-018 symptom, reintroduced by its own fix.
|
|
93
|
+
*
|
|
94
|
+
* That AOT boundary gap is real but predates this collector and is tracked
|
|
95
|
+
* separately as BUG-023. Until it is fixed, such a crash fails its route, which
|
|
96
|
+
* is the safe direction: a loud failure rather than silently truncated HTML.
|
|
97
|
+
*/
|
|
98
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"collectUnhandledSSRRenderCrashes","stability":"stable","signature":"() => SSRRenderCrash[]"} */
|
|
99
|
+
export declare function collectUnhandledSSRRenderCrashes(): SSRRenderCrash[];
|
|
100
|
+
/**
|
|
101
|
+
* Hand a component failure to its `@error-boundary`, or record it if none takes
|
|
102
|
+
* it. Returns whether a boundary accepted ownership.
|
|
103
|
+
*
|
|
104
|
+
* The single funnel for every way a component can fail to produce content: a
|
|
105
|
+
* thrown error, an unusable return value, and a rendered node that never reached
|
|
106
|
+
* the document. They were handled in five separate places and drifted — the
|
|
107
|
+
* throw paths consulted the boundary while the malformed paths recorded
|
|
108
|
+
* directly, so a component under `@error-boundary` that returned garbage left
|
|
109
|
+
* the boundary signal null, rendered no fallback, and failed the route, even
|
|
110
|
+
* though the code called it "the same content loss as a crash".
|
|
111
|
+
*
|
|
112
|
+
* Callers still do their own logging, since the wording differs per failure.
|
|
113
|
+
*/
|
|
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;
|
|
116
|
+
//# sourceMappingURL=ssrCrashes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssrCrashes.d.ts","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAIF,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,KAAK,EAAE,KAAK,CAAC;CACd;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,+IAA+I;AAC/I,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAErD;AA4BD;;;GAGG;AACH,oIAAoI;AACpI,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,2JAA2J;AAC3J,wBAAgB,gCAAgC,IAAI,cAAc,EAAE,CAKnE;AAED;;;;;;;;;;;;;GAaG;AACH,+MAA+M;AAC/M,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,GAAG,IAAI,GAC5B,OAAO,CAWT"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.ssr-crashes",
|
|
4
|
+
"title": "SSR Unhandled Component Crash Collector",
|
|
5
|
+
"category": "runtime",
|
|
6
|
+
"risk": "high"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
import { pithyGlobals } from '../types/globals';
|
|
10
|
+
import { isSSRMode } from './ssrMode';
|
|
11
|
+
import { setBoundaryError } from './binds/bindErrorBoundary';
|
|
12
|
+
/**
|
|
13
|
+
* Crashes recorded during the current server render, keyed by the placeholder
|
|
14
|
+
* element so a later binding pass over the same element can retract its own
|
|
15
|
+
* earlier record (see `clearSSRRenderCrash`).
|
|
16
|
+
*
|
|
17
|
+
* Held on `globalThis`, not in this module. `@pithyjs/ssr` depends on
|
|
18
|
+
* `@pithyjs/core` as a regular dependency, so an app and the SSR package can
|
|
19
|
+
* resolve two physical copies: `html()` would record into the app's copy while
|
|
20
|
+
* `renderToString()` collected and reset the SSR package's, reintroducing
|
|
21
|
+
* BUG-018 *and* leaking the app copy's DOM records for the life of the process.
|
|
22
|
+
* The same reasoning already puts `__PITHY_SSR__` and `__getComponentContext`
|
|
23
|
+
* on this bridge.
|
|
24
|
+
*
|
|
25
|
+
* A `Map` (not a `WeakMap`) because the collector must be enumerable at flush
|
|
26
|
+
* time. `resetSSRRenderCrashes()` is what keeps it from retaining DOM across
|
|
27
|
+
* renders — the SSR renderer calls it in a `finally`.
|
|
28
|
+
*/
|
|
29
|
+
function crashRegistry() {
|
|
30
|
+
const g = pithyGlobals();
|
|
31
|
+
return (g.__pithySSRCrashes ?? (g.__pithySSRCrashes = new Map()));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Forget any crash previously recorded for `el`.
|
|
35
|
+
*
|
|
36
|
+
* Called only at points where the record is provably no longer the outcome, and
|
|
37
|
+
* NEVER before invoking a component. Retracting eagerly at the top of an attempt
|
|
38
|
+
* hides a failed retry: a component that throws detached and then returns
|
|
39
|
+
* something unusable would have its only record erased, shipping a page with a
|
|
40
|
+
* missing subtree and a green build. The three call sites are:
|
|
41
|
+
*
|
|
42
|
+
* 1. A boundary ACCEPTING the error (`setBoundaryError()` returning `true`).
|
|
43
|
+
* A boundary merely being in scope is not enough — an already-active one
|
|
44
|
+
* with no free ancestor rejects the error, and that is as unhandled as
|
|
45
|
+
* having no boundary at all.
|
|
46
|
+
* 2. A component returning a usable node that then successfully reaches the
|
|
47
|
+
* document, i.e. after `replaceWith` has not thrown.
|
|
48
|
+
* 3. An element that has left the tree being bound (`scope.contains(el)` in
|
|
49
|
+
* `bindComponentTags`, `fragment.contains(el)` in `applyBindings`). It can
|
|
50
|
+
* no longer contribute to the output, so any record for it is stale.
|
|
51
|
+
*
|
|
52
|
+
* Retraction matters because the JIT `@if` path really does attempt the same tag
|
|
53
|
+
* twice, measured by counting component invocations:
|
|
54
|
+
*
|
|
55
|
+
* 1. `bindStructuralDirectives` runs first and `handleConditionalChain` binds
|
|
56
|
+
* the chosen branch while it is still DETACHED, so `el.closest('[data-error]')`
|
|
57
|
+
* finds nothing and the crash is recorded.
|
|
58
|
+
* 2. The branch is inserted, and `bindTemplateDirectives` then reaches the
|
|
59
|
+
* still-raw tag on the assembled tree, where the boundary is visible and
|
|
60
|
+
* accepts — retracting via case 1 above.
|
|
61
|
+
*
|
|
62
|
+
* Case 3 exists because accepting is synchronous: it immediately hides the
|
|
63
|
+
* boundary's content, so a SECOND crashing component in that branch is detached
|
|
64
|
+
* before it can be retried, and its detached-pass record would otherwise stand
|
|
65
|
+
* and fail a route whose fallback rendered correctly.
|
|
66
|
+
*
|
|
67
|
+
* Every one of these is mutation-tested; removing any of them turns a correct
|
|
68
|
+
* render into a failed route, or a broken one into a silent success.
|
|
69
|
+
*
|
|
70
|
+
* AOT invokes `applyComponent` once per `pid` and never retries, which is why
|
|
71
|
+
* the equivalent AOT boundary case behaves differently — see BUG-023.
|
|
72
|
+
*/
|
|
73
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"clearSSRRenderCrash","stability":"internal","signature":"(el: Element) => void"} */
|
|
74
|
+
export function clearSSRRenderCrash(el) {
|
|
75
|
+
crashRegistry().delete(el);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Record a component failure that no error boundary took ownership of.
|
|
79
|
+
*
|
|
80
|
+
* The precondition is **not** "no boundary was in scope". It is that no boundary
|
|
81
|
+
* ACCEPTED the error, which is a strictly weaker thing: `setBoundaryError()`
|
|
82
|
+
* rejects an error when the nearest boundary is already showing one and no
|
|
83
|
+
* ancestor is free, and both binders call this on that path with a boundary
|
|
84
|
+
* very much present. Getting the two confused is what this whole module exists
|
|
85
|
+
* to prevent.
|
|
86
|
+
*
|
|
87
|
+
* Nor is "crash" limited to a thrown error. The binders also record a component
|
|
88
|
+
* that returned an unusable result, and one whose rendered node failed to reach
|
|
89
|
+
* the document — both leave the raw tag exactly where a throw would, which is
|
|
90
|
+
* the same content loss from the page's point of view.
|
|
91
|
+
*
|
|
92
|
+
* Callers must have established `isSSRMode()` themselves; this does not
|
|
93
|
+
* re-check.
|
|
94
|
+
*/
|
|
95
|
+
function recordSSRRenderCrash(el, tag, error) {
|
|
96
|
+
crashRegistry().set(el, {
|
|
97
|
+
el,
|
|
98
|
+
tag,
|
|
99
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Drop every recorded crash. Called by the SSR renderer before a render starts
|
|
104
|
+
* and again in its `finally`, so one route's crash can never fail the next.
|
|
105
|
+
*/
|
|
106
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"resetSSRRenderCrashes","stability":"stable","signature":"() => void"} */
|
|
107
|
+
export function resetSSRRenderCrashes() {
|
|
108
|
+
crashRegistry().clear();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Return the crashes still recorded once the render has finished, and empty
|
|
112
|
+
* the collector.
|
|
113
|
+
*
|
|
114
|
+
* Every surviving record is a failure. A record is only ever retracted by
|
|
115
|
+
* `clearSSRRenderCrash`, i.e. by a genuine re-attempt at the same element that
|
|
116
|
+
* then went better — never by inspecting the finished tree.
|
|
117
|
+
*
|
|
118
|
+
* An earlier draft re-resolved each record's boundary here, dropping any crash
|
|
119
|
+
* whose element had ended up inside an `@error-boundary`. That is unsound,
|
|
120
|
+
* because a boundary *existing* above an element is not the same as that
|
|
121
|
+
* boundary having *handled* the crash:
|
|
122
|
+
*
|
|
123
|
+
* - JIT never needed it. It does record a crash from the detached first
|
|
124
|
+
* attempt, but the retry after insertion is caught by the boundary and
|
|
125
|
+
* retracts that record itself (see `clearSSRRenderCrash`). By collect time
|
|
126
|
+
* there is nothing left to re-resolve.
|
|
127
|
+
* - AOT was actively broken by it. A branch factory binds its subtree while
|
|
128
|
+
* detached, so `applyComponent`'s `el.closest('[data-error]')` finds
|
|
129
|
+
* nothing and the boundary never receives the error — but the nodes are
|
|
130
|
+
* then inserted *under* that boundary, so re-resolution saw one and
|
|
131
|
+
* dropped the record. The boundary signal stayed null, its fallback never
|
|
132
|
+
* activated, the raw component tag shipped, and the build went green: the
|
|
133
|
+
* exact BUG-018 symptom, reintroduced by its own fix.
|
|
134
|
+
*
|
|
135
|
+
* That AOT boundary gap is real but predates this collector and is tracked
|
|
136
|
+
* separately as BUG-023. Until it is fixed, such a crash fails its route, which
|
|
137
|
+
* is the safe direction: a loud failure rather than silently truncated HTML.
|
|
138
|
+
*/
|
|
139
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"collectUnhandledSSRRenderCrashes","stability":"stable","signature":"() => SSRRenderCrash[]"} */
|
|
140
|
+
export function collectUnhandledSSRRenderCrashes() {
|
|
141
|
+
const registry = crashRegistry();
|
|
142
|
+
const unhandled = [...registry.values()];
|
|
143
|
+
registry.clear();
|
|
144
|
+
return unhandled;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Hand a component failure to its `@error-boundary`, or record it if none takes
|
|
148
|
+
* it. Returns whether a boundary accepted ownership.
|
|
149
|
+
*
|
|
150
|
+
* The single funnel for every way a component can fail to produce content: a
|
|
151
|
+
* thrown error, an unusable return value, and a rendered node that never reached
|
|
152
|
+
* the document. They were handled in five separate places and drifted — the
|
|
153
|
+
* throw paths consulted the boundary while the malformed paths recorded
|
|
154
|
+
* directly, so a component under `@error-boundary` that returned garbage left
|
|
155
|
+
* the boundary signal null, rendered no fallback, and failed the route, even
|
|
156
|
+
* though the code called it "the same content loss as a crash".
|
|
157
|
+
*
|
|
158
|
+
* Callers still do their own logging, since the wording differs per failure.
|
|
159
|
+
*/
|
|
160
|
+
/** @codexApi {"parent":"pithy.runtime.ssr-crashes","name":"reportComponentFailure","stability":"internal","signature":"(el: Element, tag: string, error: Error, boundary: BoundaryInfo | null) => boolean"} */
|
|
161
|
+
export function reportComponentFailure(el, tag, error, boundary) {
|
|
162
|
+
// A boundary in scope is not a boundary that accepted: an already-active one
|
|
163
|
+
// with no free ancestor rejects, and that is as unhandled as having none.
|
|
164
|
+
const accepted = boundary ? setBoundaryError(boundary, error) : false;
|
|
165
|
+
if (isSSRMode()) {
|
|
166
|
+
if (accepted)
|
|
167
|
+
clearSSRRenderCrash(el);
|
|
168
|
+
else
|
|
169
|
+
recordSSRRenderCrash(el, tag, error);
|
|
170
|
+
}
|
|
171
|
+
return accepted;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=ssrCrashes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssrCrashes.js","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAEF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,2BAA2B,CAAC;AAchF;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;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,GAAG;QACH,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KACjE,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,oIAAoI;AACpI,MAAM,UAAU,qBAAqB;IACnC,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,2JAA2J;AAC3J,MAAM,UAAU,gCAAgC;IAC9C,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;IACjC,MAAM,SAAS,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,+MAA+M;AAC/M,MAAM,UAAU,sBAAsB,CACpC,EAAW,EACX,GAAW,EACX,KAAY,EACZ,QAA6B;IAE7B,6EAA6E;IAC7E,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEtE,IAAI,SAAS,EAAE,EAAE,CAAC;QAChB,IAAI,QAAQ;YAAE,mBAAmB,CAAC,EAAE,CAAC,CAAC;;YACjC,oBAAoB,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"category": "runtime"
|
|
6
6
|
}
|
|
7
7
|
*/
|
|
8
|
-
import { type Desc, type EventDesc, type InterpDesc, type ClassDesc, type StyleDesc, type BoundDesc, type RefDesc, type BindDesc, type CompDesc, type DeferDesc, type ErrorDesc, type ProjDesc, type IfDesc, type ForDesc, type SwitchDesc } from './bindings';
|
|
9
|
-
export type { Desc, EventDesc, InterpDesc, ClassDesc, StyleDesc, BoundDesc, RefDesc, BindDesc, CompDesc, DeferDesc, ErrorDesc, ProjDesc, IfDesc, ForDesc, SwitchDesc, };
|
|
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';
|
|
9
|
+
export type { Desc, EventDesc, InterpDesc, ClassDesc, ClassesDesc, StyleDesc, BoundDesc, RefDesc, BindDesc, CompDesc, DeferDesc, ErrorDesc, ProjDesc, IfDesc, ForDesc, SwitchDesc, };
|
|
10
10
|
/**
|
|
11
11
|
* Applies pre-extracted binding descriptors to an AOT-generated DOM fragment.
|
|
12
12
|
*
|
|
@@ -18,7 +18,7 @@ export type { Desc, EventDesc, InterpDesc, ClassDesc, StyleDesc, BoundDesc, RefD
|
|
|
18
18
|
* **Binding order** mirrors (but is not identical to) bindTemplateDirectives:
|
|
19
19
|
* 1. Structural: switch → if → for
|
|
20
20
|
* 2. Non-structural: ref → error → projection → component → bind →
|
|
21
|
-
* interpolation → event → class → style → bound attr → defer
|
|
21
|
+
* interpolation → event → class → classes → style → bound attr → defer
|
|
22
22
|
*
|
|
23
23
|
* Differences from JIT bindTemplateDirectives:
|
|
24
24
|
* - AOT has an explicit `style` phase (JIT folds inline styles into bound attrs)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyBindings.d.ts","sourceRoot":"","sources":["../../src/runtime/applyBindings.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;
|
|
1
|
+
{"version":3,"file":"applyBindings.d.ts","sourceRoot":"","sources":["../../src/runtime/applyBindings.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAIF,OAAO,EAmBL,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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,8PAA8P;AAC9P,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,IAAI,EAAE,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B;IAAE,EAAE,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA8J/C"}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
}
|
|
7
7
|
*/
|
|
8
8
|
import { drainDestroyCallbacks } from './onDestroy';
|
|
9
|
-
import {
|
|
9
|
+
import { clearSSRRenderCrash } from '../compile/ssrCrashes';
|
|
10
|
+
import { buildPidMap, buildCommentMap, mergeContexts, applyRef, applyError, applyProjection, applyComponent, applyBind, applyInterpolation, applyEvent, applyClass, applyClasses, applyStyle, applyBound, applyIf, applyFor, applySwitch, applyDefer, } from './bindings';
|
|
10
11
|
// ─── Main entry point ─────────────────────────────────────────────────────────
|
|
11
12
|
/**
|
|
12
13
|
* Applies pre-extracted binding descriptors to an AOT-generated DOM fragment.
|
|
@@ -19,7 +20,7 @@ import { buildPidMap, buildCommentMap, mergeContexts, applyRef, applyError, appl
|
|
|
19
20
|
* **Binding order** mirrors (but is not identical to) bindTemplateDirectives:
|
|
20
21
|
* 1. Structural: switch → if → for
|
|
21
22
|
* 2. Non-structural: ref → error → projection → component → bind →
|
|
22
|
-
* interpolation → event → class → style → bound attr → defer
|
|
23
|
+
* interpolation → event → class → classes → style → bound attr → defer
|
|
23
24
|
*
|
|
24
25
|
* Differences from JIT bindTemplateDirectives:
|
|
25
26
|
* - AOT has an explicit `style` phase (JIT folds inline styles into bound attrs)
|
|
@@ -61,7 +62,7 @@ export function __applyBindings(fragment, bindings, context) {
|
|
|
61
62
|
}
|
|
62
63
|
// ─── Phase 2: Non-structural bindings ────────────────────────────────
|
|
63
64
|
// Order matches bindTemplateDirectives: ref → error → proj → comp →
|
|
64
|
-
// bind → interp → event → class → style → bound → defer
|
|
65
|
+
// bind → interp → event → class → classes → style → bound → defer
|
|
65
66
|
for (const d of (byType.get('ref') ?? [])) {
|
|
66
67
|
const el = pidMap.get(d.pid);
|
|
67
68
|
if (el)
|
|
@@ -77,8 +78,26 @@ export function __applyBindings(fragment, bindings, context) {
|
|
|
77
78
|
}
|
|
78
79
|
for (const d of (byType.get('comp') ?? [])) {
|
|
79
80
|
const el = pidMap.get(d.pid);
|
|
80
|
-
|
|
81
|
+
// `pidMap` is built once, up front. An activated `@error-boundary`
|
|
82
|
+
// detaches its normal children, so a later sibling's placeholder can
|
|
83
|
+
// still be in the map while no longer being in the tree. Rendering it is
|
|
84
|
+
// pointless — and because it can no longer resolve the boundary that
|
|
85
|
+
// already handled the failure, recording its crash would fail a route
|
|
86
|
+
// whose fallback rendered perfectly well. Mirrors the `scope.contains(el)`
|
|
87
|
+
// guard in `bindComponentTags`.
|
|
88
|
+
//
|
|
89
|
+
// This does not affect a structural branch factory binding a detached
|
|
90
|
+
// subtree: that calls `applyBindings` with the branch's OWN fragment as
|
|
91
|
+
// `fragment`, so its placeholders are inside it and still bind.
|
|
92
|
+
if (el && fragment.contains(el)) {
|
|
81
93
|
applyComponent(d, el, ctx, disposers, pidMap);
|
|
94
|
+
}
|
|
95
|
+
else if (el) {
|
|
96
|
+
// Left the tree, so it contributes nothing to the output — and any crash
|
|
97
|
+
// recorded for it on an earlier detached pass is stale. Same reasoning
|
|
98
|
+
// as the `scope.contains(el)` skip in `bindComponentTags`.
|
|
99
|
+
clearSSRRenderCrash(el);
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
for (const d of (byType.get('bind') ?? [])) {
|
|
84
103
|
const el = pidMap.get(d.pid);
|
|
@@ -101,6 +120,11 @@ export function __applyBindings(fragment, bindings, context) {
|
|
|
101
120
|
if (el)
|
|
102
121
|
applyClass(d, el, ctx, disposers);
|
|
103
122
|
}
|
|
123
|
+
for (const d of (byType.get('classes') ?? [])) {
|
|
124
|
+
const el = pidMap.get(d.pid);
|
|
125
|
+
if (el)
|
|
126
|
+
applyClasses(d, el, ctx, disposers);
|
|
127
|
+
}
|
|
104
128
|
for (const d of (byType.get('style') ?? [])) {
|
|
105
129
|
const el = pidMap.get(d.pid);
|
|
106
130
|
if (el)
|
|
@@ -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,eAAe,EACf,aAAa,EACb,QAAQ,EACR,UAAU,EACV,eAAe,EACf,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,UAAU,
|
|
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,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,W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IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI,CAAC;oBACH,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjB,CAAC;gBAAC,MAAM,CAAC;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;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -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":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAmExD,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,GAC3B,IAAI,CA4PN"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { compileExpression } from '../../compile/compileExpression';
|
|
2
|
-
import { boundaryForElement,
|
|
2
|
+
import { boundaryForElement, runWithBoundary, } from '../../compile/binds/bindErrorBoundary';
|
|
3
|
+
import { collectForwardedAttrs, applyForwardedAttrs, } from '../../compile/binds/forwardedAttrs';
|
|
3
4
|
import { nativeTags } from '@pithyjs/compiler';
|
|
5
|
+
import { createRoot, untrack } from '@pithyjs/signals';
|
|
4
6
|
import { nearestCtx } from './helpers';
|
|
5
7
|
import { pithyGlobals } from '../../types/globals';
|
|
8
|
+
import { isSSRMode } from '../../compile/ssrMode';
|
|
9
|
+
import { isRenderableComponentEl } from '../../compile/componentResult';
|
|
10
|
+
import { clearSSRRenderCrash, reportComponentFailure, } from '../../compile/ssrCrashes';
|
|
6
11
|
/** Map kebab-case or lowered DOM attr name to expected camelCase prop name. */
|
|
7
12
|
function normalizePropName(authored, expectedProps) {
|
|
8
13
|
if (expectedProps.length === 0)
|
|
@@ -56,12 +61,19 @@ export function applyComponent(d, el, ctx, disposers, pidMap) {
|
|
|
56
61
|
const tagLower = d.tag.toLowerCase();
|
|
57
62
|
if (d.tag === tagLower && nativeTags.has(tagLower))
|
|
58
63
|
return;
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
// Exact case first: the context holds the template's own locals alongside its
|
|
65
|
+
// components, so a prop named `icon` sits next to the `Icon` component and
|
|
66
|
+
// collides case-insensitively. The JIT path lowercases into a Map, where the
|
|
67
|
+
// components — appended last — overwrite the locals; matching that ordering is
|
|
68
|
+
// why `<Icon>` resolves in dev, and breaking on the first match is why it did
|
|
69
|
+
// not in a build. Falling back last-wins keeps the two paths agreeing.
|
|
70
|
+
let candidate = Object.prototype.hasOwnProperty.call(ctx, d.tag)
|
|
71
|
+
? ctx[d.tag]
|
|
72
|
+
: undefined;
|
|
73
|
+
if (candidate === undefined) {
|
|
74
|
+
for (const key of Object.keys(ctx)) {
|
|
75
|
+
if (key.toLowerCase() === tagLower)
|
|
76
|
+
candidate = ctx[key];
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
if (!candidate)
|
|
@@ -85,7 +97,7 @@ export function applyComponent(d, el, ctx, disposers, pidMap) {
|
|
|
85
97
|
const propName = normalizePropName(rawName, expectedProps);
|
|
86
98
|
try {
|
|
87
99
|
const fn = compileExpression(expr, localCtx);
|
|
88
|
-
props[propName] = fn
|
|
100
|
+
props[propName] = untrack(fn);
|
|
89
101
|
}
|
|
90
102
|
catch {
|
|
91
103
|
// Leave undefined — child uses defaults
|
|
@@ -105,7 +117,21 @@ export function applyComponent(d, el, ctx, disposers, pidMap) {
|
|
|
105
117
|
slotGroups.set(slotName, []);
|
|
106
118
|
slotGroups.get(slotName).push(child);
|
|
107
119
|
}
|
|
120
|
+
// AOT has no runtime AST, so default-slot content reaches the component two
|
|
121
|
+
// ways: `renderChildren()` reads the injection fragment off the global, and
|
|
122
|
+
// `<slot>` reads it through the slot map. Both must reference the SAME
|
|
123
|
+
// fragment — a DOM node lives in one place, so two fragments would let the
|
|
124
|
+
// later consumer steal the nodes out of the first.
|
|
125
|
+
let injection;
|
|
108
126
|
for (const [slotName, nodes] of slotGroups) {
|
|
127
|
+
if (slotName === '') {
|
|
128
|
+
injection = document.createDocumentFragment();
|
|
129
|
+
for (const node of nodes)
|
|
130
|
+
injection.appendChild(node);
|
|
131
|
+
const shared = injection;
|
|
132
|
+
slotMap.set('', () => shared);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
109
135
|
slotMap.set(slotName, () => {
|
|
110
136
|
const frag = document.createDocumentFragment();
|
|
111
137
|
for (const node of nodes) {
|
|
@@ -114,45 +140,92 @@ export function applyComponent(d, el, ctx, disposers, pidMap) {
|
|
|
114
140
|
return frag;
|
|
115
141
|
});
|
|
116
142
|
}
|
|
117
|
-
const componentContext = {
|
|
143
|
+
const componentContext = {
|
|
144
|
+
...localCtx,
|
|
145
|
+
__slotMap: slotMap,
|
|
146
|
+
__childAstNodes: undefined,
|
|
147
|
+
__childFactory: d.children,
|
|
148
|
+
};
|
|
118
149
|
// Find nearest error boundary
|
|
119
150
|
const boundaryEl = el.closest('[data-error]');
|
|
120
151
|
const boundary = boundaryForElement(boundaryEl);
|
|
121
152
|
let out;
|
|
153
|
+
let disposeSetup;
|
|
122
154
|
try {
|
|
123
155
|
out = runWithBoundary(boundary, () => {
|
|
124
156
|
const g = pithyGlobals();
|
|
125
157
|
const originalContext = g.__pithyComponentContext;
|
|
126
158
|
const wasRendering = g.__pithyRenderingComponent;
|
|
159
|
+
const prevInjection = g.__pithyProjectedChildren;
|
|
127
160
|
g.__pithyComponentContext = componentContext;
|
|
128
161
|
g.__pithyRenderingComponent = true;
|
|
162
|
+
g.__pithyProjectedChildren = injection;
|
|
129
163
|
try {
|
|
130
|
-
return
|
|
164
|
+
return createRoot(disposeRoot => {
|
|
165
|
+
disposeSetup = disposeRoot;
|
|
166
|
+
return componentFn(props);
|
|
167
|
+
});
|
|
131
168
|
}
|
|
132
169
|
finally {
|
|
133
170
|
g.__pithyComponentContext = originalContext;
|
|
134
171
|
g.__pithyRenderingComponent = wasRendering;
|
|
172
|
+
g.__pithyProjectedChildren = prevInjection;
|
|
135
173
|
}
|
|
136
174
|
});
|
|
137
175
|
}
|
|
138
176
|
catch (err) {
|
|
139
177
|
if (boundary) {
|
|
140
|
-
|
|
178
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
179
|
+
// See `setBoundaryError`: an already-active boundary with no free ancestor
|
|
180
|
+
// drops the error rather than taking it, which is the normal case for a
|
|
181
|
+
// component rendering inside that boundary's `@fallback`.
|
|
182
|
+
reportComponentFailure(el, d.tag, error, boundary);
|
|
141
183
|
return;
|
|
142
184
|
}
|
|
185
|
+
// No boundary in scope *yet*. Degrade in both modes — an AOT branch
|
|
186
|
+
// factory renders detached, so `closest()` here cannot see a boundary the
|
|
187
|
+
// element will sit under once the branch is inserted, and throwing would
|
|
188
|
+
// only be swallowed by the structural handler's own catch
|
|
189
|
+
// (`applyStructural.ts`) anyway.
|
|
190
|
+
//
|
|
191
|
+
// A static/server render records the crash instead: dropping the component
|
|
192
|
+
// silently shipped HTML with <${d.tag}> left raw while `pithy-ssg` counted
|
|
193
|
+
// the route as rendered and exited 0 (BUG-018). Anything still recorded
|
|
194
|
+
// when the render finishes fails the route.
|
|
195
|
+
//
|
|
196
|
+
// Note this path cannot reach a boundary at all when the element is inside
|
|
197
|
+
// a detached structural branch: `el.closest('[data-error]')` above found
|
|
198
|
+
// nothing, and no later pass re-binds it, so the boundary never receives
|
|
199
|
+
// the error even though the nodes are inserted underneath it. That is
|
|
200
|
+
// BUG-023; recording is what stops it from shipping silently.
|
|
201
|
+
reportComponentFailure(el, d.tag, err instanceof Error ? err : new Error(String(err)), null);
|
|
143
202
|
console.error(`[AOT] Component <${d.tag}> crashed:`, err);
|
|
144
203
|
return;
|
|
145
204
|
}
|
|
146
|
-
if (!out ||
|
|
205
|
+
if (!out ||
|
|
206
|
+
typeof out !== 'object' ||
|
|
207
|
+
!('el' in out) ||
|
|
208
|
+
!isRenderableComponentEl(out.el, el)) {
|
|
209
|
+
// Not a throw, but the same outcome: the raw <${d.tag}> is left in place
|
|
210
|
+
// and the subtree never renders, which under SSR is content silently
|
|
211
|
+
// missing from the emitted HTML. Recorded exactly like a crash (BUG-018).
|
|
212
|
+
// Same funnel as a throw — see `bindComponentTags`. Recording without
|
|
213
|
+
// offering it to the boundary left an AOT component under `@error-boundary`
|
|
214
|
+
// failing its route with the boundary signal unset.
|
|
215
|
+
reportComponentFailure(el, d.tag, new Error(`Invalid render result from <${d.tag}>; expected { el, destroy }`), boundary);
|
|
216
|
+
disposeSetup?.();
|
|
147
217
|
return;
|
|
218
|
+
}
|
|
148
219
|
const { el: renderedEl, destroy } = out;
|
|
149
220
|
// Capture rendered root element before fragment is consumed by replaceWith
|
|
150
221
|
const forwardedClass = el.getAttribute('class');
|
|
222
|
+
const forwardedAttrs = collectForwardedAttrs(el);
|
|
151
223
|
const renderedRoot = renderedEl instanceof DocumentFragment
|
|
152
224
|
? renderedEl.firstElementChild
|
|
153
225
|
: renderedEl instanceof HTMLElement
|
|
154
226
|
? renderedEl
|
|
155
227
|
: null;
|
|
228
|
+
let replaced = true;
|
|
156
229
|
try {
|
|
157
230
|
if (renderedEl instanceof DocumentFragment) {
|
|
158
231
|
el.replaceWith(...Array.from(renderedEl.childNodes));
|
|
@@ -162,14 +235,26 @@ export function applyComponent(d, el, ctx, disposers, pidMap) {
|
|
|
162
235
|
}
|
|
163
236
|
}
|
|
164
237
|
catch (err) {
|
|
238
|
+
// The raw <${d.tag}> is left exactly where a crash would have left it, so
|
|
239
|
+
// this is the same content loss and is recorded the same way.
|
|
240
|
+
replaced = false;
|
|
241
|
+
reportComponentFailure(el, d.tag, err instanceof Error ? err : new Error(String(err)), boundary);
|
|
165
242
|
console.error(`[AOT] Failed to replace <${d.tag}>:`, err);
|
|
166
243
|
}
|
|
244
|
+
// Retracted only here, and in the boundary catch above. This is the point at
|
|
245
|
+
// which the component is known to have produced a usable node AND to have
|
|
246
|
+
// reached the document.
|
|
247
|
+
if (isSSRMode() && replaced)
|
|
248
|
+
clearSSRRenderCrash(el);
|
|
167
249
|
if (forwardedClass && renderedRoot) {
|
|
168
250
|
for (const cls of forwardedClass.split(/\s+/)) {
|
|
169
251
|
if (cls)
|
|
170
252
|
renderedRoot.classList.add(cls);
|
|
171
253
|
}
|
|
172
254
|
}
|
|
255
|
+
if (forwardedAttrs.length > 0 && renderedRoot) {
|
|
256
|
+
applyForwardedAttrs(renderedRoot, forwardedAttrs, d.tag);
|
|
257
|
+
}
|
|
173
258
|
// Re-target the component pid to the rendered root so subsequent binding
|
|
174
259
|
// passes (event, bound, class, style) apply to the component's actual DOM
|
|
175
260
|
// element. This matches the JIT path where data-on-* attributes are
|
|
@@ -179,11 +264,15 @@ export function applyComponent(d, el, ctx, disposers, pidMap) {
|
|
|
179
264
|
}
|
|
180
265
|
else {
|
|
181
266
|
if (import.meta.env?.DEV &&
|
|
182
|
-
(forwardedClass ||
|
|
267
|
+
(forwardedClass ||
|
|
268
|
+
forwardedAttrs.length > 0 ||
|
|
269
|
+
(d.props && Object.keys(d.props).length > 0))) {
|
|
183
270
|
console.warn(`[AOT] <${d.tag}> has forwarded attributes but returns a fragment with no single root element — forwarding skipped.`);
|
|
184
271
|
}
|
|
185
272
|
pidMap.delete(d.pid);
|
|
186
273
|
}
|
|
274
|
+
if (disposeSetup)
|
|
275
|
+
disposers.push(disposeSetup);
|
|
187
276
|
if (typeof destroy === 'function')
|
|
188
277
|
disposers.push(destroy);
|
|
189
278
|
}
|