tempo-sdk 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -2
- package/dist/assets/editor.d.ts +79 -0
- package/dist/assets/editor.js +571 -0
- package/dist/assets/editor.js.map +1 -0
- package/dist/assets/index.d.ts +83 -0
- package/dist/assets/index.js +26 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/parser.d.ts +78 -0
- package/dist/assets/parser.js +29 -0
- package/dist/assets/parser.js.map +1 -0
- package/dist/canvas/editor.js +1 -1
- package/dist/canvas/index.d.ts +99 -16
- package/dist/canvas/index.js +1427 -661
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.d.ts +8 -0
- package/dist/canvas/interact-projection.js +2848 -0
- package/dist/canvas/interact-projection.js.map +1 -0
- package/dist/canvas/parser.d.ts +25 -1
- package/dist/canvas/parser.js +3 -1
- package/dist/{chunk-6Q4I3RFN.js → chunk-GBKYTBEE.js} +242 -33
- package/dist/chunk-GBKYTBEE.js.map +1 -0
- package/dist/chunk-IWULHYPW.js +650 -0
- package/dist/chunk-IWULHYPW.js.map +1 -0
- package/dist/chunk-QXB32HG4.js +11 -0
- package/dist/chunk-QXB32HG4.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +601 -20
- package/dist/index.js.map +1 -1
- package/dist/types-B-dRoF2T.d.ts +102 -0
- package/package.json +19 -2
- package/dist/chunk-6Q4I3RFN.js.map +0 -1
package/dist/canvas/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TEMPO_INTERACT_FRAME_NAME,
|
|
3
|
+
isTempoInteractFrameName
|
|
4
|
+
} from "../chunk-QXB32HG4.js";
|
|
5
|
+
|
|
1
6
|
// canvas/canvas.tsx
|
|
2
7
|
import {
|
|
3
8
|
Children,
|
|
@@ -40,7 +45,8 @@ function Canvas({
|
|
|
40
45
|
name,
|
|
41
46
|
path,
|
|
42
47
|
backgroundColor,
|
|
43
|
-
defaultViewport
|
|
48
|
+
defaultViewport,
|
|
49
|
+
...sourceAnnotations
|
|
44
50
|
}) {
|
|
45
51
|
const contextIdentity = useCanvasIdentity();
|
|
46
52
|
const canvasName = normalizeId(name, "Canvas name");
|
|
@@ -64,6 +70,7 @@ function Canvas({
|
|
|
64
70
|
return /* @__PURE__ */ jsx(CanvasIdentityContext.Provider, { value: identity, children: /* @__PURE__ */ jsx(
|
|
65
71
|
"div",
|
|
66
72
|
{
|
|
73
|
+
...sourceAnnotations,
|
|
67
74
|
"data-tempo-canvas": canvasName,
|
|
68
75
|
"data-tempo-canvas-path": canvasPath,
|
|
69
76
|
"data-tempo-canvas-background": backgroundColor,
|
|
@@ -82,10 +89,40 @@ function CanvasContext({
|
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
// canvas/canvas-host.tsx
|
|
92
|
+
import { useMemo as useMemo4 } from "react";
|
|
93
|
+
|
|
94
|
+
// canvas/canvas-import-boundary.tsx
|
|
85
95
|
import {
|
|
86
|
-
|
|
96
|
+
Component,
|
|
97
|
+
lazy,
|
|
98
|
+
Suspense,
|
|
99
|
+
useCallback as useCallback2,
|
|
100
|
+
useEffect,
|
|
101
|
+
useLayoutEffect,
|
|
102
|
+
useMemo as useMemo2,
|
|
103
|
+
useRef,
|
|
104
|
+
useState
|
|
87
105
|
} from "react";
|
|
88
106
|
|
|
107
|
+
// canvas/host-recovery-feed.ts
|
|
108
|
+
var FEED_KEY = "__tempoCanvasHostRecoveryFeed";
|
|
109
|
+
function createFeed() {
|
|
110
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
111
|
+
return {
|
|
112
|
+
publish(event) {
|
|
113
|
+
for (const listener of [...listeners]) listener(event);
|
|
114
|
+
},
|
|
115
|
+
subscribe(listener) {
|
|
116
|
+
listeners.add(listener);
|
|
117
|
+
return () => listeners.delete(listener);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function getCanvasHostRecoveryFeed() {
|
|
122
|
+
const globals = globalThis;
|
|
123
|
+
return globals[FEED_KEY] ?? (globals[FEED_KEY] = createFeed());
|
|
124
|
+
}
|
|
125
|
+
|
|
89
126
|
// canvas/runtime-context.ts
|
|
90
127
|
import { createContext as createContext2, useCallback, useContext as useContext2 } from "react";
|
|
91
128
|
var CanvasHostContext = createContext2(null);
|
|
@@ -115,6 +152,13 @@ function useStoryboardRendered(storyboardId) {
|
|
|
115
152
|
host.markStoryboardRendered(renderId);
|
|
116
153
|
}, [host, renderId]);
|
|
117
154
|
}
|
|
155
|
+
function useStoryboardUnmounted(storyboardId) {
|
|
156
|
+
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
157
|
+
const { markStoryboardUnmounted } = useRequiredCanvasHost();
|
|
158
|
+
return useCallback(() => {
|
|
159
|
+
markStoryboardUnmounted(renderId);
|
|
160
|
+
}, [markStoryboardUnmounted, renderId]);
|
|
161
|
+
}
|
|
118
162
|
function useStoryboardErrorReporter(storyboardId) {
|
|
119
163
|
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
120
164
|
const host = useRequiredCanvasHost();
|
|
@@ -140,8 +184,109 @@ function useStoryboardPlacement(storyboardId) {
|
|
|
140
184
|
return host.getStoryboardPlacement(renderId);
|
|
141
185
|
}
|
|
142
186
|
|
|
187
|
+
// canvas/canvas-import-boundary.tsx
|
|
188
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
189
|
+
var CanvasImportErrorBoundary = class extends Component {
|
|
190
|
+
constructor() {
|
|
191
|
+
super(...arguments);
|
|
192
|
+
this.state = { hasError: false };
|
|
193
|
+
}
|
|
194
|
+
static getDerivedStateFromError() {
|
|
195
|
+
return { hasError: true };
|
|
196
|
+
}
|
|
197
|
+
componentDidCatch(error, info) {
|
|
198
|
+
this.props.reportError({
|
|
199
|
+
message: error instanceof Error ? error.message : String(error),
|
|
200
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
201
|
+
componentStack: info.componentStack ?? void 0
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
render() {
|
|
205
|
+
return this.state.hasError ? null : this.props.children;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function CanvasCommitSignal({ onCommit }) {
|
|
209
|
+
const onCommitRef = useRef(onCommit);
|
|
210
|
+
const didCommitRef = useRef(false);
|
|
211
|
+
onCommitRef.current = onCommit;
|
|
212
|
+
useLayoutEffect(() => {
|
|
213
|
+
if (didCommitRef.current) return;
|
|
214
|
+
didCommitRef.current = true;
|
|
215
|
+
onCommitRef.current();
|
|
216
|
+
}, []);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function CanvasImportBoundary({
|
|
220
|
+
canvasPath,
|
|
221
|
+
load
|
|
222
|
+
}) {
|
|
223
|
+
const {
|
|
224
|
+
clearCanvasImportError,
|
|
225
|
+
registerCanvasProblemScope,
|
|
226
|
+
reportCanvasImportError
|
|
227
|
+
} = useRequiredCanvasHost();
|
|
228
|
+
const failedRef = useRef(false);
|
|
229
|
+
const loadRef = useRef(load);
|
|
230
|
+
const previousLoadRef = useRef(load);
|
|
231
|
+
loadRef.current = load;
|
|
232
|
+
const [retryRevision, setRetryRevision] = useState(0);
|
|
233
|
+
const lazyIdentity = `${canvasPath}:${retryRevision}`;
|
|
234
|
+
const LazyCanvas = useMemo2(() => {
|
|
235
|
+
void lazyIdentity;
|
|
236
|
+
return lazy(
|
|
237
|
+
() => loadRef.current().catch((error) => {
|
|
238
|
+
getCanvasHostRecoveryFeed().publish({
|
|
239
|
+
type: "module-load-failure",
|
|
240
|
+
path: canvasPath,
|
|
241
|
+
message: error instanceof Error ? error.message : String(error)
|
|
242
|
+
});
|
|
243
|
+
throw error;
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
}, [lazyIdentity, canvasPath]);
|
|
247
|
+
const reportError = useCallback2(
|
|
248
|
+
(error) => {
|
|
249
|
+
failedRef.current = true;
|
|
250
|
+
reportCanvasImportError(canvasPath, error);
|
|
251
|
+
},
|
|
252
|
+
[canvasPath, reportCanvasImportError]
|
|
253
|
+
);
|
|
254
|
+
const markCommitted = useCallback2(() => {
|
|
255
|
+
failedRef.current = false;
|
|
256
|
+
clearCanvasImportError(canvasPath);
|
|
257
|
+
}, [canvasPath, clearCanvasImportError]);
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
const loadChanged = previousLoadRef.current !== load;
|
|
260
|
+
previousLoadRef.current = load;
|
|
261
|
+
if (loadChanged && failedRef.current) {
|
|
262
|
+
setRetryRevision((revision) => revision + 1);
|
|
263
|
+
}
|
|
264
|
+
}, [load]);
|
|
265
|
+
useEffect(
|
|
266
|
+
() => () => {
|
|
267
|
+
clearCanvasImportError(canvasPath);
|
|
268
|
+
},
|
|
269
|
+
[canvasPath, clearCanvasImportError]
|
|
270
|
+
);
|
|
271
|
+
useEffect(
|
|
272
|
+
() => registerCanvasProblemScope(canvasPath),
|
|
273
|
+
[canvasPath, registerCanvasProblemScope]
|
|
274
|
+
);
|
|
275
|
+
return /* @__PURE__ */ jsx2(CanvasImportErrorBoundary, { reportError, children: /* @__PURE__ */ jsx2(Suspense, { fallback: null, children: /* @__PURE__ */ jsxs(CanvasContext, { path: canvasPath, children: [
|
|
276
|
+
/* @__PURE__ */ jsx2(LazyCanvas, {}),
|
|
277
|
+
/* @__PURE__ */ jsx2(CanvasCommitSignal, { onCommit: markCommitted })
|
|
278
|
+
] }) }) }, retryRevision);
|
|
279
|
+
}
|
|
280
|
+
|
|
143
281
|
// canvas/use-canvas-host-postmessage.ts
|
|
144
|
-
import {
|
|
282
|
+
import {
|
|
283
|
+
useCallback as useCallback3,
|
|
284
|
+
useEffect as useEffect2,
|
|
285
|
+
useLayoutEffect as useLayoutEffect2,
|
|
286
|
+
useMemo as useMemo3,
|
|
287
|
+
useRef as useRef2,
|
|
288
|
+
useState as useState2
|
|
289
|
+
} from "react";
|
|
145
290
|
|
|
146
291
|
// canvas/canvas-host-runtime.ts
|
|
147
292
|
function getCanvasHostRuntime() {
|
|
@@ -455,7 +600,10 @@ function trackStoryboardPortals(renderId, element, status) {
|
|
|
455
600
|
var escapeRenderId = (renderId) => renderId.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
456
601
|
var buildRenderSelector = (renderId) => `[data-render-id="${escapeRenderId(renderId)}"]`;
|
|
457
602
|
var buildRenderContentSelector = (renderId) => `[data-render-content="${escapeRenderId(renderId)}"]`;
|
|
458
|
-
var buildRenderContentFiberSelector = (renderId) =>
|
|
603
|
+
var buildRenderContentFiberSelector = (renderId) => [
|
|
604
|
+
`${buildRenderContentSelector(renderId)} > :not([data-tempo-hide-fiber="true"])`,
|
|
605
|
+
`${buildRenderContentSelector(renderId)}:not(:has(> *))`
|
|
606
|
+
].join(", ");
|
|
459
607
|
function stripRenderContentWrapperAttributes(capture, renderId) {
|
|
460
608
|
if (!capture || typeof capture !== "object") return capture;
|
|
461
609
|
const dom = capture.dom;
|
|
@@ -483,12 +631,17 @@ function stripRenderContentWrapperFromCombinedCapture(capture, renderId) {
|
|
|
483
631
|
html: stripRenderContentWrapperAttributes(html, renderId)
|
|
484
632
|
};
|
|
485
633
|
}
|
|
486
|
-
|
|
634
|
+
var nextAnimationFrame = () => new Promise((resolve) => {
|
|
635
|
+
requestAnimationFrame(() => resolve());
|
|
636
|
+
});
|
|
637
|
+
async function captureStoryboardImage(renderId, options) {
|
|
487
638
|
const portalSelectors = [
|
|
488
639
|
...options?.portalSelectors ?? [],
|
|
489
640
|
...getStoryboardPortalSelectors(renderId)
|
|
490
641
|
];
|
|
491
|
-
|
|
642
|
+
await nextAnimationFrame();
|
|
643
|
+
await nextAnimationFrame();
|
|
644
|
+
return await getCanvasHostRuntime().captureSelector(
|
|
492
645
|
buildRenderSelector(renderId),
|
|
493
646
|
portalSelectors.length > 0 ? { ...options, portalSelectors: [...new Set(portalSelectors)] } : options
|
|
494
647
|
);
|
|
@@ -553,6 +706,87 @@ function watchStoryboardCombined(renderId, options) {
|
|
|
553
706
|
});
|
|
554
707
|
}
|
|
555
708
|
|
|
709
|
+
// canvas/canvas-host-legacy-compat.ts
|
|
710
|
+
var sourceAnnotationSelector = "[data-tempo-source-file], [data-tempo-source-loc], [data-tempo-filepath], [data-tempo-html-filepath]";
|
|
711
|
+
function getObservedSourceFiles(slot) {
|
|
712
|
+
if (!slot) return [];
|
|
713
|
+
return [
|
|
714
|
+
...new Set(
|
|
715
|
+
[...slot.querySelectorAll(sourceAnnotationSelector)].flatMap((element) => [
|
|
716
|
+
element.getAttribute("data-tempo-source-file"),
|
|
717
|
+
element.getAttribute("data-tempo-filepath"),
|
|
718
|
+
element.getAttribute("data-tempo-html-filepath"),
|
|
719
|
+
element.getAttribute("data-tempo-source-loc")
|
|
720
|
+
]).filter((file) => Boolean(file))
|
|
721
|
+
)
|
|
722
|
+
];
|
|
723
|
+
}
|
|
724
|
+
function latestTimestamp(values) {
|
|
725
|
+
let latest = null;
|
|
726
|
+
for (const value of values.values()) {
|
|
727
|
+
latest = latest === null ? value : Math.max(latest, value);
|
|
728
|
+
}
|
|
729
|
+
return latest;
|
|
730
|
+
}
|
|
731
|
+
function isReactConnected() {
|
|
732
|
+
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
733
|
+
return (hook?.renderers?.size ?? 0) > 0;
|
|
734
|
+
}
|
|
735
|
+
function createLegacyHostHealth() {
|
|
736
|
+
const renderCommitTimes = /* @__PURE__ */ new Map();
|
|
737
|
+
const sourceAnnotatedCommitTimes = /* @__PURE__ */ new Map();
|
|
738
|
+
const recordSourceAnnotatedCommit = (renderId, observedAt = Date.now()) => {
|
|
739
|
+
const slot = document.querySelector(buildRenderContentSelector(renderId));
|
|
740
|
+
if (getObservedSourceFiles(slot).length > 0) {
|
|
741
|
+
sourceAnnotatedCommitTimes.set(renderId, observedAt);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
return {
|
|
745
|
+
recordRenderCommit(renderId) {
|
|
746
|
+
const committedAt = Date.now();
|
|
747
|
+
renderCommitTimes.set(renderId, committedAt);
|
|
748
|
+
recordSourceAnnotatedCommit(renderId, committedAt);
|
|
749
|
+
},
|
|
750
|
+
recordSourceAnnotatedCommit(renderId) {
|
|
751
|
+
recordSourceAnnotatedCommit(renderId);
|
|
752
|
+
},
|
|
753
|
+
forgetRender(renderId) {
|
|
754
|
+
renderCommitTimes.delete(renderId);
|
|
755
|
+
sourceAnnotatedCommitTimes.delete(renderId);
|
|
756
|
+
},
|
|
757
|
+
buildSnapshot(renderId, context) {
|
|
758
|
+
const slot = renderId ? document.querySelector(buildRenderContentSelector(renderId)) : null;
|
|
759
|
+
const observedSourceFiles = getObservedSourceFiles(slot);
|
|
760
|
+
return {
|
|
761
|
+
alive: true,
|
|
762
|
+
reactConnected: isReactConnected() || renderCommitTimes.size > 0 || context.hasRenderEntries,
|
|
763
|
+
documentReadyState: document.readyState,
|
|
764
|
+
hasViteOverlayElement: document.querySelector("vite-error-overlay") !== null,
|
|
765
|
+
lastHostRenderCommitAt: latestTimestamp(renderCommitTimes),
|
|
766
|
+
lastClaimRenderCommitAt: renderCommitTimes.get(renderId) ?? null,
|
|
767
|
+
lastHostSourceAnnotatedCommitAt: latestTimestamp(
|
|
768
|
+
sourceAnnotatedCommitTimes
|
|
769
|
+
),
|
|
770
|
+
lastClaimSourceAnnotatedCommitAt: sourceAnnotatedCommitTimes.get(renderId) ?? null,
|
|
771
|
+
renderSlotExists: slot !== null,
|
|
772
|
+
renderSlotHasSourceAnnotatedContent: observedSourceFiles.length > 0,
|
|
773
|
+
renderSlotObservedSourceFiles: observedSourceFiles,
|
|
774
|
+
claimErrorBoundaryTripped: context.claimErrorBoundaryTripped,
|
|
775
|
+
observedAt: Date.now()
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
function applyLegacyRenderIsolation(renderId) {
|
|
781
|
+
document.querySelector("[data-render-isolation]")?.remove();
|
|
782
|
+
if (!renderId) return;
|
|
783
|
+
const style = document.createElement("style");
|
|
784
|
+
style.setAttribute("data-render-isolation", "");
|
|
785
|
+
const escapedId = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(renderId) : renderId;
|
|
786
|
+
style.textContent = '[data-render-id]:not([data-render-id="' + escapedId + '"]) { opacity: 0 !important; pointer-events: none !important; }';
|
|
787
|
+
document.head.appendChild(style);
|
|
788
|
+
}
|
|
789
|
+
|
|
556
790
|
// canvas/canvas-host-protocol.ts
|
|
557
791
|
function isRecord(value) {
|
|
558
792
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -570,15 +804,22 @@ var readTrimmedString = (value) => {
|
|
|
570
804
|
const normalized = value.trim();
|
|
571
805
|
return normalized.length > 0 ? normalized : void 0;
|
|
572
806
|
};
|
|
807
|
+
var readStringArray = (value) => {
|
|
808
|
+
if (!Array.isArray(value)) return void 0;
|
|
809
|
+
const values = value.map(readTrimmedString).filter((entry) => entry !== void 0);
|
|
810
|
+
return values.length > 0 ? [...new Set(values)] : void 0;
|
|
811
|
+
};
|
|
573
812
|
function resolveRenderTarget(payload) {
|
|
574
813
|
const explicitRenderId = readTrimmedString(payload.renderId);
|
|
575
814
|
const canvasPath = readTrimmedString(payload.canvasPath);
|
|
576
815
|
const storyboardId = readTrimmedString(payload.storyboardId);
|
|
816
|
+
const sourcePaths = readStringArray(payload.sourcePaths);
|
|
577
817
|
const renderId = explicitRenderId || (canvasPath && storyboardId ? getCanvasStoryboardRenderId(canvasPath, storyboardId) : storyboardId);
|
|
578
818
|
return renderId ? {
|
|
579
819
|
renderId,
|
|
580
820
|
...canvasPath ? { canvasPath } : {},
|
|
581
|
-
...storyboardId ? { storyboardId } : {}
|
|
821
|
+
...storyboardId ? { storyboardId } : {},
|
|
822
|
+
...sourcePaths ? { sourcePaths } : {}
|
|
582
823
|
} : null;
|
|
583
824
|
}
|
|
584
825
|
function requireRenderTarget(commandType, payload) {
|
|
@@ -638,6 +879,9 @@ var propsMatch = (a, b) => JSON.stringify(a ?? {}) === JSON.stringify(b ?? {});
|
|
|
638
879
|
function renderRequestMatchesEntry(entry, request) {
|
|
639
880
|
return entry?.importPath === request.importPath && entry.importName === request.importName && entry.width === request.width && entry.height === request.height && entry.intrinsicSize === request.intrinsicSize && propsMatch(entry.props, request.props);
|
|
640
881
|
}
|
|
882
|
+
function renderRequestTargetsEntry(entry, request) {
|
|
883
|
+
return entry?.importPath === request.importPath && entry.importName === request.importName && propsMatch(entry.props, request.props);
|
|
884
|
+
}
|
|
641
885
|
function acquireRender(entries, request) {
|
|
642
886
|
const next = new Map(entries);
|
|
643
887
|
const current = next.get(request.renderId);
|
|
@@ -705,26 +949,210 @@ function buildRenderSizeMap(entries) {
|
|
|
705
949
|
);
|
|
706
950
|
}
|
|
707
951
|
|
|
952
|
+
// canvas/source-identity.ts
|
|
953
|
+
function normalizeSourceIdentity(value) {
|
|
954
|
+
let normalized = value.trim().replace(/\\/g, "/");
|
|
955
|
+
const suffixIndex = normalized.search(/[?#]/);
|
|
956
|
+
if (suffixIndex !== -1) normalized = normalized.slice(0, suffixIndex);
|
|
957
|
+
try {
|
|
958
|
+
normalized = decodeURIComponent(normalized);
|
|
959
|
+
} catch {
|
|
960
|
+
}
|
|
961
|
+
normalized = normalized.replace(/^file:\/\//, "").replace(/^\/@fs\//, "/");
|
|
962
|
+
return normalized.replace(/^\.\//, "").replace(/\/{2,}/g, "/");
|
|
963
|
+
}
|
|
964
|
+
function distinctSourceIdentities(paths) {
|
|
965
|
+
return [
|
|
966
|
+
...new Set(
|
|
967
|
+
paths.map(normalizeSourceIdentity).filter((path) => path.length)
|
|
968
|
+
)
|
|
969
|
+
];
|
|
970
|
+
}
|
|
971
|
+
function normalizeDiagnosticText(value) {
|
|
972
|
+
const normalized = value.replace(/\\/g, "/");
|
|
973
|
+
try {
|
|
974
|
+
return decodeURIComponent(normalized).replace(/\bhttps?:\/\/[^/\s)]+/g, "").replace(/\/@fs\//g, "/");
|
|
975
|
+
} catch {
|
|
976
|
+
return normalized.replace(/\bhttps?:\/\/[^/\s)]+/g, "").replace(/\/@fs\//g, "/");
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
function isPathCharacter(value) {
|
|
980
|
+
return /[A-Za-z0-9._@+-]/.test(value);
|
|
981
|
+
}
|
|
982
|
+
function textMentionsPathSuffix(text, suffix) {
|
|
983
|
+
let fromIndex = 0;
|
|
984
|
+
while (fromIndex < text.length) {
|
|
985
|
+
const index = text.indexOf(suffix, fromIndex);
|
|
986
|
+
if (index < 0) return false;
|
|
987
|
+
const before = index === 0 ? "" : text[index - 1];
|
|
988
|
+
const after = text[index + suffix.length] ?? "";
|
|
989
|
+
if ((before === "" || before === "/" || !isPathCharacter(before)) && (after === "" || !isPathCharacter(after))) {
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
fromIndex = index + 1;
|
|
993
|
+
}
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
function textMentionsExactPath(text, path) {
|
|
997
|
+
let fromIndex = 0;
|
|
998
|
+
while (fromIndex < text.length) {
|
|
999
|
+
const index = text.indexOf(path, fromIndex);
|
|
1000
|
+
if (index < 0) return false;
|
|
1001
|
+
const before = index === 0 ? "" : text[index - 1];
|
|
1002
|
+
const after = text[index + path.length] ?? "";
|
|
1003
|
+
if ((before === "" || before !== "/" && !isPathCharacter(before)) && (after === "" || after !== "/" && !isPathCharacter(after))) {
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
fromIndex = index + 1;
|
|
1007
|
+
}
|
|
1008
|
+
return false;
|
|
1009
|
+
}
|
|
1010
|
+
function projectRootSpellings(projectRoot) {
|
|
1011
|
+
const spellings = [projectRoot];
|
|
1012
|
+
if (/^\/(?:var|tmp)\//.test(projectRoot)) {
|
|
1013
|
+
spellings.push(`/private${projectRoot}`);
|
|
1014
|
+
} else if (/^\/private\/(?:var|tmp)\//.test(projectRoot)) {
|
|
1015
|
+
spellings.push(projectRoot.slice("/private".length));
|
|
1016
|
+
}
|
|
1017
|
+
return spellings;
|
|
1018
|
+
}
|
|
1019
|
+
function rootedDiagnosticAliases(identityValue, projectRootValue) {
|
|
1020
|
+
const identity = normalizeSourceIdentity(identityValue);
|
|
1021
|
+
const projectRoot = normalizeSourceIdentity(projectRootValue).replace(
|
|
1022
|
+
/\/+$/,
|
|
1023
|
+
""
|
|
1024
|
+
);
|
|
1025
|
+
if (!identity || !projectRoot) return [];
|
|
1026
|
+
const roots = projectRootSpellings(projectRoot);
|
|
1027
|
+
const rootPrefix = roots.find((root) => identity.startsWith(`${root}/`));
|
|
1028
|
+
const relative = rootPrefix ? identity.slice(rootPrefix.length + 1) : identity.startsWith("/") ? identity.slice(1) : identity;
|
|
1029
|
+
return [
|
|
1030
|
+
.../* @__PURE__ */ new Set([
|
|
1031
|
+
relative,
|
|
1032
|
+
`/${relative}`,
|
|
1033
|
+
...roots.map((root) => `${root}/${relative}`)
|
|
1034
|
+
])
|
|
1035
|
+
];
|
|
1036
|
+
}
|
|
1037
|
+
function matchingDiagnosticSegments(text, identity) {
|
|
1038
|
+
const segments = identity.split("/").filter(Boolean);
|
|
1039
|
+
for (let count = segments.length; count >= 2; count -= 1) {
|
|
1040
|
+
if (textMentionsPathSuffix(text, segments.slice(-count).join("/"))) {
|
|
1041
|
+
return count;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
return 0;
|
|
1045
|
+
}
|
|
1046
|
+
function resolveUniqueDiagnosticSourceMatches(textValue, candidates, options = {}) {
|
|
1047
|
+
const text = normalizeDiagnosticText(textValue);
|
|
1048
|
+
if (!text) return [];
|
|
1049
|
+
const projectRoot = options.projectRoot?.trim();
|
|
1050
|
+
if (projectRoot) {
|
|
1051
|
+
const exactMatches = candidates.filter((candidate) => {
|
|
1052
|
+
const aliases = rootedDiagnosticAliases(candidate, projectRoot);
|
|
1053
|
+
if (aliases.some((alias) => textMentionsExactPath(text, alias))) {
|
|
1054
|
+
return true;
|
|
1055
|
+
}
|
|
1056
|
+
if (!options.allowExtensionlessJsTs || /\.(?:[cm]?[jt]sx?)$/i.test(normalizeSourceIdentity(candidate))) {
|
|
1057
|
+
return false;
|
|
1058
|
+
}
|
|
1059
|
+
return aliases.some(
|
|
1060
|
+
(alias) => [".js", ".jsx", ".ts", ".tsx", ".mjs", ".mts", ".cjs", ".cts"].some(
|
|
1061
|
+
(extension) => textMentionsExactPath(text, `${alias}${extension}`)
|
|
1062
|
+
)
|
|
1063
|
+
);
|
|
1064
|
+
});
|
|
1065
|
+
return distinctSourceIdentities(exactMatches).length === 1 ? exactMatches : [];
|
|
1066
|
+
}
|
|
1067
|
+
const evaluated = candidates.map((candidate) => {
|
|
1068
|
+
const identity = normalizeSourceIdentity(candidate);
|
|
1069
|
+
return {
|
|
1070
|
+
candidate,
|
|
1071
|
+
identity,
|
|
1072
|
+
identitySegments: identity.split("/").filter(Boolean).length,
|
|
1073
|
+
matchSegments: matchingDiagnosticSegments(text, identity)
|
|
1074
|
+
};
|
|
1075
|
+
});
|
|
1076
|
+
const pathMatches = evaluated.filter(
|
|
1077
|
+
({ matchSegments }) => matchSegments > 0
|
|
1078
|
+
);
|
|
1079
|
+
if (pathMatches.length > 0) {
|
|
1080
|
+
const strongest = Math.max(
|
|
1081
|
+
...pathMatches.map(({ matchSegments }) => matchSegments)
|
|
1082
|
+
);
|
|
1083
|
+
const strongestMatches = pathMatches.filter(
|
|
1084
|
+
({ matchSegments }) => matchSegments === strongest
|
|
1085
|
+
);
|
|
1086
|
+
const fullMatches = strongestMatches.filter(
|
|
1087
|
+
({ identitySegments, matchSegments }) => identitySegments === matchSegments
|
|
1088
|
+
);
|
|
1089
|
+
const unambiguousMatches = fullMatches.length > 0 ? fullMatches : strongestMatches;
|
|
1090
|
+
if (distinctSourceIdentities(
|
|
1091
|
+
unambiguousMatches.map(({ identity }) => identity)
|
|
1092
|
+
).length === 1) {
|
|
1093
|
+
return unambiguousMatches.map(({ candidate }) => candidate);
|
|
1094
|
+
}
|
|
1095
|
+
return [];
|
|
1096
|
+
}
|
|
1097
|
+
const basenameMatches = evaluated.filter(({ identity }) => {
|
|
1098
|
+
const basename = identity.split("/").pop() ?? "";
|
|
1099
|
+
return basename.length > 0 && textMentionsPathSuffix(text, basename);
|
|
1100
|
+
});
|
|
1101
|
+
return distinctSourceIdentities(
|
|
1102
|
+
basenameMatches.map(({ identity }) => identity)
|
|
1103
|
+
).length === 1 ? basenameMatches.map(({ candidate }) => candidate) : [];
|
|
1104
|
+
}
|
|
1105
|
+
|
|
708
1106
|
// canvas/runtime-problems.ts
|
|
709
1107
|
var CanvasHostProblemTracker = class {
|
|
710
1108
|
constructor() {
|
|
711
|
-
this.
|
|
1109
|
+
this.hostProblemWasNearRender = false;
|
|
712
1110
|
this.componentProblems = /* @__PURE__ */ new Map();
|
|
713
|
-
this.componentProblemHmrGenerations = /* @__PURE__ */ new Map();
|
|
714
1111
|
this.canvasProblems = /* @__PURE__ */ new Map();
|
|
1112
|
+
this.registeredCanvasPaths = /* @__PURE__ */ new Map();
|
|
1113
|
+
this.registeredRenderSourcePaths = /* @__PURE__ */ new Map();
|
|
715
1114
|
this.watchers = /* @__PURE__ */ new Set();
|
|
716
1115
|
this.hostProblemClearedWatchers = /* @__PURE__ */ new Set();
|
|
717
|
-
this.hmrGeneration = 0;
|
|
718
1116
|
}
|
|
719
1117
|
snapshot() {
|
|
1118
|
+
const componentProblems = new Map(this.componentProblems);
|
|
1119
|
+
const canvasProblems = new Map(this.canvasProblems);
|
|
1120
|
+
const projectViteProblem = (problem) => {
|
|
1121
|
+
const canvasPaths = this.matchingCanvasPaths(problem);
|
|
1122
|
+
if (canvasPaths.length > 0) {
|
|
1123
|
+
for (const canvasPath of canvasPaths) {
|
|
1124
|
+
canvasProblems.set(canvasPath, problem);
|
|
1125
|
+
}
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
const renderIds = this.matchingRenderIds(problem);
|
|
1129
|
+
if (renderIds.length === 0) return false;
|
|
1130
|
+
for (const renderId of renderIds) {
|
|
1131
|
+
componentProblems.set(
|
|
1132
|
+
renderId,
|
|
1133
|
+
this.problemForMatchedRender(problem, renderId)
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
return true;
|
|
1137
|
+
};
|
|
720
1138
|
const currentViteOverlay = readCurrentViteOverlay();
|
|
721
|
-
|
|
1139
|
+
let hostProblem = this.hostProblem?.sourceKind === "vite-overlay" ? void 0 : this.hostProblem;
|
|
1140
|
+
if (hostProblem && isViteProblemSourceKind(hostProblem.sourceKind) && projectViteProblem(hostProblem)) {
|
|
1141
|
+
hostProblem = void 0;
|
|
1142
|
+
}
|
|
1143
|
+
if (hostProblem && (this.hostProblemWasNearRender || isNearRenderProblemSourceKind(hostProblem.sourceKind)) && projectViteProblem(hostProblem)) {
|
|
1144
|
+
hostProblem = void 0;
|
|
1145
|
+
}
|
|
1146
|
+
if (currentViteOverlay && !projectViteProblem(currentViteOverlay)) {
|
|
1147
|
+
hostProblem = currentViteOverlay;
|
|
1148
|
+
}
|
|
722
1149
|
return {
|
|
723
1150
|
hostProblem,
|
|
724
|
-
componentProblems: [...
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
1151
|
+
componentProblems: [...componentProblems].map(([renderId, problem]) => ({
|
|
1152
|
+
renderId,
|
|
1153
|
+
problem
|
|
1154
|
+
})),
|
|
1155
|
+
canvasProblems: [...canvasProblems].map(([canvasPath, problem]) => ({
|
|
728
1156
|
canvasPath,
|
|
729
1157
|
problem
|
|
730
1158
|
}))
|
|
@@ -744,18 +1172,22 @@ var CanvasHostProblemTracker = class {
|
|
|
744
1172
|
}
|
|
745
1173
|
reportHostProblem(sourceKind, error, details = {}) {
|
|
746
1174
|
this.hostProblem = createProblem(sourceKind, error, details);
|
|
747
|
-
this.
|
|
1175
|
+
this.hostProblemWasNearRender = false;
|
|
748
1176
|
this.publish();
|
|
749
1177
|
}
|
|
750
1178
|
reportProblemNearRender(sourceKind, error, details = {}) {
|
|
751
1179
|
const problem = createProblem(sourceKind, error, details);
|
|
752
|
-
const
|
|
753
|
-
if (
|
|
754
|
-
|
|
755
|
-
|
|
1180
|
+
const renderIds = this.matchingRenderIds(problem);
|
|
1181
|
+
if (renderIds.length > 0) {
|
|
1182
|
+
for (const renderId of renderIds) {
|
|
1183
|
+
this.componentProblems.set(
|
|
1184
|
+
renderId,
|
|
1185
|
+
this.problemForMatchedRender(problem, renderId)
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
756
1188
|
} else {
|
|
757
1189
|
this.hostProblem = problem;
|
|
758
|
-
this.
|
|
1190
|
+
this.hostProblemWasNearRender = true;
|
|
759
1191
|
}
|
|
760
1192
|
this.publish();
|
|
761
1193
|
}
|
|
@@ -763,19 +1195,59 @@ var CanvasHostProblemTracker = class {
|
|
|
763
1195
|
// storyboards ever registered). Keyed by canvas path, not renderId — the
|
|
764
1196
|
// renderer scopes it to that canvas's storyboards.
|
|
765
1197
|
reportCanvasProblem(canvasPath, sourceKind, error, details = {}) {
|
|
766
|
-
this.canvasProblems.set(
|
|
1198
|
+
this.canvasProblems.set(
|
|
1199
|
+
canvasPath,
|
|
1200
|
+
createProblem(sourceKind, error, details)
|
|
1201
|
+
);
|
|
767
1202
|
this.publish();
|
|
768
1203
|
}
|
|
769
|
-
clearCanvasProblem(canvasPath) {
|
|
770
|
-
|
|
1204
|
+
clearCanvasProblem(canvasPath, sourceKinds) {
|
|
1205
|
+
const problem = this.canvasProblems.get(canvasPath);
|
|
1206
|
+
if (!problem) return;
|
|
1207
|
+
if (sourceKinds && !sourceKinds.includes(problem.sourceKind)) return;
|
|
1208
|
+
this.canvasProblems.delete(canvasPath);
|
|
771
1209
|
this.publish();
|
|
772
1210
|
}
|
|
1211
|
+
registerCanvasPath(canvasPath) {
|
|
1212
|
+
const normalizedPath = normalizeCanvasPath(canvasPath);
|
|
1213
|
+
if (!normalizedPath) return () => {
|
|
1214
|
+
};
|
|
1215
|
+
this.registeredCanvasPaths.set(
|
|
1216
|
+
normalizedPath,
|
|
1217
|
+
(this.registeredCanvasPaths.get(normalizedPath) ?? 0) + 1
|
|
1218
|
+
);
|
|
1219
|
+
this.publishIfViteProjectionChanged();
|
|
1220
|
+
return () => {
|
|
1221
|
+
const count = this.registeredCanvasPaths.get(normalizedPath) ?? 0;
|
|
1222
|
+
if (count <= 1) {
|
|
1223
|
+
this.registeredCanvasPaths.delete(normalizedPath);
|
|
1224
|
+
this.clearCanvasProblem(normalizedPath, ["vite-overlay"]);
|
|
1225
|
+
} else {
|
|
1226
|
+
this.registeredCanvasPaths.set(normalizedPath, count - 1);
|
|
1227
|
+
}
|
|
1228
|
+
this.publishIfViteProjectionChanged();
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
matchingCanvasPaths(problem) {
|
|
1232
|
+
const candidates = [...this.registeredCanvasPaths.keys()];
|
|
1233
|
+
const filenameMatches = resolveUniqueDiagnosticSourceMatches(
|
|
1234
|
+
problem.filename ?? "",
|
|
1235
|
+
candidates,
|
|
1236
|
+
{ projectRoot: readTempoProjectRoot() }
|
|
1237
|
+
);
|
|
1238
|
+
if (filenameMatches.length > 0) return filenameMatches;
|
|
1239
|
+
const text = [problem.message, problem.stack, problem.filename].filter(Boolean).join("\n");
|
|
1240
|
+
return resolveUniqueDiagnosticSourceMatches(text, candidates, {
|
|
1241
|
+
projectRoot: readTempoProjectRoot()
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
773
1244
|
clearHostProblem(sourceKinds) {
|
|
774
1245
|
if (!this.hostProblem) return;
|
|
775
|
-
if (sourceKinds && !sourceKinds.includes(this.hostProblem.sourceKind))
|
|
1246
|
+
if (sourceKinds && !sourceKinds.includes(this.hostProblem.sourceKind))
|
|
1247
|
+
return;
|
|
776
1248
|
const clearedProblem = this.hostProblem;
|
|
777
1249
|
this.hostProblem = void 0;
|
|
778
|
-
this.
|
|
1250
|
+
this.hostProblemWasNearRender = false;
|
|
779
1251
|
this.publish();
|
|
780
1252
|
this.publishHostProblemCleared(clearedProblem);
|
|
781
1253
|
}
|
|
@@ -784,7 +1256,6 @@ var CanvasHostProblemTracker = class {
|
|
|
784
1256
|
renderId,
|
|
785
1257
|
createProblem(sourceKind, error, details)
|
|
786
1258
|
);
|
|
787
|
-
this.componentProblemHmrGenerations.set(renderId, this.hmrGeneration);
|
|
788
1259
|
this.publish();
|
|
789
1260
|
}
|
|
790
1261
|
clearComponentProblem(renderId, sourceKinds) {
|
|
@@ -792,68 +1263,117 @@ var CanvasHostProblemTracker = class {
|
|
|
792
1263
|
if (!problem) return;
|
|
793
1264
|
if (sourceKinds && !sourceKinds.includes(problem.sourceKind)) return;
|
|
794
1265
|
this.componentProblems.delete(renderId);
|
|
795
|
-
this.componentProblemHmrGenerations.delete(renderId);
|
|
796
1266
|
this.publish();
|
|
797
1267
|
}
|
|
798
1268
|
hasComponentProblem(renderId) {
|
|
799
1269
|
return this.componentProblems.has(renderId);
|
|
800
1270
|
}
|
|
1271
|
+
syncRenderSourcePaths(entries) {
|
|
1272
|
+
const next = new Map(
|
|
1273
|
+
entries.flatMap(
|
|
1274
|
+
(entry) => entry.sourcePaths?.length ? [[entry.renderId, entry.sourcePaths]] : []
|
|
1275
|
+
)
|
|
1276
|
+
);
|
|
1277
|
+
const changed = JSON.stringify([...this.registeredRenderSourcePaths]) !== JSON.stringify([...next]);
|
|
1278
|
+
if (!changed) return;
|
|
1279
|
+
this.registeredRenderSourcePaths = next;
|
|
1280
|
+
if (this.hostProblem && (this.hostProblemWasNearRender || isNearRenderProblemSourceKind(this.hostProblem.sourceKind)) && this.matchingRenderIds(this.hostProblem).length > 0) {
|
|
1281
|
+
this.publish();
|
|
1282
|
+
} else {
|
|
1283
|
+
this.publishIfViteProjectionChanged();
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
matchingRenderIds(problem) {
|
|
1287
|
+
return findRenderIdsForProblem(
|
|
1288
|
+
problem,
|
|
1289
|
+
[...this.registeredRenderSourcePaths].flatMap(
|
|
1290
|
+
([renderId, sourcePaths]) => sourcePaths.map((sourceFile) => ({ renderId, sourceFile }))
|
|
1291
|
+
)
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
problemForMatchedRender(problem, renderId) {
|
|
1295
|
+
if (problem.sourceKind !== "unhandled-rejection" || !this.matchingDeclaredRenderIds(problem).includes(renderId)) {
|
|
1296
|
+
return problem;
|
|
1297
|
+
}
|
|
1298
|
+
return { ...problem, sourceKind: "render-error-boundary" };
|
|
1299
|
+
}
|
|
1300
|
+
matchingDeclaredRenderIds(problem) {
|
|
1301
|
+
return findRenderIdsForProblem(
|
|
1302
|
+
problem,
|
|
1303
|
+
[...this.registeredRenderSourcePaths].flatMap(
|
|
1304
|
+
([renderId, sourcePaths]) => sourcePaths.map((sourceFile) => ({ renderId, sourceFile }))
|
|
1305
|
+
),
|
|
1306
|
+
false
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
801
1309
|
clearRecoveredComponentProblemsAfterRender(renderId) {
|
|
802
1310
|
let changed = false;
|
|
803
1311
|
const problem = this.componentProblems.get(renderId);
|
|
804
|
-
if (problem && problem.sourceKind !== "render-error-boundary"
|
|
1312
|
+
if (problem && problem.sourceKind !== "render-error-boundary") {
|
|
805
1313
|
this.componentProblems.delete(renderId);
|
|
806
|
-
this.componentProblemHmrGenerations.delete(renderId);
|
|
807
1314
|
changed = true;
|
|
808
1315
|
}
|
|
809
1316
|
if (this.clearRecoveredHostProblemAfterRender(renderId)) changed = true;
|
|
810
|
-
if (changed)
|
|
1317
|
+
if (changed) {
|
|
1318
|
+
this.publish();
|
|
1319
|
+
} else {
|
|
1320
|
+
this.publishIfViteProjectionChanged();
|
|
1321
|
+
}
|
|
811
1322
|
}
|
|
812
|
-
|
|
813
|
-
this.
|
|
1323
|
+
reconcileViteOverlayProjection() {
|
|
1324
|
+
this.publishIfViteProjectionChanged();
|
|
814
1325
|
}
|
|
815
1326
|
dispose() {
|
|
816
1327
|
this.watchers.clear();
|
|
817
1328
|
this.hostProblemClearedWatchers.clear();
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
const renderIdFilter = options.renderId ?? void 0;
|
|
821
|
-
const currentRenderFailures = [];
|
|
822
|
-
for (const [renderId, failure] of this.componentProblems) {
|
|
823
|
-
if (renderIdFilter != null && renderId !== renderIdFilter) continue;
|
|
824
|
-
currentRenderFailures.push({ renderId, failure });
|
|
825
|
-
}
|
|
826
|
-
const currentHostFailure = readCurrentViteOverlay() ?? this.hostProblem;
|
|
827
|
-
return {
|
|
828
|
-
...currentHostFailure ? { currentHostFailure } : {},
|
|
829
|
-
currentRenderFailures,
|
|
830
|
-
currentCanvasFailures: [...this.canvasProblems].map(
|
|
831
|
-
([canvasPath, failure]) => ({ canvasPath, failure })
|
|
832
|
-
),
|
|
833
|
-
observedAt: Date.now()
|
|
834
|
-
};
|
|
1329
|
+
this.registeredCanvasPaths.clear();
|
|
1330
|
+
this.registeredRenderSourcePaths.clear();
|
|
835
1331
|
}
|
|
836
1332
|
publish() {
|
|
1333
|
+
this.publishedViteProjectionSignature = this.viteProjectionSignature();
|
|
837
1334
|
for (const watcher of this.watchers) {
|
|
838
1335
|
watcher();
|
|
839
1336
|
}
|
|
840
1337
|
}
|
|
1338
|
+
publishIfViteProjectionChanged() {
|
|
1339
|
+
const signature = this.viteProjectionSignature();
|
|
1340
|
+
if (this.publishedViteProjectionSignature === void 0) {
|
|
1341
|
+
this.publishedViteProjectionSignature = signature;
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
if (signature === this.publishedViteProjectionSignature) return;
|
|
1345
|
+
this.publish();
|
|
1346
|
+
}
|
|
1347
|
+
viteProjectionSignature() {
|
|
1348
|
+
const snapshot = this.snapshot();
|
|
1349
|
+
const identify = (problem) => [problem.sourceKind, problem.filename, problem.message].join("\0");
|
|
1350
|
+
return JSON.stringify({
|
|
1351
|
+
host: snapshot.hostProblem && isProjectedViteProblemSourceKind(snapshot.hostProblem.sourceKind) ? identify(snapshot.hostProblem) : null,
|
|
1352
|
+
components: snapshot.componentProblems.flatMap(
|
|
1353
|
+
({ renderId, problem }) => isProjectedViteProblemSourceKind(problem.sourceKind) ? [[renderId, identify(problem)]] : []
|
|
1354
|
+
),
|
|
1355
|
+
canvases: snapshot.canvasProblems.flatMap(
|
|
1356
|
+
({ canvasPath, problem }) => isProjectedViteProblemSourceKind(problem.sourceKind) ? [[canvasPath, identify(problem)]] : []
|
|
1357
|
+
)
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
841
1360
|
publishHostProblemCleared(problem) {
|
|
842
1361
|
for (const watcher of this.hostProblemClearedWatchers) {
|
|
843
1362
|
watcher(problem);
|
|
844
1363
|
}
|
|
845
1364
|
}
|
|
846
1365
|
clearRecoveredHostProblemAfterRender(renderId) {
|
|
847
|
-
if (!this.hostProblem || !renderRecoveredHostProblemSourceKinds.includes(
|
|
1366
|
+
if (!this.hostProblem || !renderRecoveredHostProblemSourceKinds.includes(
|
|
1367
|
+
this.hostProblem.sourceKind
|
|
1368
|
+
)) {
|
|
848
1369
|
return false;
|
|
849
1370
|
}
|
|
850
|
-
|
|
851
|
-
if (
|
|
1371
|
+
const matchingRenderIds = this.matchingRenderIds(this.hostProblem);
|
|
1372
|
+
if (matchingRenderIds.length > 0 && !matchingRenderIds.includes(renderId))
|
|
852
1373
|
return false;
|
|
853
|
-
}
|
|
854
1374
|
const clearedProblem = this.hostProblem;
|
|
855
1375
|
this.hostProblem = void 0;
|
|
856
|
-
this.
|
|
1376
|
+
this.hostProblemWasNearRender = false;
|
|
857
1377
|
this.publishHostProblemCleared(clearedProblem);
|
|
858
1378
|
return true;
|
|
859
1379
|
}
|
|
@@ -864,36 +1384,113 @@ function createCanvasHostProblemTracker() {
|
|
|
864
1384
|
function installCanvasHostRuntimeProblemTracking(tracker) {
|
|
865
1385
|
if (typeof window === "undefined") return () => {
|
|
866
1386
|
};
|
|
1387
|
+
const startupProblems = takeFrameStartupProblems();
|
|
867
1388
|
const cleanupHostCapture = installHostProblemCapture(tracker);
|
|
868
|
-
const cleanupCanvasImportCapture = installCanvasImportProblemCapture(tracker);
|
|
869
1389
|
const cleanupViteCapture = installViteProblemCapture(tracker);
|
|
870
|
-
const
|
|
1390
|
+
const cleanupViteErrorStream = installViteErrorStream(tracker);
|
|
1391
|
+
for (const problem of startupProblems) {
|
|
1392
|
+
tracker.reportProblemNearRender(
|
|
1393
|
+
problem.kind === "error" ? "page-error" : "unhandled-rejection",
|
|
1394
|
+
problem.message,
|
|
1395
|
+
{
|
|
1396
|
+
timestamp: problem.timestamp,
|
|
1397
|
+
stack: problem.stack,
|
|
1398
|
+
filename: problem.filename,
|
|
1399
|
+
line: problem.line,
|
|
1400
|
+
column: problem.column
|
|
1401
|
+
}
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
871
1404
|
return () => {
|
|
872
1405
|
cleanupHostCapture();
|
|
873
|
-
cleanupCanvasImportCapture();
|
|
874
1406
|
cleanupViteCapture();
|
|
875
|
-
|
|
876
|
-
tracker.dispose();
|
|
1407
|
+
cleanupViteErrorStream();
|
|
877
1408
|
};
|
|
878
1409
|
}
|
|
879
|
-
function
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1410
|
+
function installViteErrorStream(tracker) {
|
|
1411
|
+
if (typeof EventSource === "undefined") return () => {
|
|
1412
|
+
};
|
|
1413
|
+
const source = new EventSource("/__tempo/errors");
|
|
1414
|
+
source.onmessage = (event) => {
|
|
1415
|
+
let problem;
|
|
1416
|
+
try {
|
|
1417
|
+
problem = JSON.parse(event.data);
|
|
1418
|
+
} catch {
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
if (problem === null) {
|
|
1422
|
+
tracker.clearHostProblem(["vite-hmr-error"]);
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
if (typeof problem?.message !== "string") return;
|
|
1426
|
+
tracker.reportHostProblem("vite-hmr-error", problem.message, {
|
|
1427
|
+
stack: problem.stack,
|
|
1428
|
+
filename: problem.file ?? problem.loc?.file
|
|
889
1429
|
});
|
|
890
1430
|
};
|
|
891
|
-
window.addEventListener("tempo:canvas-import-error", onCanvasImportError);
|
|
892
1431
|
return () => {
|
|
893
|
-
|
|
1432
|
+
source.close();
|
|
894
1433
|
};
|
|
895
1434
|
}
|
|
1435
|
+
function takeFrameStartupProblems() {
|
|
1436
|
+
const take = window.framePool?.takeStartupErrors;
|
|
1437
|
+
if (typeof take !== "function") return [];
|
|
1438
|
+
let value;
|
|
1439
|
+
try {
|
|
1440
|
+
value = take();
|
|
1441
|
+
} catch {
|
|
1442
|
+
return [];
|
|
1443
|
+
}
|
|
1444
|
+
if (!Array.isArray(value)) return [];
|
|
1445
|
+
return value.flatMap((candidate) => {
|
|
1446
|
+
if (!candidate || typeof candidate !== "object" || candidate.kind !== "error" && candidate.kind !== "unhandledrejection" || typeof candidate.message !== "string" || typeof candidate.timestamp !== "number") {
|
|
1447
|
+
return [];
|
|
1448
|
+
}
|
|
1449
|
+
const record = candidate;
|
|
1450
|
+
return [
|
|
1451
|
+
{
|
|
1452
|
+
kind: record.kind,
|
|
1453
|
+
timestamp: record.timestamp,
|
|
1454
|
+
message: record.message,
|
|
1455
|
+
...typeof record.stack === "string" && { stack: record.stack },
|
|
1456
|
+
...typeof record.filename === "string" && {
|
|
1457
|
+
filename: record.filename
|
|
1458
|
+
},
|
|
1459
|
+
...typeof record.line === "number" && { line: record.line },
|
|
1460
|
+
...typeof record.column === "number" && { column: record.column }
|
|
1461
|
+
}
|
|
1462
|
+
];
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
896
1465
|
var renderRecoveredHostProblemSourceKinds = ["page-error", "unhandled-rejection", "console-vite-error", "vite-hmr-error"];
|
|
1466
|
+
var FAILED_RELOAD_PROBE_DELAYS_MS = [50, 400, 1600];
|
|
1467
|
+
async function moduleTransformSucceeds(path) {
|
|
1468
|
+
const [pathname, query = ""] = path.split("?");
|
|
1469
|
+
const url = `${pathname}?${query ? `${query}&` : ""}t=${Date.now()}`;
|
|
1470
|
+
const response = await fetch(url, { cache: "no-store" });
|
|
1471
|
+
return response.ok;
|
|
1472
|
+
}
|
|
1473
|
+
async function compileErrorFileStillBroken(file) {
|
|
1474
|
+
const cleaned = file.replace(/:\d+(?::\d+)?$/, "");
|
|
1475
|
+
const candidates = cleaned.startsWith("/@") ? [cleaned] : [`/@fs${cleaned}`, cleaned];
|
|
1476
|
+
for (const candidate of candidates) {
|
|
1477
|
+
try {
|
|
1478
|
+
if (await moduleTransformSucceeds(candidate)) return false;
|
|
1479
|
+
} catch {
|
|
1480
|
+
return true;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
function isViteProblemSourceKind(sourceKind) {
|
|
1486
|
+
return sourceKind === "vite-hmr-error" || sourceKind === "console-vite-error";
|
|
1487
|
+
}
|
|
1488
|
+
function isNearRenderProblemSourceKind(sourceKind) {
|
|
1489
|
+
return sourceKind === "page-error" || sourceKind === "unhandled-rejection" || sourceKind === "console-vite-error";
|
|
1490
|
+
}
|
|
1491
|
+
function isProjectedViteProblemSourceKind(sourceKind) {
|
|
1492
|
+
return sourceKind === "vite-overlay" || isViteProblemSourceKind(sourceKind);
|
|
1493
|
+
}
|
|
897
1494
|
function createProblem(sourceKind, error, details = {}) {
|
|
898
1495
|
return {
|
|
899
1496
|
sourceKind,
|
|
@@ -904,29 +1501,47 @@ function createProblem(sourceKind, error, details = {}) {
|
|
|
904
1501
|
...details
|
|
905
1502
|
};
|
|
906
1503
|
}
|
|
907
|
-
function
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if (!renderId) continue;
|
|
919
|
-
const sourceFiles = getObservedSourceFiles(slot);
|
|
920
|
-
if (sourceFiles.some((sourceFile) => problemTextMentionsSource(haystack, sourceFile))) {
|
|
921
|
-
return renderId;
|
|
1504
|
+
function findRenderIdsForProblem(problem, registered = [], includeDom = true) {
|
|
1505
|
+
const observed = [
|
|
1506
|
+
...registered
|
|
1507
|
+
];
|
|
1508
|
+
if (includeDom && typeof document !== "undefined") {
|
|
1509
|
+
for (const slot of document.querySelectorAll("[data-render-id]")) {
|
|
1510
|
+
const renderId = slot.getAttribute("data-render-id");
|
|
1511
|
+
if (!renderId) continue;
|
|
1512
|
+
for (const sourceFile of getObservedSourceFiles2(slot)) {
|
|
1513
|
+
observed.push({ renderId, sourceFile });
|
|
1514
|
+
}
|
|
922
1515
|
}
|
|
923
1516
|
}
|
|
924
|
-
|
|
1517
|
+
if (observed.length === 0) return [];
|
|
1518
|
+
const exactFilenameMatches = new Set(
|
|
1519
|
+
resolveUniqueDiagnosticSourceMatches(
|
|
1520
|
+
problem.filename ?? "",
|
|
1521
|
+
observed.map(({ sourceFile }) => sourceFile),
|
|
1522
|
+
{
|
|
1523
|
+
projectRoot: readTempoProjectRoot(),
|
|
1524
|
+
allowExtensionlessJsTs: true
|
|
1525
|
+
}
|
|
1526
|
+
)
|
|
1527
|
+
);
|
|
1528
|
+
if (exactFilenameMatches.size > 0) {
|
|
1529
|
+
return uniqueRenderIds(
|
|
1530
|
+
observed.filter(({ sourceFile }) => exactFilenameMatches.has(sourceFile))
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
const filenameMatches = matchObservedRenderIds(
|
|
1534
|
+
problem.filename ?? "",
|
|
1535
|
+
observed
|
|
1536
|
+
);
|
|
1537
|
+
if (filenameMatches.length > 0) return filenameMatches;
|
|
1538
|
+
const haystack = [problem.message, problem.stack, problem.componentStack].filter(Boolean).join("\n");
|
|
1539
|
+
return matchObservedRenderIds(haystack, observed);
|
|
925
1540
|
}
|
|
926
|
-
var
|
|
927
|
-
function
|
|
1541
|
+
var sourceAnnotationSelector2 = "[data-tempo-source-file], [data-tempo-source-loc], [data-tempo-filepath], [data-tempo-html-filepath]";
|
|
1542
|
+
function getObservedSourceFiles2(slot) {
|
|
928
1543
|
const sourceFiles = /* @__PURE__ */ new Set();
|
|
929
|
-
for (const element of slot.querySelectorAll(
|
|
1544
|
+
for (const element of slot.querySelectorAll(sourceAnnotationSelector2)) {
|
|
930
1545
|
for (const attribute of [
|
|
931
1546
|
"data-tempo-source-file",
|
|
932
1547
|
"data-tempo-filepath",
|
|
@@ -941,19 +1556,43 @@ function getObservedSourceFiles(slot) {
|
|
|
941
1556
|
}
|
|
942
1557
|
return [...sourceFiles];
|
|
943
1558
|
}
|
|
944
|
-
function
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
|
|
1559
|
+
function matchObservedRenderIds(text, observed) {
|
|
1560
|
+
const matches = new Set(
|
|
1561
|
+
resolveUniqueDiagnosticSourceMatches(
|
|
1562
|
+
text,
|
|
1563
|
+
observed.map(({ sourceFile }) => sourceFile),
|
|
1564
|
+
{
|
|
1565
|
+
projectRoot: readTempoProjectRoot(),
|
|
1566
|
+
allowExtensionlessJsTs: true
|
|
1567
|
+
}
|
|
1568
|
+
)
|
|
1569
|
+
);
|
|
1570
|
+
return uniqueRenderIds(
|
|
1571
|
+
observed.filter(({ sourceFile }) => matches.has(sourceFile))
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
function readTempoProjectRoot() {
|
|
1575
|
+
if (typeof document === "undefined") return null;
|
|
1576
|
+
return document.querySelector('meta[name="tempo-source-identity-root"]')?.content.trim() || document.querySelector('meta[name="tempo-project-root"]')?.content.trim() || null;
|
|
1577
|
+
}
|
|
1578
|
+
function uniqueRenderIds(matches) {
|
|
1579
|
+
return [...new Set(matches.map(({ renderId }) => renderId))];
|
|
1580
|
+
}
|
|
1581
|
+
function normalizeCanvasPath(value) {
|
|
1582
|
+
return value.trim();
|
|
948
1583
|
}
|
|
949
1584
|
function installHostProblemCapture(tracker) {
|
|
950
1585
|
const onError = (event) => {
|
|
951
1586
|
if (event.target instanceof Element) return;
|
|
952
|
-
tracker.reportProblemNearRender(
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
1587
|
+
tracker.reportProblemNearRender(
|
|
1588
|
+
"page-error",
|
|
1589
|
+
event.error ?? event.message,
|
|
1590
|
+
{
|
|
1591
|
+
filename: event.filename || void 0,
|
|
1592
|
+
line: typeof event.lineno === "number" ? event.lineno : void 0,
|
|
1593
|
+
column: typeof event.colno === "number" ? event.colno : void 0
|
|
1594
|
+
}
|
|
1595
|
+
);
|
|
957
1596
|
};
|
|
958
1597
|
const onUnhandledRejection = (event) => {
|
|
959
1598
|
tracker.reportProblemNearRender("unhandled-rejection", event.reason);
|
|
@@ -972,7 +1611,7 @@ function installHostProblemCapture(tracker) {
|
|
|
972
1611
|
return;
|
|
973
1612
|
}
|
|
974
1613
|
const url = target.getAttribute("src") || target.getAttribute("href") || "";
|
|
975
|
-
const message =
|
|
1614
|
+
const message = `Failed to load ${target.tagName.toLowerCase()}${url ? `: ${url}` : ""}`;
|
|
976
1615
|
const renderId = target.closest("[data-render-id]")?.getAttribute("data-render-id");
|
|
977
1616
|
if (renderId) {
|
|
978
1617
|
tracker.reportComponentProblem(renderId, "resource-load", message);
|
|
@@ -987,7 +1626,7 @@ function installHostProblemCapture(tracker) {
|
|
|
987
1626
|
const families = faces.map((face) => face.family).filter(Boolean).join(", ");
|
|
988
1627
|
tracker.reportHostProblem(
|
|
989
1628
|
"resource-load",
|
|
990
|
-
|
|
1629
|
+
`Failed to load font${families ? `: ${families}` : ""}`
|
|
991
1630
|
);
|
|
992
1631
|
};
|
|
993
1632
|
const fontFaceSet = typeof document.fonts?.addEventListener === "function" ? document.fonts : void 0;
|
|
@@ -1006,15 +1645,7 @@ function installHostProblemCapture(tracker) {
|
|
|
1006
1645
|
}
|
|
1007
1646
|
function installViteProblemCapture(tracker) {
|
|
1008
1647
|
const reconcileViteOverlay = () => {
|
|
1009
|
-
|
|
1010
|
-
if (problem) {
|
|
1011
|
-
tracker.reportHostProblem("vite-overlay", problem.message, {
|
|
1012
|
-
stack: problem.stack,
|
|
1013
|
-
filename: problem.filename
|
|
1014
|
-
});
|
|
1015
|
-
} else {
|
|
1016
|
-
tracker.clearHostProblem(["vite-overlay"]);
|
|
1017
|
-
}
|
|
1648
|
+
tracker.reconcileViteOverlayProjection();
|
|
1018
1649
|
};
|
|
1019
1650
|
const observer = new MutationObserver(reconcileViteOverlay);
|
|
1020
1651
|
if (document.body) {
|
|
@@ -1022,16 +1653,16 @@ function installViteProblemCapture(tracker) {
|
|
|
1022
1653
|
reconcileViteOverlay();
|
|
1023
1654
|
void Promise.resolve().then(reconcileViteOverlay);
|
|
1024
1655
|
}
|
|
1025
|
-
const
|
|
1026
|
-
const
|
|
1656
|
+
const evalFailedModules = /* @__PURE__ */ new Map();
|
|
1657
|
+
const latestEvaluationFailure = () => {
|
|
1027
1658
|
let latest;
|
|
1028
|
-
for (const problem of
|
|
1659
|
+
for (const problem of evalFailedModules.values()) {
|
|
1029
1660
|
if (!latest || problem.timestamp >= latest.timestamp) latest = problem;
|
|
1030
1661
|
}
|
|
1031
1662
|
return latest;
|
|
1032
1663
|
};
|
|
1033
|
-
const
|
|
1034
|
-
const latest =
|
|
1664
|
+
const reconcileEvaluationHostProblem = () => {
|
|
1665
|
+
const latest = latestEvaluationFailure();
|
|
1035
1666
|
if (latest) {
|
|
1036
1667
|
tracker.reportHostProblem("vite-hmr-error", latest.message, latest);
|
|
1037
1668
|
} else {
|
|
@@ -1039,77 +1670,12 @@ function installViteProblemCapture(tracker) {
|
|
|
1039
1670
|
}
|
|
1040
1671
|
};
|
|
1041
1672
|
const failedReloadPattern = /^Failed to reload (.+?)\. This could be due to/;
|
|
1042
|
-
|
|
1043
|
-
let viteHmrCycleActive = false;
|
|
1044
|
-
let cycleFailedPaths = /* @__PURE__ */ new Map();
|
|
1045
|
-
let lastCycleViteErrorDetail;
|
|
1046
|
-
const onViteBeforeUpdate = () => {
|
|
1047
|
-
viteHmrCycleActive = true;
|
|
1048
|
-
cycleFailedPaths = /* @__PURE__ */ new Map();
|
|
1049
|
-
lastCycleViteErrorDetail = void 0;
|
|
1050
|
-
tracker.noteHmrUpdateStarted();
|
|
1051
|
-
};
|
|
1052
|
-
const onViteAfterUpdate = (payload) => {
|
|
1053
|
-
const updatedPaths = readUpdatePaths(payload);
|
|
1054
|
-
let shouldReconcile = false;
|
|
1055
|
-
if (updatedPaths.length > 0 && !cycleFailedPaths.has(pathlessViteErrorKey)) {
|
|
1056
|
-
shouldReconcile = viteHmrFailedModules.delete(pathlessViteErrorKey);
|
|
1057
|
-
}
|
|
1058
|
-
for (const [path, problem] of cycleFailedPaths) {
|
|
1059
|
-
viteHmrFailedModules.set(path, problem);
|
|
1060
|
-
shouldReconcile = true;
|
|
1061
|
-
}
|
|
1062
|
-
viteHmrCycleActive = false;
|
|
1063
|
-
cycleFailedPaths = /* @__PURE__ */ new Map();
|
|
1064
|
-
if (shouldReconcile) reconcileViteHmrHostProblem();
|
|
1065
|
-
};
|
|
1066
|
-
const onViteError = (payload) => {
|
|
1067
|
-
const error = readViteError(payload);
|
|
1068
|
-
if (!error) return;
|
|
1069
|
-
lastCycleViteErrorDetail = error;
|
|
1070
|
-
const path = error.filename ?? pathlessViteErrorKey;
|
|
1071
|
-
const problem = createProblem("vite-hmr-error", error.message, {
|
|
1072
|
-
stack: error.stack,
|
|
1073
|
-
filename: error.filename
|
|
1074
|
-
});
|
|
1075
|
-
if (viteHmrCycleActive) {
|
|
1076
|
-
cycleFailedPaths.set(path, problem);
|
|
1077
|
-
} else {
|
|
1078
|
-
viteHmrFailedModules.set(path, problem);
|
|
1079
|
-
}
|
|
1080
|
-
reconcileViteHmrHostProblem();
|
|
1081
|
-
};
|
|
1082
|
-
let hotEventsCancelled = false;
|
|
1083
|
-
let subscribedHot;
|
|
1084
|
-
const subscribeHotEvents = (hot2) => {
|
|
1085
|
-
subscribedHot = hot2;
|
|
1086
|
-
hot2.on?.("vite:beforeUpdate", onViteBeforeUpdate);
|
|
1087
|
-
hot2.on?.("vite:afterUpdate", onViteAfterUpdate);
|
|
1088
|
-
hot2.on?.("vite:error", onViteError);
|
|
1089
|
-
};
|
|
1090
|
-
const hot = readViteHot();
|
|
1091
|
-
if (hot?.on) {
|
|
1092
|
-
subscribeHotEvents(hot);
|
|
1093
|
-
} else {
|
|
1094
|
-
void import(
|
|
1095
|
-
/* @vite-ignore */
|
|
1096
|
-
/* webpackIgnore: true */
|
|
1097
|
-
/* turbopackIgnore: true */
|
|
1098
|
-
"/@vite/client"
|
|
1099
|
-
).then((client) => {
|
|
1100
|
-
const createHotContext = client.createHotContext;
|
|
1101
|
-
const context = createHotContext?.("/__tempo-canvas-host__");
|
|
1102
|
-
if (!context || hotEventsCancelled) return;
|
|
1103
|
-
subscribeHotEvents(context);
|
|
1104
|
-
}).catch(() => {
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1673
|
+
let lastViteConsoleErrorDetail = null;
|
|
1107
1674
|
const stopClearedWatch = tracker.watchHostProblemCleared((problem) => {
|
|
1108
1675
|
if (problem.sourceKind !== "vite-hmr-error") return;
|
|
1109
|
-
const
|
|
1110
|
-
if (!
|
|
1111
|
-
|
|
1112
|
-
void Promise.resolve().then(reconcileViteHmrHostProblem);
|
|
1676
|
+
const removed = problem.filename ? evalFailedModules.delete(problem.filename) : false;
|
|
1677
|
+
if (!removed) return;
|
|
1678
|
+
queueMicrotask(reconcileEvaluationHostProblem);
|
|
1113
1679
|
});
|
|
1114
1680
|
const originalConsoleError = console.error;
|
|
1115
1681
|
const patchedConsoleError = (...args) => {
|
|
@@ -1118,74 +1684,76 @@ function installViteProblemCapture(tracker) {
|
|
|
1118
1684
|
if (!error) return;
|
|
1119
1685
|
const failedReload = failedReloadPattern.exec(error.message);
|
|
1120
1686
|
if (failedReload) {
|
|
1121
|
-
const path = failedReload[1];
|
|
1122
|
-
const detail =
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
} else {
|
|
1136
|
-
void verifyModuleStillExists(path).then((exists) => {
|
|
1137
|
-
if (exists) viteHmrFailedModules.set(path, problem);
|
|
1138
|
-
else viteHmrFailedModules.delete(path);
|
|
1139
|
-
reconcileViteHmrHostProblem();
|
|
1687
|
+
const path = failedReload[1] ?? error.message;
|
|
1688
|
+
const detail = lastViteConsoleErrorDetail;
|
|
1689
|
+
lastViteConsoleErrorDetail = null;
|
|
1690
|
+
if (detail && !/failed to fetch/i.test(detail.message)) {
|
|
1691
|
+
const problem = createProblem("vite-hmr-error", detail.message, {
|
|
1692
|
+
stack: detail.stack,
|
|
1693
|
+
filename: path
|
|
1694
|
+
});
|
|
1695
|
+
evalFailedModules.set(path, problem);
|
|
1696
|
+
reconcileEvaluationHostProblem();
|
|
1697
|
+
getCanvasHostRecoveryFeed().publish({
|
|
1698
|
+
type: "module-load-failure",
|
|
1699
|
+
path,
|
|
1700
|
+
message: detail.message
|
|
1140
1701
|
});
|
|
1702
|
+
return;
|
|
1141
1703
|
}
|
|
1704
|
+
void (async () => {
|
|
1705
|
+
for (const delayMs of FAILED_RELOAD_PROBE_DELAYS_MS) {
|
|
1706
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
1707
|
+
try {
|
|
1708
|
+
if (!await moduleTransformSucceeds(path)) continue;
|
|
1709
|
+
const snapshot = tracker.snapshot();
|
|
1710
|
+
const compileErrorFiles = /* @__PURE__ */ new Set();
|
|
1711
|
+
for (const problem of [
|
|
1712
|
+
snapshot.hostProblem,
|
|
1713
|
+
...snapshot.componentProblems.map((entry) => entry.problem),
|
|
1714
|
+
...snapshot.canvasProblems.map((entry) => entry.problem)
|
|
1715
|
+
]) {
|
|
1716
|
+
if (!problem) continue;
|
|
1717
|
+
if (!isProjectedViteProblemSourceKind(problem.sourceKind)) {
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
if (problem.filename) compileErrorFiles.add(problem.filename);
|
|
1721
|
+
}
|
|
1722
|
+
for (const file of compileErrorFiles) {
|
|
1723
|
+
if (await compileErrorFileStillBroken(file)) return;
|
|
1724
|
+
}
|
|
1725
|
+
getCanvasHostRecoveryFeed().publish({
|
|
1726
|
+
type: "module-update-dropped",
|
|
1727
|
+
path,
|
|
1728
|
+
message: error.message
|
|
1729
|
+
});
|
|
1730
|
+
return;
|
|
1731
|
+
} catch {
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
})();
|
|
1142
1736
|
return;
|
|
1143
1737
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
return;
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1738
|
+
lastViteConsoleErrorDetail = error;
|
|
1739
|
+
queueMicrotask(() => {
|
|
1740
|
+
if (lastViteConsoleErrorDetail !== error) return;
|
|
1741
|
+
lastViteConsoleErrorDetail = null;
|
|
1742
|
+
tracker.reportProblemNearRender("console-vite-error", error.message, {
|
|
1743
|
+
stack: error.stack,
|
|
1744
|
+
filename: error.filename
|
|
1745
|
+
});
|
|
1151
1746
|
});
|
|
1152
1747
|
};
|
|
1153
1748
|
console.error = patchedConsoleError;
|
|
1154
1749
|
return () => {
|
|
1155
1750
|
observer.disconnect();
|
|
1156
1751
|
stopClearedWatch();
|
|
1157
|
-
hotEventsCancelled = true;
|
|
1158
|
-
subscribedHot?.off?.("vite:beforeUpdate", onViteBeforeUpdate);
|
|
1159
|
-
subscribedHot?.off?.("vite:afterUpdate", onViteAfterUpdate);
|
|
1160
|
-
subscribedHot?.off?.("vite:error", onViteError);
|
|
1161
1752
|
if (console.error === patchedConsoleError) {
|
|
1162
1753
|
console.error = originalConsoleError;
|
|
1163
1754
|
}
|
|
1164
1755
|
};
|
|
1165
1756
|
}
|
|
1166
|
-
function installCurrentProblemInspector(tracker) {
|
|
1167
|
-
const maybeWindow = window;
|
|
1168
|
-
const previous = maybeWindow.__tempoErrorTrackingInspectCurrentProblems;
|
|
1169
|
-
const inspect = (options = {}) => mergeCurrentProblemSnapshots(
|
|
1170
|
-
tracker.inspectCurrentProblems(options),
|
|
1171
|
-
previous?.(options) ?? null
|
|
1172
|
-
);
|
|
1173
|
-
maybeWindow.__tempoErrorTrackingInspectCurrentProblems = inspect;
|
|
1174
|
-
return () => {
|
|
1175
|
-
if (maybeWindow.__tempoErrorTrackingInspectCurrentProblems === inspect) {
|
|
1176
|
-
maybeWindow.__tempoErrorTrackingInspectCurrentProblems = previous;
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
function readViteHot() {
|
|
1181
|
-
const explicitHot = window.__tempoCanvasHostViteHot;
|
|
1182
|
-
if (explicitHot) return explicitHot;
|
|
1183
|
-
try {
|
|
1184
|
-
return eval("import.meta && import.meta.hot");
|
|
1185
|
-
} catch {
|
|
1186
|
-
return void 0;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
1757
|
function readCurrentViteOverlay() {
|
|
1190
1758
|
if (typeof document === "undefined") return void 0;
|
|
1191
1759
|
const overlay = document.querySelector("vite-error-overlay");
|
|
@@ -1240,64 +1808,9 @@ function readViteConsoleError(first, second) {
|
|
|
1240
1808
|
filename: detail?.filename
|
|
1241
1809
|
} : void 0;
|
|
1242
1810
|
}
|
|
1243
|
-
function readUpdatePaths(payload) {
|
|
1244
|
-
const updates = typeof payload === "object" && payload !== null && Array.isArray(payload.updates) ? payload.updates : [];
|
|
1245
|
-
const paths = /* @__PURE__ */ new Set();
|
|
1246
|
-
const collectPath = (value) => {
|
|
1247
|
-
if (typeof value === "string") paths.add(value);
|
|
1248
|
-
};
|
|
1249
|
-
for (const update of updates) {
|
|
1250
|
-
collectPath(update.path);
|
|
1251
|
-
collectPath(update.acceptedPath);
|
|
1252
|
-
collectPath(update.id);
|
|
1253
|
-
}
|
|
1254
|
-
return [...paths];
|
|
1255
|
-
}
|
|
1256
|
-
async function verifyModuleStillExists(path) {
|
|
1257
|
-
if (typeof fetch !== "function") return true;
|
|
1258
|
-
try {
|
|
1259
|
-
const response = await fetch(path, { cache: "no-store" });
|
|
1260
|
-
const contentType = response.headers.get("content-type") || "";
|
|
1261
|
-
return !contentType.includes("text/html");
|
|
1262
|
-
} catch {
|
|
1263
|
-
return true;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
function mergeCurrentProblemSnapshots(primary, fallback) {
|
|
1267
|
-
if (!fallback) return primary;
|
|
1268
|
-
const currentRenderFailures = [...primary.currentRenderFailures];
|
|
1269
|
-
const seen = new Set(
|
|
1270
|
-
currentRenderFailures.map(
|
|
1271
|
-
(entry) => `${entry.renderId ?? ""}:${entry.failure.sourceKind}:${entry.failure.message}`
|
|
1272
|
-
)
|
|
1273
|
-
);
|
|
1274
|
-
for (const entry of fallback.currentRenderFailures) {
|
|
1275
|
-
const key = `${entry.renderId ?? ""}:${entry.failure.sourceKind}:${entry.failure.message}`;
|
|
1276
|
-
if (seen.has(key)) continue;
|
|
1277
|
-
seen.add(key);
|
|
1278
|
-
currentRenderFailures.push(entry);
|
|
1279
|
-
}
|
|
1280
|
-
const currentCanvasFailures = [...primary.currentCanvasFailures ?? []];
|
|
1281
|
-
const seenCanvas = new Set(
|
|
1282
|
-
currentCanvasFailures.map(
|
|
1283
|
-
(entry) => `${entry.canvasPath}:${entry.failure.sourceKind}:${entry.failure.message}`
|
|
1284
|
-
)
|
|
1285
|
-
);
|
|
1286
|
-
for (const entry of fallback.currentCanvasFailures ?? []) {
|
|
1287
|
-
const key = `${entry.canvasPath}:${entry.failure.sourceKind}:${entry.failure.message}`;
|
|
1288
|
-
if (seenCanvas.has(key)) continue;
|
|
1289
|
-
seenCanvas.add(key);
|
|
1290
|
-
currentCanvasFailures.push(entry);
|
|
1291
|
-
}
|
|
1292
|
-
return {
|
|
1293
|
-
currentHostFailure: primary.currentHostFailure ?? fallback.currentHostFailure,
|
|
1294
|
-
currentRenderFailures,
|
|
1295
|
-
currentCanvasFailures,
|
|
1296
|
-
observedAt: Math.max(primary.observedAt, fallback.observedAt)
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
1811
|
|
|
1300
1812
|
// canvas/use-canvas-host-postmessage.ts
|
|
1813
|
+
var DEFAULT_MAX_CACHED_RENDERS = 20;
|
|
1301
1814
|
function postToMessageSource(source, response, targetOrigin) {
|
|
1302
1815
|
const origin = safePostMessageTargetOrigin(targetOrigin);
|
|
1303
1816
|
if (source && "postMessage" in source && source !== window) {
|
|
@@ -1313,39 +1826,101 @@ function safePostMessageTargetOrigin(targetOrigin) {
|
|
|
1313
1826
|
const currentOrigin = window.location.origin;
|
|
1314
1827
|
return currentOrigin && currentOrigin !== "null" ? currentOrigin : "*";
|
|
1315
1828
|
}
|
|
1829
|
+
function acknowledgeWatchEstablishment(request) {
|
|
1830
|
+
if (request.establishment.status !== "pending") return;
|
|
1831
|
+
request.establishment.status = "established";
|
|
1832
|
+
postToMessageSource(
|
|
1833
|
+
request.source,
|
|
1834
|
+
{
|
|
1835
|
+
type: "render-pool:ack",
|
|
1836
|
+
requestId: request.requestId,
|
|
1837
|
+
command: request.commandType
|
|
1838
|
+
},
|
|
1839
|
+
request.targetOrigin
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
function rejectWatchEstablishment(request, error) {
|
|
1843
|
+
if (request.establishment.status !== "pending") return;
|
|
1844
|
+
request.establishment.status = "failed";
|
|
1845
|
+
postWatchError(request, error);
|
|
1846
|
+
}
|
|
1847
|
+
function postWatchError(request, error) {
|
|
1848
|
+
postToMessageSource(
|
|
1849
|
+
request.source,
|
|
1850
|
+
{
|
|
1851
|
+
type: "render-pool:error",
|
|
1852
|
+
requestId: request.requestId,
|
|
1853
|
+
watchId: request.watchId,
|
|
1854
|
+
command: request.commandType,
|
|
1855
|
+
error: error.message
|
|
1856
|
+
},
|
|
1857
|
+
request.targetOrigin
|
|
1858
|
+
);
|
|
1859
|
+
}
|
|
1860
|
+
function readWatchResumeOptions(payload) {
|
|
1861
|
+
const flush = payload.flush;
|
|
1862
|
+
const triggers = Array.isArray(payload.triggers) ? payload.triggers.filter(
|
|
1863
|
+
(trigger) => trigger === "viewport-capture"
|
|
1864
|
+
) : [];
|
|
1865
|
+
const validFlush = flush === "always" || flush === "if-dirty" || flush === "never" ? flush : void 0;
|
|
1866
|
+
return validFlush === void 0 && triggers.length === 0 ? void 0 : { flush: validFlush, triggers };
|
|
1867
|
+
}
|
|
1868
|
+
function setRuntimeWatchPaused(watch, paused, resumeOptions) {
|
|
1869
|
+
if (watch.setPaused) {
|
|
1870
|
+
if (resumeOptions === void 0) {
|
|
1871
|
+
watch.setPaused(paused);
|
|
1872
|
+
} else {
|
|
1873
|
+
watch.setPaused(paused, resumeOptions);
|
|
1874
|
+
}
|
|
1875
|
+
} else if (paused) {
|
|
1876
|
+
watch.pause?.();
|
|
1877
|
+
} else {
|
|
1878
|
+
if (resumeOptions === void 0) {
|
|
1879
|
+
watch.resume?.();
|
|
1880
|
+
} else {
|
|
1881
|
+
watch.resume?.(resumeOptions);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1316
1885
|
function useCanvasHostPostMessage() {
|
|
1317
|
-
const [renderEntriesById, setRenderEntriesById] =
|
|
1886
|
+
const [renderEntriesById, setRenderEntriesById] = useState2(
|
|
1318
1887
|
() => /* @__PURE__ */ new Map()
|
|
1319
1888
|
);
|
|
1320
|
-
const [watchRequestsById, setWatchRequestsById] =
|
|
1889
|
+
const [watchRequestsById, setWatchRequestsById] = useState2(
|
|
1321
1890
|
() => /* @__PURE__ */ new Map()
|
|
1322
1891
|
);
|
|
1323
|
-
const [renderCommitVersionById, setRenderCommitVersionById] =
|
|
1892
|
+
const [renderCommitVersionById, setRenderCommitVersionById] = useState2(
|
|
1324
1893
|
() => /* @__PURE__ */ new Map()
|
|
1325
1894
|
);
|
|
1326
|
-
const renderEntriesRef =
|
|
1327
|
-
const watchRequestsRef =
|
|
1328
|
-
const maxCachedRef =
|
|
1329
|
-
const
|
|
1330
|
-
const
|
|
1331
|
-
const
|
|
1332
|
-
|
|
1333
|
-
const problemTrackerRef = useRef(createCanvasHostProblemTracker());
|
|
1334
|
-
const renderCommitTimesRef = useRef(/* @__PURE__ */ new Map());
|
|
1335
|
-
const sourceAnnotatedCommitTimesRef = useRef(/* @__PURE__ */ new Map());
|
|
1336
|
-
const buildProblemSnapshot = useCallback2(
|
|
1337
|
-
() => problemTrackerRef.current.snapshot(),
|
|
1338
|
-
[]
|
|
1895
|
+
const renderEntriesRef = useRef2(renderEntriesById);
|
|
1896
|
+
const watchRequestsRef = useRef2(watchRequestsById);
|
|
1897
|
+
const maxCachedRef = useRef2(DEFAULT_MAX_CACHED_RENDERS);
|
|
1898
|
+
const legacyHealthRef = useRef2(createLegacyHostHealth());
|
|
1899
|
+
const renderedRenderIdsRef = useRef2(/* @__PURE__ */ new Set());
|
|
1900
|
+
const pendingRenderWaitersRef = useRef2(
|
|
1901
|
+
/* @__PURE__ */ new Map()
|
|
1339
1902
|
);
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1903
|
+
const watchesRef = useRef2(/* @__PURE__ */ new Map());
|
|
1904
|
+
const startingWatchesRef = useRef2(
|
|
1905
|
+
/* @__PURE__ */ new Map()
|
|
1906
|
+
);
|
|
1907
|
+
const problemWatchersRef = useRef2(/* @__PURE__ */ new Map());
|
|
1908
|
+
const problemTrackerRef = useRef2(createCanvasHostProblemTracker());
|
|
1909
|
+
const updateWatchRequests = useCallback3(
|
|
1910
|
+
(update) => {
|
|
1911
|
+
const current = watchRequestsRef.current;
|
|
1912
|
+
const next = update(current);
|
|
1913
|
+
if (next === current) return;
|
|
1914
|
+
watchRequestsRef.current = next;
|
|
1915
|
+
setWatchRequestsById(next);
|
|
1345
1916
|
},
|
|
1346
1917
|
[]
|
|
1347
1918
|
);
|
|
1348
|
-
const
|
|
1919
|
+
const buildProblemSnapshot = useCallback3(
|
|
1920
|
+
() => problemTrackerRef.current.snapshot(),
|
|
1921
|
+
[]
|
|
1922
|
+
);
|
|
1923
|
+
const publishProblemSnapshot = useCallback3(() => {
|
|
1349
1924
|
const payload = buildProblemSnapshot();
|
|
1350
1925
|
for (const watcher of problemWatchersRef.current.values()) {
|
|
1351
1926
|
postToMessageSource(
|
|
@@ -1360,16 +1935,16 @@ function useCanvasHostPostMessage() {
|
|
|
1360
1935
|
);
|
|
1361
1936
|
}
|
|
1362
1937
|
}, [buildProblemSnapshot]);
|
|
1363
|
-
const setEntries =
|
|
1938
|
+
const setEntries = useCallback3(
|
|
1364
1939
|
(update) => {
|
|
1365
1940
|
setRenderEntriesById((entries) => {
|
|
1366
1941
|
const next = update(entries);
|
|
1367
1942
|
renderEntriesRef.current = next;
|
|
1943
|
+
problemTrackerRef.current.syncRenderSourcePaths([...next.values()]);
|
|
1368
1944
|
for (const renderId of [...renderedRenderIdsRef.current]) {
|
|
1369
1945
|
if (!next.has(renderId)) {
|
|
1370
1946
|
renderedRenderIdsRef.current.delete(renderId);
|
|
1371
|
-
|
|
1372
|
-
sourceAnnotatedCommitTimesRef.current.delete(renderId);
|
|
1947
|
+
legacyHealthRef.current.forgetRender(renderId);
|
|
1373
1948
|
}
|
|
1374
1949
|
}
|
|
1375
1950
|
return next;
|
|
@@ -1377,7 +1952,7 @@ function useCanvasHostPostMessage() {
|
|
|
1377
1952
|
},
|
|
1378
1953
|
[]
|
|
1379
1954
|
);
|
|
1380
|
-
const waitForRender =
|
|
1955
|
+
const waitForRender = useCallback3(
|
|
1381
1956
|
(request) => {
|
|
1382
1957
|
const current = renderEntriesRef.current.get(request.renderId);
|
|
1383
1958
|
const alreadyRendered = current?.status === "active" && renderedRenderIdsRef.current.has(request.renderId) && renderRequestMatchesEntry(current, request);
|
|
@@ -1386,14 +1961,14 @@ function useCanvasHostPostMessage() {
|
|
|
1386
1961
|
return Promise.resolve();
|
|
1387
1962
|
}
|
|
1388
1963
|
return new Promise((resolve, reject) => {
|
|
1389
|
-
const
|
|
1390
|
-
|
|
1391
|
-
|
|
1964
|
+
const pendingWaiters = pendingRenderWaitersRef.current.get(request.renderId) ?? [];
|
|
1965
|
+
pendingWaiters.push({ resolve, reject });
|
|
1966
|
+
pendingRenderWaitersRef.current.set(request.renderId, pendingWaiters);
|
|
1392
1967
|
});
|
|
1393
1968
|
},
|
|
1394
1969
|
[setEntries]
|
|
1395
1970
|
);
|
|
1396
|
-
const releaseRenderLease =
|
|
1971
|
+
const releaseRenderLease = useCallback3(
|
|
1397
1972
|
(renderId) => {
|
|
1398
1973
|
setEntries(
|
|
1399
1974
|
(entries) => releaseRender(entries, renderId, maxCachedRef.current)
|
|
@@ -1401,79 +1976,107 @@ function useCanvasHostPostMessage() {
|
|
|
1401
1976
|
},
|
|
1402
1977
|
[setEntries]
|
|
1403
1978
|
);
|
|
1404
|
-
const stopRuntimeWatch =
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1979
|
+
const stopRuntimeWatch = useCallback3(
|
|
1980
|
+
async (watchId, establishment) => {
|
|
1981
|
+
const existingWatch = watchesRef.current.get(watchId);
|
|
1982
|
+
if (!existingWatch || establishment && existingWatch.establishment !== establishment) {
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
watchesRef.current.delete(watchId);
|
|
1986
|
+
await existingWatch.watch.stop();
|
|
1987
|
+
},
|
|
1988
|
+
[]
|
|
1989
|
+
);
|
|
1990
|
+
const removeWatchRequest = useCallback3(
|
|
1991
|
+
async (watchId, reason) => {
|
|
1412
1992
|
const existingRequest = watchRequestsRef.current.get(watchId);
|
|
1993
|
+
if (existingRequest) {
|
|
1994
|
+
rejectWatchEstablishment(
|
|
1995
|
+
existingRequest,
|
|
1996
|
+
reason ?? new Error(
|
|
1997
|
+
`Canvas host watch ${watchId} was cancelled before establishment`
|
|
1998
|
+
)
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
1413
2001
|
try {
|
|
1414
|
-
await stopRuntimeWatch(watchId);
|
|
2002
|
+
await stopRuntimeWatch(watchId, existingRequest?.establishment);
|
|
1415
2003
|
} finally {
|
|
1416
|
-
if (
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
2004
|
+
if (existingRequest) {
|
|
2005
|
+
updateWatchRequests((requests) => {
|
|
2006
|
+
if (requests.get(watchId)?.establishment !== existingRequest.establishment) {
|
|
2007
|
+
return requests;
|
|
2008
|
+
}
|
|
2009
|
+
const next = new Map(requests);
|
|
2010
|
+
next.delete(watchId);
|
|
2011
|
+
return next;
|
|
2012
|
+
});
|
|
2013
|
+
releaseRenderLease(existingRequest.request.renderId);
|
|
2014
|
+
}
|
|
1424
2015
|
}
|
|
1425
2016
|
},
|
|
1426
|
-
[releaseRenderLease, stopRuntimeWatch]
|
|
2017
|
+
[releaseRenderLease, stopRuntimeWatch, updateWatchRequests]
|
|
2018
|
+
);
|
|
2019
|
+
const suspendEstablishedWatch = useCallback3(
|
|
2020
|
+
(request) => {
|
|
2021
|
+
if (request.establishment.status !== "established") return;
|
|
2022
|
+
void stopRuntimeWatch(request.watchId, request.establishment).catch(
|
|
2023
|
+
() => {
|
|
2024
|
+
}
|
|
2025
|
+
);
|
|
2026
|
+
},
|
|
2027
|
+
[stopRuntimeWatch]
|
|
1427
2028
|
);
|
|
1428
|
-
const buildState =
|
|
2029
|
+
const buildState = useCallback3(
|
|
1429
2030
|
() => buildRenderStatePayload(renderEntriesRef.current, maxCachedRef.current),
|
|
1430
2031
|
[]
|
|
1431
2032
|
);
|
|
1432
|
-
const
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
claimErrorBoundaryTripped: problemTrackerRef.current.hasComponentProblem(renderId),
|
|
1450
|
-
observedAt: Date.now()
|
|
1451
|
-
};
|
|
2033
|
+
const markStoryboardRendered = useCallback3((storyboardId) => {
|
|
2034
|
+
renderedRenderIdsRef.current.add(storyboardId);
|
|
2035
|
+
legacyHealthRef.current.recordRenderCommit(storyboardId);
|
|
2036
|
+
setRenderCommitVersionById((versions) => {
|
|
2037
|
+
const next = new Map(versions);
|
|
2038
|
+
next.set(storyboardId, (next.get(storyboardId) ?? 0) + 1);
|
|
2039
|
+
return next;
|
|
2040
|
+
});
|
|
2041
|
+
problemTrackerRef.current.clearRecoveredComponentProblemsAfterRender(
|
|
2042
|
+
storyboardId
|
|
2043
|
+
);
|
|
2044
|
+
const pendingWaiters = pendingRenderWaitersRef.current.get(storyboardId);
|
|
2045
|
+
if (!pendingWaiters) return;
|
|
2046
|
+
pendingRenderWaitersRef.current.delete(storyboardId);
|
|
2047
|
+
for (const waiter of pendingWaiters) {
|
|
2048
|
+
waiter.resolve();
|
|
2049
|
+
}
|
|
1452
2050
|
}, []);
|
|
1453
|
-
const
|
|
2051
|
+
const markStoryboardUnmounted = useCallback3(
|
|
1454
2052
|
(storyboardId) => {
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
2053
|
+
queueMicrotask(() => {
|
|
2054
|
+
const remounted = [
|
|
2055
|
+
...document.querySelectorAll("[data-render-id]")
|
|
2056
|
+
].some(
|
|
2057
|
+
(element) => element.getAttribute("data-render-id") === storyboardId
|
|
2058
|
+
);
|
|
2059
|
+
if (remounted) return;
|
|
2060
|
+
renderedRenderIdsRef.current.delete(storyboardId);
|
|
2061
|
+
for (const request of watchRequestsRef.current.values()) {
|
|
2062
|
+
if (request.request.renderId === storyboardId) {
|
|
2063
|
+
suspendEstablishedWatch(request);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
const pendingWaiters = pendingRenderWaitersRef.current.get(storyboardId);
|
|
2067
|
+
if (!pendingWaiters) return;
|
|
2068
|
+
pendingRenderWaitersRef.current.delete(storyboardId);
|
|
2069
|
+
const error = new Error(
|
|
2070
|
+
`Storyboard ${JSON.stringify(storyboardId)} unmounted before its requested render committed`
|
|
2071
|
+
);
|
|
2072
|
+
for (const waiter of pendingWaiters) {
|
|
2073
|
+
waiter.reject(error);
|
|
2074
|
+
}
|
|
1463
2075
|
});
|
|
1464
|
-
problemTrackerRef.current.clearRecoveredComponentProblemsAfterRender(
|
|
1465
|
-
storyboardId
|
|
1466
|
-
);
|
|
1467
|
-
const pendingAcks = pendingRenderAcksRef.current.get(storyboardId);
|
|
1468
|
-
if (!pendingAcks) return;
|
|
1469
|
-
pendingRenderAcksRef.current.delete(storyboardId);
|
|
1470
|
-
for (const ack of pendingAcks) {
|
|
1471
|
-
ack.resolve();
|
|
1472
|
-
}
|
|
1473
2076
|
},
|
|
1474
|
-
[
|
|
2077
|
+
[suspendEstablishedWatch]
|
|
1475
2078
|
);
|
|
1476
|
-
const reportStoryboardError =
|
|
2079
|
+
const reportStoryboardError = useCallback3(
|
|
1477
2080
|
(storyboardId, error) => {
|
|
1478
2081
|
renderedRenderIdsRef.current.delete(storyboardId);
|
|
1479
2082
|
problemTrackerRef.current.reportComponentProblem(
|
|
@@ -1485,28 +2088,79 @@ function useCanvasHostPostMessage() {
|
|
|
1485
2088
|
componentStack: error.componentStack
|
|
1486
2089
|
}
|
|
1487
2090
|
);
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
for (const
|
|
1493
|
-
|
|
2091
|
+
const renderError = new Error(error.message);
|
|
2092
|
+
const pendingWaiters = pendingRenderWaitersRef.current.get(storyboardId);
|
|
2093
|
+
if (pendingWaiters) {
|
|
2094
|
+
pendingRenderWaitersRef.current.delete(storyboardId);
|
|
2095
|
+
for (const waiter of pendingWaiters) {
|
|
2096
|
+
waiter.reject(renderError);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
for (const request of watchRequestsRef.current.values()) {
|
|
2100
|
+
if (request.request.renderId !== storyboardId || request.establishment.status === "failed") {
|
|
2101
|
+
continue;
|
|
2102
|
+
}
|
|
2103
|
+
if (request.establishment.status === "pending") {
|
|
2104
|
+
rejectWatchEstablishment(request, renderError);
|
|
2105
|
+
void removeWatchRequest(request.watchId, renderError);
|
|
2106
|
+
} else {
|
|
2107
|
+
postWatchError(request, renderError);
|
|
2108
|
+
suspendEstablishedWatch(request);
|
|
1494
2109
|
}
|
|
1495
2110
|
}
|
|
1496
2111
|
},
|
|
2112
|
+
[removeWatchRequest, suspendEstablishedWatch]
|
|
2113
|
+
);
|
|
2114
|
+
const clearStoryboardError = useCallback3((storyboardId) => {
|
|
2115
|
+
problemTrackerRef.current.clearComponentProblem(storyboardId, [
|
|
2116
|
+
"render-error-boundary"
|
|
2117
|
+
]);
|
|
2118
|
+
}, []);
|
|
2119
|
+
const reportCanvasImportError = useCallback3(
|
|
2120
|
+
(canvasPath, error) => {
|
|
2121
|
+
const normalizedPath = canvasPath.trim();
|
|
2122
|
+
if (!normalizedPath) return;
|
|
2123
|
+
problemTrackerRef.current.reportCanvasProblem(
|
|
2124
|
+
normalizedPath,
|
|
2125
|
+
"runtime-bootstrap",
|
|
2126
|
+
error.message,
|
|
2127
|
+
{
|
|
2128
|
+
stack: error.stack,
|
|
2129
|
+
componentStack: error.componentStack,
|
|
2130
|
+
filename: normalizedPath
|
|
2131
|
+
}
|
|
2132
|
+
);
|
|
2133
|
+
},
|
|
1497
2134
|
[]
|
|
1498
2135
|
);
|
|
1499
|
-
const
|
|
1500
|
-
(
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
2136
|
+
const clearCanvasImportError = useCallback3((canvasPath) => {
|
|
2137
|
+
const normalizedPath = canvasPath.trim();
|
|
2138
|
+
if (!normalizedPath) return;
|
|
2139
|
+
problemTrackerRef.current.clearCanvasProblem(normalizedPath, [
|
|
2140
|
+
"runtime-bootstrap"
|
|
2141
|
+
]);
|
|
2142
|
+
}, []);
|
|
2143
|
+
const registerCanvasProblemScope = useCallback3(
|
|
2144
|
+
(canvasPath) => problemTrackerRef.current.registerCanvasPath(canvasPath),
|
|
2145
|
+
[]
|
|
2146
|
+
);
|
|
2147
|
+
useEffect2(
|
|
2148
|
+
() => () => {
|
|
2149
|
+
problemTrackerRef.current.dispose();
|
|
1504
2150
|
},
|
|
1505
2151
|
[]
|
|
1506
2152
|
);
|
|
1507
|
-
|
|
2153
|
+
useLayoutEffect2(() => {
|
|
2154
|
+
if (typeof window === "undefined") return;
|
|
2155
|
+
const stopRuntimeProblemTracking = installCanvasHostRuntimeProblemTracking(
|
|
2156
|
+
problemTrackerRef.current
|
|
2157
|
+
);
|
|
2158
|
+
return () => {
|
|
2159
|
+
stopRuntimeProblemTracking();
|
|
2160
|
+
};
|
|
2161
|
+
}, []);
|
|
2162
|
+
useEffect2(() => {
|
|
1508
2163
|
if (typeof window === "undefined") return;
|
|
1509
|
-
let cancelled = false;
|
|
1510
2164
|
const activeWatchIds = new Set(watchRequestsById.keys());
|
|
1511
2165
|
for (const watchId of watchesRef.current.keys()) {
|
|
1512
2166
|
if (!activeWatchIds.has(watchId)) {
|
|
@@ -1514,18 +2168,40 @@ function useCanvasHostPostMessage() {
|
|
|
1514
2168
|
}
|
|
1515
2169
|
}
|
|
1516
2170
|
for (const request of watchRequestsById.values()) {
|
|
2171
|
+
if (request.establishment.status === "failed") continue;
|
|
1517
2172
|
const renderEntry = renderEntriesById.get(request.request.renderId);
|
|
1518
|
-
const renderReady = renderEntry?.status === "active" && renderedRenderIdsRef.current.has(request.request.renderId) &&
|
|
2173
|
+
const renderReady = renderEntry?.status === "active" && renderedRenderIdsRef.current.has(request.request.renderId) && renderRequestTargetsEntry(renderEntry, request.request);
|
|
1519
2174
|
if (!renderReady) continue;
|
|
1520
2175
|
const existing = watchesRef.current.get(request.watchId);
|
|
1521
|
-
if (existing?.bindingKey === request.bindingKey)
|
|
2176
|
+
if (existing?.bindingKey === request.bindingKey && existing.establishment === request.establishment) {
|
|
2177
|
+
const currentRequest = watchRequestsRef.current.get(request.watchId);
|
|
2178
|
+
if (currentRequest?.establishment !== request.establishment) continue;
|
|
2179
|
+
if (currentRequest.paused) setRuntimeWatchPaused(existing.watch, true);
|
|
2180
|
+
acknowledgeWatchEstablishment(currentRequest);
|
|
2181
|
+
continue;
|
|
2182
|
+
}
|
|
2183
|
+
if (!existing && request.paused) continue;
|
|
2184
|
+
const starting = startingWatchesRef.current.get(request.watchId);
|
|
2185
|
+
if (starting?.bindingKey === request.bindingKey && starting.establishment === request.establishment) {
|
|
2186
|
+
continue;
|
|
2187
|
+
}
|
|
2188
|
+
const startToken = {
|
|
2189
|
+
bindingKey: request.bindingKey,
|
|
2190
|
+
establishment: request.establishment
|
|
2191
|
+
};
|
|
2192
|
+
startingWatchesRef.current.set(request.watchId, startToken);
|
|
1522
2193
|
void (async () => {
|
|
1523
2194
|
if (existing) {
|
|
1524
|
-
await stopRuntimeWatch(request.watchId);
|
|
2195
|
+
await stopRuntimeWatch(request.watchId, existing.establishment);
|
|
1525
2196
|
}
|
|
1526
|
-
if (cancelled) return;
|
|
1527
2197
|
const onUpdate = (capture) => {
|
|
1528
|
-
|
|
2198
|
+
const currentRequest2 = watchRequestsRef.current.get(request.watchId);
|
|
2199
|
+
if (currentRequest2?.establishment !== request.establishment || currentRequest2.establishment.status === "failed") {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
legacyHealthRef.current.recordSourceAnnotatedCommit(
|
|
2203
|
+
request.request.renderId
|
|
2204
|
+
);
|
|
1529
2205
|
postToMessageSource(
|
|
1530
2206
|
request.source,
|
|
1531
2207
|
{
|
|
@@ -1539,17 +2215,14 @@ function useCanvasHostPostMessage() {
|
|
|
1539
2215
|
);
|
|
1540
2216
|
};
|
|
1541
2217
|
const onError = (error) => {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
},
|
|
1551
|
-
request.targetOrigin
|
|
1552
|
-
);
|
|
2218
|
+
const currentRequest2 = watchRequestsRef.current.get(request.watchId);
|
|
2219
|
+
if (currentRequest2?.establishment !== request.establishment) return;
|
|
2220
|
+
if (currentRequest2.establishment.status === "pending") {
|
|
2221
|
+
rejectWatchEstablishment(currentRequest2, error);
|
|
2222
|
+
void removeWatchRequest(request.watchId, error);
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
postWatchError(request, error);
|
|
1553
2226
|
};
|
|
1554
2227
|
const common = {
|
|
1555
2228
|
onUpdate,
|
|
@@ -1564,44 +2237,47 @@ function useCanvasHostPostMessage() {
|
|
|
1564
2237
|
fiberTags: Array.isArray(request.payload.fiberTags) ? request.payload.fiberTags : void 0,
|
|
1565
2238
|
knownSourceVersion: typeof request.payload.knownSourceVersion === "object" && request.payload.knownSourceVersion !== null ? request.payload.knownSourceVersion : void 0
|
|
1566
2239
|
});
|
|
1567
|
-
|
|
2240
|
+
const currentRequest = watchRequestsRef.current.get(request.watchId);
|
|
2241
|
+
if (currentRequest?.establishment !== request.establishment || currentRequest.establishment.status === "failed") {
|
|
1568
2242
|
await watch.stop();
|
|
1569
2243
|
return;
|
|
1570
2244
|
}
|
|
1571
2245
|
watchesRef.current.set(request.watchId, {
|
|
1572
2246
|
renderId: request.request.renderId,
|
|
1573
2247
|
bindingKey: request.bindingKey,
|
|
2248
|
+
establishment: request.establishment,
|
|
1574
2249
|
watch
|
|
1575
2250
|
});
|
|
1576
|
-
if (
|
|
1577
|
-
|
|
1578
|
-
else watch.pause?.();
|
|
2251
|
+
if (currentRequest.paused) {
|
|
2252
|
+
setRuntimeWatchPaused(watch, true);
|
|
1579
2253
|
}
|
|
2254
|
+
acknowledgeWatchEstablishment(currentRequest);
|
|
1580
2255
|
})().catch((caught) => {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
);
|
|
2256
|
+
const currentRequest = watchRequestsRef.current.get(request.watchId);
|
|
2257
|
+
if (currentRequest?.establishment !== request.establishment) {
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
2260
|
+
const error = caught instanceof Error ? caught : new Error(String(caught));
|
|
2261
|
+
if (currentRequest.establishment.status === "pending") {
|
|
2262
|
+
rejectWatchEstablishment(currentRequest, error);
|
|
2263
|
+
} else {
|
|
2264
|
+
postWatchError(currentRequest, error);
|
|
2265
|
+
}
|
|
2266
|
+
void removeWatchRequest(request.watchId, error);
|
|
2267
|
+
}).finally(() => {
|
|
2268
|
+
if (startingWatchesRef.current.get(request.watchId) === startToken) {
|
|
2269
|
+
startingWatchesRef.current.delete(request.watchId);
|
|
2270
|
+
}
|
|
1592
2271
|
});
|
|
1593
2272
|
}
|
|
1594
|
-
return () => {
|
|
1595
|
-
cancelled = true;
|
|
1596
|
-
};
|
|
1597
2273
|
}, [
|
|
1598
|
-
recordSourceAnnotatedCommit,
|
|
1599
2274
|
renderCommitVersionById,
|
|
1600
2275
|
renderEntriesById,
|
|
2276
|
+
removeWatchRequest,
|
|
1601
2277
|
stopRuntimeWatch,
|
|
1602
2278
|
watchRequestsById
|
|
1603
2279
|
]);
|
|
1604
|
-
|
|
2280
|
+
useEffect2(() => {
|
|
1605
2281
|
if (typeof window === "undefined") return;
|
|
1606
2282
|
const waitForRenderLease = async (request) => {
|
|
1607
2283
|
try {
|
|
@@ -1638,18 +2314,16 @@ function useCanvasHostPostMessage() {
|
|
|
1638
2314
|
const postAsyncError = (caught) => {
|
|
1639
2315
|
error(caught instanceof Error ? caught.message : String(caught));
|
|
1640
2316
|
};
|
|
1641
|
-
const postCaptureResult = (capture) =>
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
2317
|
+
const postCaptureResult = (renderId) => (capture) => {
|
|
2318
|
+
legacyHealthRef.current.recordSourceAnnotatedCommit(renderId);
|
|
2319
|
+
post({
|
|
2320
|
+
type: "render-pool:capture-result",
|
|
2321
|
+
requestId: command.requestId,
|
|
2322
|
+
command: command.type,
|
|
2323
|
+
payload: { capture }
|
|
2324
|
+
});
|
|
2325
|
+
};
|
|
1647
2326
|
try {
|
|
1648
|
-
if (command.type === "render-pool:render") {
|
|
1649
|
-
const request = readRenderRequest(command.type, payload);
|
|
1650
|
-
void waitForRenderLease(request).then(ack).catch(postAsyncError);
|
|
1651
|
-
return;
|
|
1652
|
-
}
|
|
1653
2327
|
if (command.type === "render-pool:capture-image") {
|
|
1654
2328
|
const request = readRenderRequest(command.type, payload);
|
|
1655
2329
|
void withRenderLease(
|
|
@@ -1665,10 +2339,7 @@ function useCanvasHostPostMessage() {
|
|
|
1665
2339
|
(selector) => typeof selector === "string"
|
|
1666
2340
|
) : void 0
|
|
1667
2341
|
})
|
|
1668
|
-
).then((
|
|
1669
|
-
recordSourceAnnotatedCommit(request.renderId);
|
|
1670
|
-
postCaptureResult(capture);
|
|
1671
|
-
}).catch(postAsyncError);
|
|
2342
|
+
).then(postCaptureResult(request.renderId)).catch(postAsyncError);
|
|
1672
2343
|
return;
|
|
1673
2344
|
}
|
|
1674
2345
|
if (command.type === "render-pool:capture-html") {
|
|
@@ -1678,23 +2349,7 @@ function useCanvasHostPostMessage() {
|
|
|
1678
2349
|
() => captureStoryboardHtml(request.renderId, {
|
|
1679
2350
|
timeout: readOptionalNumber(payload, "timeout")
|
|
1680
2351
|
})
|
|
1681
|
-
).then((
|
|
1682
|
-
recordSourceAnnotatedCommit(request.renderId);
|
|
1683
|
-
postCaptureResult(capture);
|
|
1684
|
-
}).catch(postAsyncError);
|
|
1685
|
-
return;
|
|
1686
|
-
}
|
|
1687
|
-
if (command.type === "render-pool:capture-static-html") {
|
|
1688
|
-
const request = readRenderRequest(command.type, payload);
|
|
1689
|
-
void withRenderLease(
|
|
1690
|
-
request,
|
|
1691
|
-
() => captureStoryboardStaticHtml(request.renderId, {
|
|
1692
|
-
timeout: readOptionalNumber(payload, "timeout")
|
|
1693
|
-
})
|
|
1694
|
-
).then((capture) => {
|
|
1695
|
-
recordSourceAnnotatedCommit(request.renderId);
|
|
1696
|
-
postCaptureResult(capture);
|
|
1697
|
-
}).catch(postAsyncError);
|
|
2352
|
+
).then(postCaptureResult(request.renderId)).catch(postAsyncError);
|
|
1698
2353
|
return;
|
|
1699
2354
|
}
|
|
1700
2355
|
if (command.type === "render-pool:capture-combined") {
|
|
@@ -1706,34 +2361,33 @@ function useCanvasHostPostMessage() {
|
|
|
1706
2361
|
fiberTags: Array.isArray(payload.fiberTags) ? payload.fiberTags : void 0,
|
|
1707
2362
|
timeout: readOptionalNumber(payload, "timeout")
|
|
1708
2363
|
})
|
|
1709
|
-
).then((
|
|
1710
|
-
recordSourceAnnotatedCommit(request.renderId);
|
|
1711
|
-
postCaptureResult(capture);
|
|
1712
|
-
}).catch(postAsyncError);
|
|
2364
|
+
).then(postCaptureResult(request.renderId)).catch(postAsyncError);
|
|
1713
2365
|
return;
|
|
1714
2366
|
}
|
|
1715
|
-
if (command.type === "render-pool:watch-
|
|
2367
|
+
if (command.type === "render-pool:watch-combined" || command.type === "render-pool:watch-html") {
|
|
1716
2368
|
const request = readRenderRequest(command.type, payload);
|
|
1717
2369
|
const watchId = readWatchId(command.type, payload);
|
|
1718
2370
|
void removeWatchRequest(watchId).then(() => {
|
|
1719
2371
|
setEntries((entries) => acquireRender(entries, request));
|
|
1720
|
-
|
|
2372
|
+
const establishment = { status: "pending" };
|
|
2373
|
+
const watchRequest = {
|
|
2374
|
+
commandType: command.type,
|
|
2375
|
+
requestId: command.requestId,
|
|
2376
|
+
watchId,
|
|
2377
|
+
source,
|
|
2378
|
+
targetOrigin,
|
|
2379
|
+
request,
|
|
2380
|
+
payload,
|
|
2381
|
+
paused: payload.paused === true,
|
|
2382
|
+
bindingKey: buildWatchBindingKey(command.type, payload),
|
|
2383
|
+
establishment
|
|
2384
|
+
};
|
|
2385
|
+
updateWatchRequests((requests) => {
|
|
1721
2386
|
const next = new Map(requests);
|
|
1722
|
-
next.set(watchId,
|
|
1723
|
-
commandType: command.type,
|
|
1724
|
-
requestId: command.requestId,
|
|
1725
|
-
watchId,
|
|
1726
|
-
source,
|
|
1727
|
-
targetOrigin,
|
|
1728
|
-
request,
|
|
1729
|
-
payload,
|
|
1730
|
-
paused: false,
|
|
1731
|
-
bindingKey: buildWatchBindingKey(command.type, payload)
|
|
1732
|
-
});
|
|
1733
|
-
watchRequestsRef.current = next;
|
|
2387
|
+
next.set(watchId, watchRequest);
|
|
1734
2388
|
return next;
|
|
1735
2389
|
});
|
|
1736
|
-
|
|
2390
|
+
acknowledgeWatchEstablishment(watchRequest);
|
|
1737
2391
|
}).catch(postAsyncError);
|
|
1738
2392
|
return;
|
|
1739
2393
|
}
|
|
@@ -1746,28 +2400,23 @@ function useCanvasHostPostMessage() {
|
|
|
1746
2400
|
const watchId = readWatchId(command.type, payload);
|
|
1747
2401
|
const paused = payload.paused === true;
|
|
1748
2402
|
const watch = watchesRef.current.get(watchId)?.watch;
|
|
1749
|
-
watch
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
2403
|
+
if (watch) {
|
|
2404
|
+
setRuntimeWatchPaused(
|
|
2405
|
+
watch,
|
|
2406
|
+
paused,
|
|
2407
|
+
paused ? void 0 : readWatchResumeOptions(payload)
|
|
2408
|
+
);
|
|
1753
2409
|
}
|
|
1754
|
-
|
|
2410
|
+
updateWatchRequests((requests) => {
|
|
1755
2411
|
const current = requests.get(watchId);
|
|
1756
2412
|
if (!current || current.paused === paused) return requests;
|
|
1757
2413
|
const next = new Map(requests);
|
|
1758
2414
|
next.set(watchId, { ...current, paused });
|
|
1759
|
-
watchRequestsRef.current = next;
|
|
1760
2415
|
return next;
|
|
1761
2416
|
});
|
|
1762
2417
|
ack();
|
|
1763
2418
|
return;
|
|
1764
2419
|
}
|
|
1765
|
-
if (command.type === "render-pool:unrender") {
|
|
1766
|
-
const target = requireRenderTarget(command.type, payload);
|
|
1767
|
-
releaseRenderLease(target.renderId);
|
|
1768
|
-
ack();
|
|
1769
|
-
return;
|
|
1770
|
-
}
|
|
1771
2420
|
if (command.type === "render-pool:list") {
|
|
1772
2421
|
post({
|
|
1773
2422
|
type: "render-pool:state",
|
|
@@ -1776,43 +2425,6 @@ function useCanvasHostPostMessage() {
|
|
|
1776
2425
|
});
|
|
1777
2426
|
return;
|
|
1778
2427
|
}
|
|
1779
|
-
if (command.type === "render-pool:set-cache-limit") {
|
|
1780
|
-
const maxCached = typeof payload.maxCached === "number" && Number.isInteger(payload.maxCached) ? Math.max(0, payload.maxCached) : maxCachedRef.current;
|
|
1781
|
-
maxCachedRef.current = maxCached;
|
|
1782
|
-
setEntries((entries) => evictCachedRenders(entries, maxCached));
|
|
1783
|
-
ack();
|
|
1784
|
-
return;
|
|
1785
|
-
}
|
|
1786
|
-
if (command.type === "render-pool:isolate") {
|
|
1787
|
-
const target = resolveRenderTarget(payload);
|
|
1788
|
-
document.querySelector("[data-render-isolation]")?.remove();
|
|
1789
|
-
if (target?.renderId) {
|
|
1790
|
-
const style = document.createElement("style");
|
|
1791
|
-
style.setAttribute("data-render-isolation", "");
|
|
1792
|
-
const escapedId = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(target.renderId) : target.renderId;
|
|
1793
|
-
style.textContent = '[data-render-id]:not([data-render-id="' + escapedId + '"]) { opacity: 0 !important; pointer-events: none !important; }';
|
|
1794
|
-
document.head.appendChild(style);
|
|
1795
|
-
}
|
|
1796
|
-
ack();
|
|
1797
|
-
return;
|
|
1798
|
-
}
|
|
1799
|
-
if (command.type === "render-pool:query-health") {
|
|
1800
|
-
const target = resolveRenderTarget(payload);
|
|
1801
|
-
post({
|
|
1802
|
-
type: "render-pool:health-snapshot",
|
|
1803
|
-
requestId: command.requestId,
|
|
1804
|
-
snapshot: buildHealthSnapshot(target?.renderId ?? "")
|
|
1805
|
-
});
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
if (command.type === "render-pool:query-problems") {
|
|
1809
|
-
post({
|
|
1810
|
-
type: "render-pool:problem-snapshot",
|
|
1811
|
-
requestId: command.requestId,
|
|
1812
|
-
payload: buildProblemSnapshot()
|
|
1813
|
-
});
|
|
1814
|
-
return;
|
|
1815
|
-
}
|
|
1816
2428
|
if (command.type === "render-pool:watch-problems") {
|
|
1817
2429
|
const watchId = typeof payload.watchId === "string" && payload.watchId.trim() ? payload.watchId : String(command.requestId ?? "default");
|
|
1818
2430
|
problemWatchersRef.current.set(watchId, {
|
|
@@ -1834,6 +2446,65 @@ function useCanvasHostPostMessage() {
|
|
|
1834
2446
|
const watchId = typeof payload.watchId === "string" && payload.watchId.trim() ? payload.watchId : String(command.requestId ?? "default");
|
|
1835
2447
|
problemWatchersRef.current.delete(watchId);
|
|
1836
2448
|
ack();
|
|
2449
|
+
return;
|
|
2450
|
+
}
|
|
2451
|
+
if (command.type === "render-pool:query-problems") {
|
|
2452
|
+
post({
|
|
2453
|
+
type: "render-pool:problem-snapshot",
|
|
2454
|
+
requestId: command.requestId,
|
|
2455
|
+
payload: buildProblemSnapshot()
|
|
2456
|
+
});
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
if (command.type === "render-pool:render") {
|
|
2460
|
+
const request = readRenderRequest(command.type, payload);
|
|
2461
|
+
void waitForRenderLease(request).then(ack).catch(postAsyncError);
|
|
2462
|
+
return;
|
|
2463
|
+
}
|
|
2464
|
+
if (command.type === "render-pool:unrender") {
|
|
2465
|
+
const target = requireRenderTarget(command.type, payload);
|
|
2466
|
+
releaseRenderLease(target.renderId);
|
|
2467
|
+
ack();
|
|
2468
|
+
return;
|
|
2469
|
+
}
|
|
2470
|
+
if (command.type === "render-pool:capture-static-html") {
|
|
2471
|
+
const request = readRenderRequest(command.type, payload);
|
|
2472
|
+
void withRenderLease(
|
|
2473
|
+
request,
|
|
2474
|
+
() => captureStoryboardStaticHtml(request.renderId, {
|
|
2475
|
+
timeout: readOptionalNumber(payload, "timeout")
|
|
2476
|
+
})
|
|
2477
|
+
).then(postCaptureResult(request.renderId)).catch(postAsyncError);
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2480
|
+
if (command.type === "render-pool:set-cache-limit") {
|
|
2481
|
+
if (typeof payload.maxCached === "number" && Number.isInteger(payload.maxCached)) {
|
|
2482
|
+
maxCachedRef.current = Math.max(0, payload.maxCached);
|
|
2483
|
+
}
|
|
2484
|
+
setEntries(
|
|
2485
|
+
(entries) => evictCachedRenders(entries, maxCachedRef.current)
|
|
2486
|
+
);
|
|
2487
|
+
ack();
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
if (command.type === "render-pool:isolate") {
|
|
2491
|
+
applyLegacyRenderIsolation(
|
|
2492
|
+
resolveRenderTarget(payload)?.renderId ?? null
|
|
2493
|
+
);
|
|
2494
|
+
ack();
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
if (command.type === "render-pool:query-health") {
|
|
2498
|
+
const renderId = resolveRenderTarget(payload)?.renderId ?? "";
|
|
2499
|
+
post({
|
|
2500
|
+
type: "render-pool:health-snapshot",
|
|
2501
|
+
requestId: command.requestId,
|
|
2502
|
+
snapshot: legacyHealthRef.current.buildSnapshot(renderId, {
|
|
2503
|
+
hasRenderEntries: renderEntriesRef.current.size > 0,
|
|
2504
|
+
claimErrorBoundaryTripped: problemTrackerRef.current.hasComponentProblem(renderId)
|
|
2505
|
+
})
|
|
2506
|
+
});
|
|
2507
|
+
return;
|
|
1837
2508
|
}
|
|
1838
2509
|
} catch (caught) {
|
|
1839
2510
|
postAsyncError(caught);
|
|
@@ -1846,14 +2517,10 @@ function useCanvasHostPostMessage() {
|
|
|
1846
2517
|
const stopProblemPublisher = problemTrackerRef.current.watch(
|
|
1847
2518
|
publishProblemSnapshot
|
|
1848
2519
|
);
|
|
1849
|
-
const stopRuntimeProblemTracking = installCanvasHostRuntimeProblemTracking(
|
|
1850
|
-
problemTrackerRef.current
|
|
1851
|
-
);
|
|
1852
2520
|
window.postMessage({ type: "render-pool:ready" }, "*");
|
|
1853
2521
|
return () => {
|
|
1854
2522
|
window.removeEventListener("message", onMessage);
|
|
1855
2523
|
window.removeEventListener("__render-pool:command", onBridgeCommand);
|
|
1856
|
-
stopRuntimeProblemTracking();
|
|
1857
2524
|
stopProblemPublisher();
|
|
1858
2525
|
for (const { watch } of watchesRef.current.values()) {
|
|
1859
2526
|
void watch.stop();
|
|
@@ -1862,41 +2529,33 @@ function useCanvasHostPostMessage() {
|
|
|
1862
2529
|
problemWatchersRef.current.clear();
|
|
1863
2530
|
};
|
|
1864
2531
|
}, [
|
|
1865
|
-
buildHealthSnapshot,
|
|
1866
2532
|
buildProblemSnapshot,
|
|
1867
2533
|
buildState,
|
|
1868
2534
|
publishProblemSnapshot,
|
|
1869
|
-
recordSourceAnnotatedCommit,
|
|
1870
2535
|
releaseRenderLease,
|
|
1871
2536
|
removeWatchRequest,
|
|
1872
2537
|
setEntries,
|
|
2538
|
+
updateWatchRequests,
|
|
1873
2539
|
waitForRender
|
|
1874
2540
|
]);
|
|
1875
2541
|
return {
|
|
1876
|
-
renderStatusById:
|
|
2542
|
+
renderStatusById: useMemo3(
|
|
1877
2543
|
() => buildRenderStatusMap(renderEntriesById),
|
|
1878
2544
|
[renderEntriesById]
|
|
1879
2545
|
),
|
|
1880
|
-
renderSizeById:
|
|
2546
|
+
renderSizeById: useMemo3(
|
|
1881
2547
|
() => buildRenderSizeMap(renderEntriesById),
|
|
1882
2548
|
[renderEntriesById]
|
|
1883
2549
|
),
|
|
1884
2550
|
markStoryboardRendered,
|
|
2551
|
+
markStoryboardUnmounted,
|
|
1885
2552
|
reportStoryboardError,
|
|
1886
|
-
clearStoryboardError
|
|
2553
|
+
clearStoryboardError,
|
|
2554
|
+
reportCanvasImportError,
|
|
2555
|
+
clearCanvasImportError,
|
|
2556
|
+
registerCanvasProblemScope
|
|
1887
2557
|
};
|
|
1888
2558
|
}
|
|
1889
|
-
function latestTimestamp(values) {
|
|
1890
|
-
let latest = null;
|
|
1891
|
-
for (const value of values.values()) {
|
|
1892
|
-
latest = latest === null ? value : Math.max(latest, value);
|
|
1893
|
-
}
|
|
1894
|
-
return latest;
|
|
1895
|
-
}
|
|
1896
|
-
function isReactConnected() {
|
|
1897
|
-
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
1898
|
-
return (hook?.renderers?.size ?? 0) > 0;
|
|
1899
|
-
}
|
|
1900
2559
|
function buildWatchBindingKey(commandType, payload) {
|
|
1901
2560
|
try {
|
|
1902
2561
|
return JSON.stringify({ commandType, payload });
|
|
@@ -1904,27 +2563,15 @@ function buildWatchBindingKey(commandType, payload) {
|
|
|
1904
2563
|
return `${commandType}:${Date.now()}`;
|
|
1905
2564
|
}
|
|
1906
2565
|
}
|
|
1907
|
-
var sourceAnnotationSelector2 = "[data-tempo-source-file], [data-tempo-source-loc], [data-tempo-filepath], [data-tempo-html-filepath]";
|
|
1908
|
-
function renderSlotHasSourceAnnotations(renderId) {
|
|
1909
|
-
const slot = typeof document === "undefined" ? null : document.querySelector(buildRenderContentSelector(renderId));
|
|
1910
|
-
return getObservedSourceFiles2(slot).length > 0;
|
|
1911
|
-
}
|
|
1912
|
-
function getObservedSourceFiles2(slot) {
|
|
1913
|
-
if (!slot) return [];
|
|
1914
|
-
return [
|
|
1915
|
-
...new Set(
|
|
1916
|
-
[...slot.querySelectorAll(sourceAnnotationSelector2)].flatMap((element) => [
|
|
1917
|
-
element.getAttribute("data-tempo-source-file"),
|
|
1918
|
-
element.getAttribute("data-tempo-filepath"),
|
|
1919
|
-
element.getAttribute("data-tempo-html-filepath"),
|
|
1920
|
-
element.getAttribute("data-tempo-source-loc")
|
|
1921
|
-
]).filter((file) => Boolean(file))
|
|
1922
|
-
)
|
|
1923
|
-
];
|
|
1924
|
-
}
|
|
1925
2566
|
|
|
1926
2567
|
// canvas/canvas-host.tsx
|
|
1927
|
-
import { jsx as
|
|
2568
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2569
|
+
var CanvasHostContractError = class extends Error {
|
|
2570
|
+
constructor() {
|
|
2571
|
+
super(...arguments);
|
|
2572
|
+
this.name = "CanvasHostContractError";
|
|
2573
|
+
}
|
|
2574
|
+
};
|
|
1928
2575
|
function readDirectUrlDimension(value) {
|
|
1929
2576
|
const match = value.trim().match(/^([0-9]*\.?[0-9]+)(px|vw|vh)?$/);
|
|
1930
2577
|
if (!match) {
|
|
@@ -1968,23 +2615,36 @@ function readDirectUrlRender() {
|
|
|
1968
2615
|
}
|
|
1969
2616
|
function CanvasHost({
|
|
1970
2617
|
children,
|
|
2618
|
+
canvasModules,
|
|
1971
2619
|
activeStoryboardIds,
|
|
1972
2620
|
isStoryboardActive
|
|
1973
2621
|
}) {
|
|
2622
|
+
if (children !== void 0 && canvasModules !== void 0) {
|
|
2623
|
+
throw new CanvasHostContractError(
|
|
2624
|
+
"CanvasHost cannot receive both children and canvasModules."
|
|
2625
|
+
);
|
|
2626
|
+
}
|
|
1974
2627
|
const {
|
|
1975
2628
|
renderStatusById: renderStatusById2,
|
|
1976
2629
|
renderSizeById,
|
|
1977
2630
|
markStoryboardRendered,
|
|
2631
|
+
markStoryboardUnmounted,
|
|
1978
2632
|
reportStoryboardError,
|
|
1979
|
-
clearStoryboardError
|
|
2633
|
+
clearStoryboardError,
|
|
2634
|
+
reportCanvasImportError,
|
|
2635
|
+
clearCanvasImportError,
|
|
2636
|
+
registerCanvasProblemScope
|
|
1980
2637
|
} = useCanvasHostPostMessage();
|
|
1981
2638
|
const directUrlSearch = typeof window === "undefined" ? "" : window.location.search;
|
|
1982
|
-
const directUrlRender =
|
|
1983
|
-
|
|
2639
|
+
const directUrlRender = useMemo4(() => {
|
|
2640
|
+
void directUrlSearch;
|
|
2641
|
+
return readDirectUrlRender();
|
|
2642
|
+
}, [directUrlSearch]);
|
|
2643
|
+
const propActiveIds = useMemo4(
|
|
1984
2644
|
() => new Set(activeStoryboardIds ?? []),
|
|
1985
2645
|
[activeStoryboardIds]
|
|
1986
2646
|
);
|
|
1987
|
-
const runtime =
|
|
2647
|
+
const runtime = useMemo4(
|
|
1988
2648
|
() => ({
|
|
1989
2649
|
getStoryboardStatus(storyboardId) {
|
|
1990
2650
|
const normalizedId = normalizeId(storyboardId, "Storyboard id");
|
|
@@ -2005,31 +2665,116 @@ function CanvasHost({
|
|
|
2005
2665
|
return directUrlRender?.renderId === normalizedId ? { left: 0, top: 0 } : void 0;
|
|
2006
2666
|
},
|
|
2007
2667
|
markStoryboardRendered,
|
|
2668
|
+
markStoryboardUnmounted,
|
|
2008
2669
|
reportStoryboardError,
|
|
2009
|
-
clearStoryboardError
|
|
2670
|
+
clearStoryboardError,
|
|
2671
|
+
reportCanvasImportError,
|
|
2672
|
+
clearCanvasImportError,
|
|
2673
|
+
registerCanvasProblemScope
|
|
2010
2674
|
}),
|
|
2011
2675
|
[
|
|
2012
2676
|
clearStoryboardError,
|
|
2677
|
+
clearCanvasImportError,
|
|
2013
2678
|
directUrlRender,
|
|
2014
2679
|
isStoryboardActive,
|
|
2015
2680
|
markStoryboardRendered,
|
|
2681
|
+
markStoryboardUnmounted,
|
|
2016
2682
|
propActiveIds,
|
|
2683
|
+
registerCanvasProblemScope,
|
|
2684
|
+
reportCanvasImportError,
|
|
2017
2685
|
reportStoryboardError,
|
|
2018
2686
|
renderSizeById,
|
|
2019
2687
|
renderStatusById2
|
|
2020
2688
|
]
|
|
2021
2689
|
);
|
|
2022
|
-
return /* @__PURE__ */
|
|
2690
|
+
return /* @__PURE__ */ jsxs2(CanvasHostContext.Provider, { value: runtime, children: [
|
|
2691
|
+
children,
|
|
2692
|
+
canvasModules?.map(({ canvasPath, load }) => /* @__PURE__ */ jsx3(
|
|
2693
|
+
CanvasImportBoundary,
|
|
2694
|
+
{
|
|
2695
|
+
canvasPath,
|
|
2696
|
+
load
|
|
2697
|
+
},
|
|
2698
|
+
canvasPath
|
|
2699
|
+
))
|
|
2700
|
+
] });
|
|
2023
2701
|
}
|
|
2024
2702
|
|
|
2703
|
+
// canvas/host-capability.ts
|
|
2704
|
+
var canvasHostCapability = {
|
|
2705
|
+
protocolVersion: 1,
|
|
2706
|
+
supportsModules: true
|
|
2707
|
+
};
|
|
2708
|
+
|
|
2025
2709
|
// canvas/storyboard.tsx
|
|
2026
2710
|
import {
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2711
|
+
Children as Children2,
|
|
2712
|
+
Component as Component2,
|
|
2713
|
+
cloneElement as cloneElement2,
|
|
2714
|
+
isValidElement as isValidElement2,
|
|
2715
|
+
Suspense as Suspense2,
|
|
2716
|
+
useCallback as useCallback5,
|
|
2717
|
+
useEffect as useEffect4,
|
|
2718
|
+
useLayoutEffect as useLayoutEffect3,
|
|
2719
|
+
useMemo as useMemo5,
|
|
2720
|
+
useRef as useRef4,
|
|
2721
|
+
useState as useState3
|
|
2031
2722
|
} from "react";
|
|
2032
|
-
|
|
2723
|
+
|
|
2724
|
+
// canvas/render-error-recovery.ts
|
|
2725
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
2726
|
+
var renderErrorRetryBaseDelayMs = 1e3;
|
|
2727
|
+
var renderErrorRetryMaxDelayMs = 8e3;
|
|
2728
|
+
var beatListeners = /* @__PURE__ */ new Set();
|
|
2729
|
+
function emitRenderErrorRecoveryBeat() {
|
|
2730
|
+
for (const listener of [...beatListeners]) listener();
|
|
2731
|
+
}
|
|
2732
|
+
var hot = import.meta.hot;
|
|
2733
|
+
hot?.on?.("vite:afterUpdate", emitRenderErrorRecoveryBeat);
|
|
2734
|
+
function useRenderErrorRecovery(retryNow) {
|
|
2735
|
+
const retryNowRef = useRef3(retryNow);
|
|
2736
|
+
retryNowRef.current = retryNow;
|
|
2737
|
+
const timerRef = useRef3(null);
|
|
2738
|
+
const nextDelayRef = useRef3(renderErrorRetryBaseDelayMs);
|
|
2739
|
+
const erroredRef = useRef3(false);
|
|
2740
|
+
const clearTimer = useCallback4(() => {
|
|
2741
|
+
if (timerRef.current === null) return;
|
|
2742
|
+
clearTimeout(timerRef.current);
|
|
2743
|
+
timerRef.current = null;
|
|
2744
|
+
}, []);
|
|
2745
|
+
const noteRenderError = useCallback4(() => {
|
|
2746
|
+
erroredRef.current = true;
|
|
2747
|
+
if (timerRef.current !== null) return;
|
|
2748
|
+
const delay = nextDelayRef.current;
|
|
2749
|
+
nextDelayRef.current = Math.min(delay * 2, renderErrorRetryMaxDelayMs);
|
|
2750
|
+
timerRef.current = setTimeout(() => {
|
|
2751
|
+
timerRef.current = null;
|
|
2752
|
+
retryNowRef.current();
|
|
2753
|
+
}, delay);
|
|
2754
|
+
}, []);
|
|
2755
|
+
const noteRecovered = useCallback4(() => {
|
|
2756
|
+
erroredRef.current = false;
|
|
2757
|
+
nextDelayRef.current = renderErrorRetryBaseDelayMs;
|
|
2758
|
+
clearTimer();
|
|
2759
|
+
}, [clearTimer]);
|
|
2760
|
+
useEffect3(() => {
|
|
2761
|
+
const onBeat = () => {
|
|
2762
|
+
nextDelayRef.current = renderErrorRetryBaseDelayMs;
|
|
2763
|
+
if (!erroredRef.current) return;
|
|
2764
|
+
clearTimer();
|
|
2765
|
+
retryNowRef.current();
|
|
2766
|
+
};
|
|
2767
|
+
beatListeners.add(onBeat);
|
|
2768
|
+
return () => {
|
|
2769
|
+
beatListeners.delete(onBeat);
|
|
2770
|
+
clearTimer();
|
|
2771
|
+
};
|
|
2772
|
+
}, [clearTimer]);
|
|
2773
|
+
return { noteRenderError, noteRecovered };
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
// canvas/storyboard.tsx
|
|
2777
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2033
2778
|
function Storyboard({
|
|
2034
2779
|
id,
|
|
2035
2780
|
name,
|
|
@@ -2037,28 +2782,28 @@ function Storyboard({
|
|
|
2037
2782
|
layout,
|
|
2038
2783
|
props
|
|
2039
2784
|
}) {
|
|
2040
|
-
const
|
|
2041
|
-
return /* @__PURE__ */
|
|
2785
|
+
const Component3 = component;
|
|
2786
|
+
return /* @__PURE__ */ jsx4(StoryboardSlot, { id, name, layout, kind: "component", children: /* @__PURE__ */ jsx4(Component3, { ...props ?? {} }) });
|
|
2042
2787
|
}
|
|
2043
2788
|
function LegacyStoryboardV1({
|
|
2044
2789
|
id,
|
|
2045
2790
|
storyboard
|
|
2046
2791
|
}) {
|
|
2047
|
-
return /* @__PURE__ */
|
|
2792
|
+
return /* @__PURE__ */ jsx4(
|
|
2048
2793
|
StoryboardSlot,
|
|
2049
2794
|
{
|
|
2050
2795
|
id,
|
|
2051
2796
|
name: storyboard.name,
|
|
2052
2797
|
layout: storyboard.layout,
|
|
2053
2798
|
kind: "component",
|
|
2054
|
-
children: /* @__PURE__ */
|
|
2799
|
+
children: /* @__PURE__ */ jsx4(LegacyStoryboardV1Render, { render: storyboard.render })
|
|
2055
2800
|
}
|
|
2056
2801
|
);
|
|
2057
2802
|
}
|
|
2058
2803
|
function LegacyStoryboardV1Render({
|
|
2059
2804
|
render
|
|
2060
2805
|
}) {
|
|
2061
|
-
return /* @__PURE__ */
|
|
2806
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: render() });
|
|
2062
2807
|
}
|
|
2063
2808
|
function RouteStoryboard({
|
|
2064
2809
|
id,
|
|
@@ -2066,7 +2811,7 @@ function RouteStoryboard({
|
|
|
2066
2811
|
route,
|
|
2067
2812
|
layout
|
|
2068
2813
|
}) {
|
|
2069
|
-
return /* @__PURE__ */
|
|
2814
|
+
return /* @__PURE__ */ jsx4(
|
|
2070
2815
|
StoryboardSlot,
|
|
2071
2816
|
{
|
|
2072
2817
|
id,
|
|
@@ -2084,7 +2829,7 @@ function HtmlStoryboard({
|
|
|
2084
2829
|
src,
|
|
2085
2830
|
layout
|
|
2086
2831
|
}) {
|
|
2087
|
-
return /* @__PURE__ */
|
|
2832
|
+
return /* @__PURE__ */ jsx4(
|
|
2088
2833
|
StoryboardSlot,
|
|
2089
2834
|
{
|
|
2090
2835
|
id,
|
|
@@ -2112,22 +2857,65 @@ function StoryboardSlot({
|
|
|
2112
2857
|
const renderSize = useStoryboardSize(id);
|
|
2113
2858
|
const placement = useStoryboardPlacement(id);
|
|
2114
2859
|
const markRendered = useStoryboardRendered(id);
|
|
2860
|
+
const markUnmounted = useStoryboardUnmounted(id);
|
|
2115
2861
|
const { reportError, clearError } = useStoryboardErrorReporter(id);
|
|
2116
2862
|
const renderWidth = renderSize?.width;
|
|
2117
2863
|
const renderHeight = renderSize?.height;
|
|
2864
|
+
const renderRevision = renderSize?.revision ?? 0;
|
|
2118
2865
|
const intrinsicSize = renderSize?.intrinsicSize ?? (kind === "component" && layout.intrinsicSizing === "root-element");
|
|
2119
|
-
const resetKey = `${renderId}:${
|
|
2120
|
-
const contentRef =
|
|
2121
|
-
|
|
2866
|
+
const resetKey = `${renderId}:${renderRevision}`;
|
|
2867
|
+
const contentRef = useRef4(null);
|
|
2868
|
+
const errorBoundaryRef = useRef4(null);
|
|
2869
|
+
const lastReportedCommitRef = useRef4(null);
|
|
2870
|
+
const previousChildrenRef = useRef4(children);
|
|
2871
|
+
const [recoveryRevision, setRecoveryRevision] = useState3(0);
|
|
2872
|
+
const commitKey = `${resetKey}:${recoveryRevision}`;
|
|
2873
|
+
const retryRenderNow = useCallback5(() => {
|
|
2874
|
+
if (!errorBoundaryRef.current?.retry()) return false;
|
|
2875
|
+
setRecoveryRevision((revision) => revision + 1);
|
|
2876
|
+
return true;
|
|
2877
|
+
}, []);
|
|
2878
|
+
const { noteRenderError, noteRecovered } = useRenderErrorRecovery(retryRenderNow);
|
|
2879
|
+
const handleRenderError = useCallback5(
|
|
2880
|
+
(error) => {
|
|
2881
|
+
noteRenderError();
|
|
2882
|
+
reportError(error);
|
|
2883
|
+
},
|
|
2884
|
+
[noteRenderError, reportError]
|
|
2885
|
+
);
|
|
2886
|
+
const handleRendered = useCallback5(
|
|
2887
|
+
(reportedCommitKey) => {
|
|
2888
|
+
noteRecovered();
|
|
2889
|
+
if (lastReportedCommitRef.current === reportedCommitKey) return;
|
|
2890
|
+
lastReportedCommitRef.current = reportedCommitKey;
|
|
2891
|
+
clearError();
|
|
2892
|
+
markRendered();
|
|
2893
|
+
},
|
|
2894
|
+
[clearError, markRendered, noteRecovered]
|
|
2895
|
+
);
|
|
2896
|
+
const renderChildren = useMemo5(() => {
|
|
2897
|
+
if (isValidElement2(children)) return cloneElement2(children);
|
|
2898
|
+
return Children2.map(
|
|
2899
|
+
children,
|
|
2900
|
+
(child) => isValidElement2(child) ? cloneElement2(child) : child
|
|
2901
|
+
);
|
|
2902
|
+
}, [children]);
|
|
2903
|
+
useEffect4(() => markUnmounted, [markUnmounted]);
|
|
2904
|
+
useEffect4(() => {
|
|
2905
|
+
const childrenChanged = previousChildrenRef.current !== children;
|
|
2906
|
+
previousChildrenRef.current = children;
|
|
2907
|
+
if (childrenChanged) retryRenderNow();
|
|
2908
|
+
}, [children, retryRenderNow]);
|
|
2909
|
+
useEffect4(() => {
|
|
2122
2910
|
if (!contentRef.current || status === "unmounted") return;
|
|
2123
2911
|
return trackStoryboardPortals(renderId, contentRef.current, status);
|
|
2124
2912
|
}, [renderId, status]);
|
|
2125
|
-
|
|
2913
|
+
useEffect4(() => {
|
|
2126
2914
|
if (status === "unmounted") return;
|
|
2127
2915
|
syncStoryboardPortals(renderId, status);
|
|
2128
2916
|
}, [renderId, status]);
|
|
2129
2917
|
if (status === "unmounted") return null;
|
|
2130
|
-
return /* @__PURE__ */
|
|
2918
|
+
return /* @__PURE__ */ jsx4(
|
|
2131
2919
|
"div",
|
|
2132
2920
|
{
|
|
2133
2921
|
"data-render-id": renderId,
|
|
@@ -2152,27 +2940,29 @@ function StoryboardSlot({
|
|
|
2152
2940
|
visibility: status === "active" ? "visible" : "hidden",
|
|
2153
2941
|
pointerEvents: status === "active" ? "auto" : "none"
|
|
2154
2942
|
},
|
|
2155
|
-
children: /* @__PURE__ */
|
|
2943
|
+
children: /* @__PURE__ */ jsx4(
|
|
2156
2944
|
"div",
|
|
2157
2945
|
{
|
|
2158
2946
|
"data-render-content": renderId,
|
|
2947
|
+
"data-tempo-render-mode": kind === "html" ? "static-dom" : void 0,
|
|
2948
|
+
"data-tempo-hide-fiber": "true",
|
|
2159
2949
|
ref: contentRef,
|
|
2160
2950
|
style: { width: "100%", height: "100%" },
|
|
2161
|
-
children: /* @__PURE__ */
|
|
2951
|
+
children: /* @__PURE__ */ jsx4(
|
|
2162
2952
|
StoryboardErrorBoundary,
|
|
2163
2953
|
{
|
|
2164
|
-
|
|
2165
|
-
|
|
2954
|
+
ref: errorBoundaryRef,
|
|
2955
|
+
onError: handleRenderError,
|
|
2166
2956
|
resetKey,
|
|
2167
|
-
children: /* @__PURE__ */
|
|
2168
|
-
|
|
2169
|
-
/* @__PURE__ */
|
|
2170
|
-
|
|
2957
|
+
children: /* @__PURE__ */ jsxs3(Suspense2, { fallback: null, children: [
|
|
2958
|
+
renderChildren,
|
|
2959
|
+
/* @__PURE__ */ jsx4(
|
|
2960
|
+
StoryboardCommitSignal,
|
|
2171
2961
|
{
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2962
|
+
commitKey,
|
|
2963
|
+
onCommit: handleRendered
|
|
2964
|
+
},
|
|
2965
|
+
commitKey
|
|
2176
2966
|
)
|
|
2177
2967
|
] })
|
|
2178
2968
|
}
|
|
@@ -2182,11 +2972,18 @@ function StoryboardSlot({
|
|
|
2182
2972
|
}
|
|
2183
2973
|
);
|
|
2184
2974
|
}
|
|
2185
|
-
|
|
2186
|
-
|
|
2975
|
+
function StoryboardCommitSignal({
|
|
2976
|
+
commitKey,
|
|
2977
|
+
onCommit
|
|
2978
|
+
}) {
|
|
2979
|
+
const onCommitRef = useRef4(onCommit);
|
|
2980
|
+
onCommitRef.current = onCommit;
|
|
2981
|
+
useLayoutEffect3(() => onCommitRef.current(commitKey), [commitKey]);
|
|
2982
|
+
return null;
|
|
2983
|
+
}
|
|
2984
|
+
var StoryboardErrorBoundary = class extends Component2 {
|
|
2187
2985
|
constructor() {
|
|
2188
2986
|
super(...arguments);
|
|
2189
|
-
this.retryTimer = null;
|
|
2190
2987
|
this.state = {
|
|
2191
2988
|
error: null,
|
|
2192
2989
|
componentStack: void 0,
|
|
@@ -2198,7 +2995,11 @@ var StoryboardErrorBoundary = class extends Component {
|
|
|
2198
2995
|
}
|
|
2199
2996
|
static getDerivedStateFromProps(props, state) {
|
|
2200
2997
|
if (props.resetKey !== state.resetKey) {
|
|
2201
|
-
return {
|
|
2998
|
+
return {
|
|
2999
|
+
error: null,
|
|
3000
|
+
componentStack: void 0,
|
|
3001
|
+
resetKey: props.resetKey
|
|
3002
|
+
};
|
|
2202
3003
|
}
|
|
2203
3004
|
return null;
|
|
2204
3005
|
}
|
|
@@ -2209,38 +3010,20 @@ var StoryboardErrorBoundary = class extends Component {
|
|
|
2209
3010
|
stack: error.stack,
|
|
2210
3011
|
componentStack: info.componentStack ?? void 0
|
|
2211
3012
|
});
|
|
2212
|
-
this.scheduleRetry();
|
|
2213
|
-
}
|
|
2214
|
-
componentDidUpdate(_prevProps, prevState) {
|
|
2215
|
-
if (this.state.error) {
|
|
2216
|
-
if (!this.retryTimer) this.scheduleRetry();
|
|
2217
|
-
return;
|
|
2218
|
-
}
|
|
2219
|
-
this.clearRetryTimer();
|
|
2220
|
-
if (prevState.error && !this.state.error) {
|
|
2221
|
-
this.props.onRecover();
|
|
2222
|
-
}
|
|
2223
3013
|
}
|
|
2224
|
-
|
|
2225
|
-
this.
|
|
2226
|
-
}
|
|
2227
|
-
scheduleRetry() {
|
|
2228
|
-
this.clearRetryTimer();
|
|
2229
|
-
this.retryTimer = setTimeout(() => {
|
|
2230
|
-
this.retryTimer = null;
|
|
2231
|
-
this.setState(
|
|
2232
|
-
(state) => state.error ? { error: null, componentStack: void 0, resetKey: state.resetKey } : null
|
|
2233
|
-
);
|
|
2234
|
-
}, renderErrorRetryDelayMs);
|
|
3014
|
+
hasError() {
|
|
3015
|
+
return this.state.error !== null;
|
|
2235
3016
|
}
|
|
2236
|
-
|
|
2237
|
-
if (!this.
|
|
2238
|
-
|
|
2239
|
-
|
|
3017
|
+
retry() {
|
|
3018
|
+
if (!this.state.error) return false;
|
|
3019
|
+
this.setState(
|
|
3020
|
+
(state) => state.error ? { error: null, componentStack: void 0, resetKey: state.resetKey } : null
|
|
3021
|
+
);
|
|
3022
|
+
return true;
|
|
2240
3023
|
}
|
|
2241
3024
|
render() {
|
|
2242
3025
|
if (this.state.error) {
|
|
2243
|
-
return /* @__PURE__ */
|
|
3026
|
+
return /* @__PURE__ */ jsx4(
|
|
2244
3027
|
"div",
|
|
2245
3028
|
{
|
|
2246
3029
|
"data-render-error": "true",
|
|
@@ -2252,50 +3035,33 @@ var StoryboardErrorBoundary = class extends Component {
|
|
|
2252
3035
|
return this.props.children;
|
|
2253
3036
|
}
|
|
2254
3037
|
};
|
|
2255
|
-
function StoryboardReadySentinel({
|
|
2256
|
-
active,
|
|
2257
|
-
clearError,
|
|
2258
|
-
markRendered
|
|
2259
|
-
}) {
|
|
2260
|
-
useEffect2(() => {
|
|
2261
|
-
if (!active) return;
|
|
2262
|
-
let paintFrame = 0;
|
|
2263
|
-
const commitFrame = requestAnimationFrame(() => {
|
|
2264
|
-
paintFrame = requestAnimationFrame(() => {
|
|
2265
|
-
clearError();
|
|
2266
|
-
markRendered();
|
|
2267
|
-
});
|
|
2268
|
-
});
|
|
2269
|
-
return () => {
|
|
2270
|
-
cancelAnimationFrame(commitFrame);
|
|
2271
|
-
cancelAnimationFrame(paintFrame);
|
|
2272
|
-
};
|
|
2273
|
-
}, [active, clearError, markRendered]);
|
|
2274
|
-
return null;
|
|
2275
|
-
}
|
|
2276
3038
|
export {
|
|
2277
3039
|
Canvas,
|
|
2278
3040
|
CanvasContext,
|
|
2279
3041
|
CanvasHost,
|
|
3042
|
+
CanvasHostContractError,
|
|
3043
|
+
CanvasImportBoundary,
|
|
2280
3044
|
HtmlStoryboard,
|
|
2281
3045
|
LegacyStoryboardV1,
|
|
2282
3046
|
RouteStoryboard,
|
|
2283
3047
|
Storyboard,
|
|
2284
3048
|
StoryboardSlot,
|
|
3049
|
+
TEMPO_INTERACT_FRAME_NAME,
|
|
2285
3050
|
buildRenderContentFiberSelector,
|
|
2286
3051
|
buildRenderContentSelector,
|
|
2287
3052
|
buildRenderSelector,
|
|
3053
|
+
canvasHostCapability,
|
|
2288
3054
|
captureStoryboardCombined,
|
|
2289
3055
|
captureStoryboardHtml,
|
|
2290
3056
|
captureStoryboardImage,
|
|
2291
|
-
|
|
3057
|
+
getCanvasHostRecoveryFeed,
|
|
2292
3058
|
getCanvasHostRuntime,
|
|
2293
3059
|
getCanvasStoryboardRenderId,
|
|
2294
3060
|
getOptionalCanvasHostRuntime,
|
|
3061
|
+
isTempoInteractFrameName,
|
|
2295
3062
|
stripRenderContentWrapperAttributes,
|
|
2296
3063
|
stripRenderContentWrapperFromCombinedCapture,
|
|
2297
3064
|
useActiveState,
|
|
2298
|
-
watchStoryboardCombined
|
|
2299
|
-
watchStoryboardHtml
|
|
3065
|
+
watchStoryboardCombined
|
|
2300
3066
|
};
|
|
2301
3067
|
//# sourceMappingURL=index.js.map
|